Skip to content
Snippets Groups Projects
Unverified Commit 38337981 authored by Benjamin Cumming's avatar Benjamin Cumming Committed by GitHub
Browse files

remove ARB_HAVE_GPU from header file (#574)

Move implementation of `gpu_context` from header to `cpp` file, so that `ARB_WITH_CUDA` doesn't leak from library implementation.
parent 2c135d75
No related branches found
No related tags found
No related merge requests found
#pragma once
#include <algorithm>
#include <memory>
#include <arbor/assert.hpp>
......
#include <memory>
#ifdef ARB_HAVE_GPU
#include <cuda.h>
#include <cuda_runtime.h>
#endif
#include "gpu_context.hpp"
namespace arb {
bool gpu_context::has_concurrent_managed_access() const {
return attributes_ & gpu_flags::has_concurrent_managed_access;
}
bool gpu_context::has_atomic_double() const {
return attributes_ & gpu_flags::has_atomic_double;
}
#ifndef ARB_HAVE_GPU
gpu_context::gpu_context(): has_gpu_(false), attributes_(0) {}
void gpu_context::synchronize_for_managed_access() const {}
#else
gpu_context::gpu_context(): has_gpu_(true), attributes_(0) {
cudaDeviceProp prop;
cudaGetDeviceProperties(&prop, 0);
if (prop.concurrentManagedAccess) {
attributes_ |= gpu_flags::has_concurrent_managed_access;
}
if (prop.major*100 + prop.minor >= 600) {
attributes_ |= gpu_flags::has_atomic_double;
}
};
void gpu_context::synchronize_for_managed_access() const {
if(!has_concurrent_managed_access()) {
cudaDeviceSynchronize();
}
}
#endif
std::shared_ptr<gpu_context> make_gpu_context() {
return std::make_shared<gpu_context>();
}
......
#include <memory>
#ifdef ARB_HAVE_GPU
#include <cuda.h>
#include <cuda_runtime.h>
#endif
#pragma once
namespace arb {
#ifndef ARB_HAVE_GPU
struct gpu_context {
bool has_gpu_;
size_t attributes_;
gpu_context(): has_gpu_(false), attributes_(0) {}
};
#else
enum gpu_flags {
has_concurrent_managed_access = 1,
has_atomic_double = 2
......@@ -26,32 +11,11 @@ struct gpu_context {
bool has_gpu_;
size_t attributes_;
gpu_context() : has_gpu_(true) {
cudaDeviceProp prop;
cudaGetDeviceProperties(&prop, 0);
attributes_ = 0;
if (prop.concurrentManagedAccess) {
attributes_ |= gpu_flags::has_concurrent_managed_access;
}
if (prop.major*100 + prop.minor >= 600) {
attributes_ |= gpu_flags::has_atomic_double;
}
};
bool has_concurrent_managed_access() {
return attributes_ & gpu_flags::has_concurrent_managed_access;
}
bool has_atomic_double() {
return attributes_ & gpu_flags::has_atomic_double;
}
gpu_context();
void synchronize_for_managed_access() {
if(!has_concurrent_managed_access()) {
cudaDeviceSynchronize();
}
}
bool has_concurrent_managed_access() const;
bool has_atomic_double() const;
void synchronize_for_managed_access() const;
};
#endif
}
......@@ -27,15 +27,19 @@ add_custom_command(
set(arb_features)
if(ARB_WITH_ASSERTIONS)
# define ARB_ASSERT_ENABLED in version.hpp
list(APPEND arb_features ASSERT)
endif()
if(ARB_WITH_MPI)
# define ARB_MPI_ENABLED in version.hpp
list(APPEND arb_features MPI)
endif()
if(ARB_WITH_CUDA)
# define ARB_GPU_ENABLED in version.hpp
list(APPEND arb_features GPU)
endif()
if(ARB_WITH_PROFILING)
# define ARB_PROFILE_ENABLED in version.hpp
list(APPEND arb_features PROFILE)
endif()
......
......@@ -140,6 +140,5 @@ add_executable(unit ${unit_sources} ${test_mech_sources})
add_dependencies(unit build_test_mods)
target_compile_options(unit PRIVATE ${ARB_CXXOPT_ARCH})
target_compile_definitions(unit PRIVATE "-DDATADIR=\"${CMAKE_CURRENT_SOURCE_DIR}/swc\"")
target_compile_definitions(unit PRIVATE ARB_HAVE_GPU)
target_include_directories(unit PRIVATE "${CMAKE_CURRENT_BINARY_DIR}")
target_link_libraries(unit PRIVATE gtest arbor arbor-private-headers arbor-aux)
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