Skip to content
Snippets Groups Projects
  • boeschf's avatar
    export API (#1824) · 675fdbc9
    boeschf authored
    Exports all symbols so arbor can be compiled as set of shared libraries. 
    
    In order to export all symbols correctly, one macro per library and one global macro are added. The content of the macros is determined at configure time depending on build variant (static/shared), compiler, and platforms (linux, mac os) and goes into the library's include directory as `export.hpp` when installed (at build time it resides at cmake's temporary build directory). The per-library macro is named `ARB_LIBNAME_API` and goes in front of to-be-exported symbols. The global macro is `ARB_SYMBOL_VISIBLE`. 
    
    This PR adds the annotation in all of the places where it is required. Most of them are in the public headers (and corresponding sources) but some are also added in internal headers, which were required for the unit tests to link properly.
    
    Fixes #1752
    Unverified
    675fdbc9
cuda_api.hpp 1.04 KiB
#include <utility>
#include <string>

#include <cuda.h>
#include <cuda_runtime.h>
#include <cuda_runtime_api.h>
#include <arborenv/export.hpp>

using DeviceProp = cudaDeviceProp;

struct ARB_SYMBOL_VISIBLE api_error_type {
    cudaError_t value;
    api_error_type(cudaError_t e): value(e) {}

    operator bool() const {
        return value==cudaSuccess;
    }

    bool is_invalid_device() const {
        return value == cudaErrorInvalidDevice;
    }

    bool no_device_found() const {
        return value == cudaErrorNoDevice;
    }

    std::string name() const {
        std::string s = cudaGetErrorName(value);
        return s;
    }

    std::string description() const {
        std::string s = cudaGetErrorString(value);
        return s;
    }
};

template <typename... ARGS>
inline api_error_type get_device_count(ARGS&&... args) {
    return cudaGetDeviceCount(std::forward<ARGS>(args)...);
}

template <typename... ARGS>
inline api_error_type get_device_properties(ARGS&&... args) {
    return cudaGetDeviceProperties(std::forward<ARGS>(args)...);
}