Commit 9068746a authored by Nicolas Denoyelle's avatar Nicolas Denoyelle Committed by Swann Perarnau

Add macros for assessing compiled backends. Add function to assess backends...

Add macros for assessing compiled backends. Add function to assess backends usability at runtime. Use this capability in area cuda test to skip tests when no cuda device is present.
parent a0e605bb
......@@ -107,6 +107,8 @@ AM_CONDITIONAL([BUILD_DOCS],[ test "x$docs" == xtrue ])
# check CUDA compiler and libraries
#####################################
have_cuda=0
AC_ARG_WITH([cuda],
[AS_HELP_STRING([--with-cuda@<:@=yes|no|DIR@:>@],
[support cuda inside the library (default is check)])],
......@@ -164,17 +166,12 @@ if [[ "x$have_nvcc" = xyes ]]; then
AC_MSG_ERROR([could not find cudart library]))
LIBS=$saved_LIBS
CFLAGS=$saved_CFLAGS
have_cuda=1
fi
if [[ "x$have_nvcc" = xyes ]]; then
# we only get there if every test worked
AC_DEFINE([HAVE_CUDA], [1], [Whether aml support cuda library calls.])
have_cuda="yes"
else
have_cuda="no"
fi
AM_CONDITIONAL([HAVE_CUDA], [ test "x$have_cuda" = xyes ])
AC_DEFINE_UNQUOTED([HAVE_CUDA], [$have_cuda], [Whether aml support cuda library calls.])
AC_SUBST([HAVE_CUDA],[$have_cuda])
AM_CONDITIONAL([HAVE_CUDA], [ test "$have_cuda" == "1" ])
AC_SUBST(CUDA_CFLAGS)
AC_SUBST(CUDA_LIBS)
AC_SUBST(NVCC)
......@@ -191,6 +188,7 @@ AC_CONFIG_FILES([Makefile
doc/Makefile
benchmarks/Makefile
aml.pc
include/aml/utils/version.h])
include/aml/utils/version.h
include/aml/utils/features.h])
AC_CONFIG_FILES([o2lo], [chmod +x o2lo])
AC_OUTPUT
......@@ -34,5 +34,6 @@ include_amlutils_HEADERS = \
aml/utils/error.h \
aml/utils/inner-malloc.h \
aml/utils/vector.h \
aml/utils/version.h
aml/utils/version.h \
aml/utils/features.h
......@@ -38,6 +38,7 @@
#include "aml/utils/inner-malloc.h"
#include "aml/utils/vector.h"
#include "aml/utils/version.h"
#include "aml/utils/features.h"
////////////////////////////////////////////////////////////////////////////////
......
/*******************************************************************************
* Copyright 2019 UChicago Argonne, LLC.
* (c.f. AUTHORS, LICENSE)
*
* This file is part of the AML project.
* For more info, see https://xgitlab.cels.anl.gov/argo/aml
*
* SPDX-License-Identifier: BSD-3-Clause
*******************************************************************************/
#ifndef AML_FEATURES_H
#define AML_FEATURES_H
/**
* @defgroup aml_features "AML Features Detection API"
* @brief AML Features Detection API
*
* This module provides the compile time and runtime detection of backends
* used in AML.
* This feature is usefull for instance when testing AML. When AML is compiled
* with cuda backend support but runs on a machine without cuda devices, we can
* disable cuda tests.
* @{
**/
/** Whether aml had libnuma at compile time. (always true) **/
#define AML_HAVE_BACKEND_LIBNUMA 1
/** Whether aml had cuda capabilities at compile time **/
#define AML_HAVE_BACKEND_CUDA @HAVE_CUDA@
/** Flag for checking runtime suport for libnuma **/
#define AML_BACKEND_LIBNUMA (1UL<<1)
/** Flag for checking runtime suport for cuda **/
#define AML_BACKEND_CUDA (1UL<<2)
/**
* Check if a set of backends can be used at runtime.
*
* Checking for cuda and libnuma support at runtime:
* ```
* if (aml_support_backend(AML_BACKEND_LIBNUMA_FLAG | AML_BACKEND_CUDA_FLAG)
* { ... }
* ```
* @param[in] backends: The backend to check.
* @return 1 if the backend works, else 0.
**/
int aml_support_backends(const unsigned long backends);
/**
* @}
**/
#endif // AML_FEATURES_H
......@@ -34,7 +34,8 @@ TILING_SOURCES = \
UTILS_SOURCES = \
utils/bitmap.c \
utils/error.c \
utils/vector.c
utils/vector.c \
utils/features.c
LIB_SOURCES = \
$(AREA_SOURCES) \
......
/*******************************************************************************
* Copyright 2019 UChicago Argonne, LLC.
* (c.f. AUTHORS, LICENSE)
*
* This file is part of the AML project.
* For more info, see https://xgitlab.cels.anl.gov/argo/aml
*
* SPDX-License-Identifier: BSD-3-Clause
*******************************************************************************/
#include "aml/utils/features.h"
#include "config.h"
#if HAVE_CUDA == 1
#include <cuda.h>
#include <cuda_runtime.h>
#endif
static int aml_support_cuda(void)
{
#if HAVE_CUDA == 0
return 0;
#else
int x;
if (cudaGetDeviceCount(&x) != cudaSuccess || x <= 0)
return 0;
return 1;
#endif
}
int aml_support_backends(const unsigned long backends)
{
// Cuda check: compilation support and runtime support must be present.
if ((backends & AML_BACKEND_CUDA) &&
!(AML_HAVE_BACKEND_CUDA && aml_support_cuda()))
return 0;
return 1;
}
......@@ -3,6 +3,16 @@ AM_COLOR_TESTS = yes
AM_CFLAGS = -I$(top_srcdir)/include $(PTHREAD_CFLAGS)
AM_LDFLAGS = ../src/libaml.la $(PTHREAD_LIBS)
if HAVE_CUDA
# LIBS is used instead of AM_LDFLAGS on purpose
# AM_LDFLAGS appends flags before libraries added before LDADD.
# Thus, when linking with libaml.la, linking with cuda is not done.
LIBS += $(CUDA_CFLAGS)
LIBS += $(CUDA_LIBS)
AM_CFLAGS += $(CUDA_CFLAGS)
AM_LDFLAGS += $(CUDA_LIBS)
endif
# valgrind support
if TEST_VALGRIND
TESTS_ENVIRONMENT= @LIBTOOL@ --mode=execute @VALGRIND@ --tool=memcheck -q --leak-check=full
......@@ -30,10 +40,6 @@ SCRATCH_TESTS = scratch/test_scratch_seq \
if HAVE_CUDA
AM_CFLAGS += $(CUDA_CFLAGS)
AM_LDFLAGS += $(CUDA_LIBS)
AREA_TESTS += area/test_cuda
endif
......
......@@ -10,6 +10,7 @@
#include "aml.h"
#include "config.h"
#include "aml/area/cuda.h"
#include "aml/utils/features.h"
#include <stdlib.h>
#include <string.h>
#include <cuda.h>
......@@ -209,6 +210,9 @@ int main(void)
int has_register_ptr;
int current_device;
if (!aml_support_backends(AML_BACKEND_CUDA))
return 77;
assert(cudaGetDeviceCount(&num_devices) == cudaSuccess);
assert(cudaGetDevice(&current_device) == cudaSuccess);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment