Skip to content

Commit fb1ece9

Browse files
committed
Refactor: detail/compute_capability -> detail/gpu/cuda/compute_capability which is cuda-only.
Usage is guarded out, and previously macro'd out tests are now enabled (but heterogenous AMD systems may encounter test failures)
1 parent 69b6399 commit fb1ece9

14 files changed

Lines changed: 190 additions & 164 deletions

File tree

include/flamegpu/detail/compute_capability.cuh renamed to include/flamegpu/detail/gpu/cuda/compute_capability.cuh

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
#ifndef INCLUDE_FLAMEGPU_DETAIL_COMPUTE_CAPABILITY_CUH_
2-
#define INCLUDE_FLAMEGPU_DETAIL_COMPUTE_CAPABILITY_CUH_
1+
#ifndef INCLUDE_FLAMEGPU_DETAIL_GPU_CUDA_COMPUTE_CAPABILITY_CUH_
2+
#define INCLUDE_FLAMEGPU_DETAIL_GPU_CUDA_COMPUTE_CAPABILITY_CUH_
33

4-
// Todo: device on the AMD equivalent compute capability stuff
5-
#ifdef FLAMEGPU_USE_CUDA
4+
#if defined(FLAMEGPU_USE_CUDA)
65

76
#include <vector>
87
#include <string>
@@ -12,10 +11,17 @@
1211

1312
namespace flamegpu {
1413
namespace detail {
14+
namespace gpu {
15+
/**
16+
* CUDA-specifc internal code
17+
*/
18+
namespace cuda {
1519
namespace compute_capability {
1620

1721
/**
1822
* get the compute capability for a device
23+
*
24+
* @note CUDA only
1925
* @param deviceIndex the index of the device to be queried
2026
* @return integer value representing the compute capability, i.e 70 for SM_70
2127
*/
@@ -27,6 +33,8 @@ int getComputeCapability(int deviceIndex);
2733
* Extracts the first element from `__CUDA_ARCH_LIST__` which is an ordered list of integer architectures passed to nvcc, with the 0th value being the lowest.
2834
*
2935
* __CUDA_ARCH_LIST__ values are 3 or 4 digits long, with SM_80 becoming 800, or SM_103 becoming 1030, so they are scaled back down to match SM_ notation.
36+
*
37+
* @note CUDA only
3038
*
3139
* @return the minimum compute capability from __CUDA_ARCH_LIST__ as a 2+ digit integer, i.e. 80 for SM_80, or 0 if __CUDA_ARCH_LIST__ was undefined
3240
*/
@@ -44,6 +52,9 @@ std::string compiledCompiledComputeCapabilitiesString();
4452
* This assumes JIT support is enabled for future (major) architectures.
4553
* If __CUDA_ARCH_LIST__ could not be used to extract a minimum compiled architecture, no decision can be made so it is assumed to be successful.
4654
* If a or f post-fixed architectures are used, this check may also be insufficient for forwards compatibilty, but this requires an SM >= 100 device to test this on.
55+
*
56+
* @note CUDA only
57+
*
4758
* @param deviceIndex the index of the device to be checked.
4859
* @return boolean indicating if the executable can run on the specified device.
4960
*/
@@ -52,6 +63,9 @@ bool checkComputeCapability(int deviceIndex);
5263
/**
5364
* Get the comptue capabilities supported by the linked NVRTC, irrespective of whether FLAMEGPU was configured for that architecture.
5465
* CUDA 11.2 or greater provides methods to make this dynamic. Older versions of CUDA are hardcoded (11.1, 11.0 and 10.x only).
66+
*
67+
* @note CUDA only
68+
*
5569
* @return vector of compute capability integers ((major * 10) + minor) in ascending order
5670
*/
5771
std::vector<int> getNVRTCSupportedComputeCapabilties();
@@ -62,16 +76,20 @@ std::vector<int> getNVRTCSupportedComputeCapabilties();
6276
*
6377
* This method has been separated from JitifyCache::preprocessKernel so that it can be tested generically, without having to write tests which are relative to the linked nvrtc and/or the current device.
6478
*
79+
* @note CUDA only
80+
*
6581
* @param target compute capability to find the best match for
6682
* @param archictectures a vector of architectures in ascending order
6783
* @return the best compute capability to use (the largest value LE target), or 0 if none are appropriate.
6884
*/
6985
int selectAppropraiteComputeCapability(const int target, const std::vector<int>& architectures);
7086

7187
} // namespace compute_capability
88+
} // namespace cuda
89+
} // namespace gpu
7290
} // namespace detail
7391
} // namespace flamegpu
7492

75-
#endif // FLAMEGPU_USE_CUDA
93+
#endif // defined(FLAMEGPU_USE_CUDA)
7694

77-
#endif // INCLUDE_FLAMEGPU_DETAIL_COMPUTE_CAPABILITY_CUH_
95+
#endif // INCLUDE_FLAMEGPU_DETAIL_GPU_CUDA_COMPUTE_CAPABILITY_CUH_

src/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -287,10 +287,10 @@ SET(SRC_INCLUDE
287287
${FLAMEGPU_ROOT}/include/flamegpu/detail/gpu/types.hpp
288288
${FLAMEGPU_ROOT}/include/flamegpu/detail/gpu/gpu_api_error_checking.cuh
289289
${FLAMEGPU_ROOT}/include/flamegpu/detail/gpu/device_name.hpp
290+
${FLAMEGPU_ROOT}/include/flamegpu/detail/gpu/cuda/compute_capability.cuh
290291
${FLAMEGPU_ROOT}/include/flamegpu/detail/Any.h
291292
${FLAMEGPU_ROOT}/include/flamegpu/detail/demangle.h
292293
${FLAMEGPU_ROOT}/include/flamegpu/detail/type_decode.h
293-
${FLAMEGPU_ROOT}/include/flamegpu/detail/compute_capability.cuh
294294
${FLAMEGPU_ROOT}/include/flamegpu/detail/curand.cuh
295295
${FLAMEGPU_ROOT}/include/flamegpu/detail/wddm.cuh
296296
${FLAMEGPU_ROOT}/include/flamegpu/detail/CUDAEventTimer.cuh
@@ -386,8 +386,8 @@ SET(SRC_FLAMEGPU
386386
${FLAMEGPU_ROOT}/src/flamegpu/io/Telemetry.cpp
387387
${FLAMEGPU_ROOT}/src/flamegpu/util/cleanup.cu
388388
${FLAMEGPU_ROOT}/src/flamegpu/detail/gpu/device_name.cu
389+
${FLAMEGPU_ROOT}/src/flamegpu/detail/gpu/cuda/compute_capability.cu
389390
${FLAMEGPU_ROOT}/src/flamegpu/detail/demangle.cpp
390-
${FLAMEGPU_ROOT}/src/flamegpu/detail/compute_capability.cu
391391
${FLAMEGPU_ROOT}/src/flamegpu/detail/wddm.cu
392392
${FLAMEGPU_ROOT}/src/flamegpu/detail/JitifyCache.cu
393393
${FLAMEGPU_ROOT}/src/flamegpu/detail/TestSuiteTelemetry.cpp

src/flamegpu/detail/JitifyCache.cu

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
#include "flamegpu/version.h"
1919
#include "flamegpu/exception/FLAMEGPUException.h"
20-
#include "flamegpu/detail/compute_capability.cuh"
20+
#include "flamegpu/detail/gpu/cuda/compute_capability.cuh"
2121
#include "flamegpu/util/nvtx.h"
2222
#include "flamegpu/detail/gpu/macros.hpp"
2323

@@ -396,7 +396,7 @@ std::unique_ptr<jitify2::LinkedProgramData> JitifyCache::buildProgram(
396396
#endif
397397

398398
// Set the cuda compuate capability architecture to optimize / generate for, based on the values supported by the current dynamiclaly linked nvrtc and the device in question.
399-
std::vector<int> nvrtcArchitectures = detail::compute_capability::getNVRTCSupportedComputeCapabilties();
399+
std::vector<int> nvrtcArchitectures = detail::gpu::cuda::compute_capability::getNVRTCSupportedComputeCapabilties();
400400
if (nvrtcArchitectures.size()) {
401401
int currentDeviceIdx = 0;
402402
if (FLAMEGPU_GPU_RUNTIME_SYMBOL(Success) == cudaGetDevice(&currentDeviceIdx)) {

src/flamegpu/detail/compute_capability.cu renamed to src/flamegpu/detail/gpu/cuda/compute_capability.cu

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
1-
#ifdef FLAMEGPU_USE_CUDA
1+
// only implemented for CUDA
2+
#if defined(FLAMEGPU_USE_CUDA)
23
#include <nvrtc.h>
3-
#endif // FLAMEGPU_USE_CUDA
44

55
#include <cassert>
66
#include <array>
77
#include <vector>
88
#include <string>
99

10-
#include "flamegpu/detail/compute_capability.cuh"
10+
#include "flamegpu/detail/gpu/cuda/compute_capability.cuh"
1111
#include "flamegpu/detail/gpu/gpu_api_error_checking.cuh"
1212
#include "flamegpu/detail/gpu/macros.hpp"
1313

14-
#ifdef FLAMEGPU_USE_CUDA
15-
1614
namespace flamegpu {
1715
namespace detail {
16+
namespace gpu {
17+
namespace cuda {
1818

1919
namespace {
2020
/**
@@ -137,7 +137,9 @@ int compute_capability::selectAppropraiteComputeCapability(const int target, con
137137
return maxArch;
138138
}
139139

140+
} // namespace cuda
141+
} // namespace gpu
140142
} // namespace detail
141143
} // namespace flamegpu
142144

143-
#endif // FLAMEGPU_USE_CUDA
145+
#endif // defined(FLAMEGPU_USE_CUDA)

src/flamegpu/detail/gpu/device_name.cu

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#include <set>
22
#include <string>
33

4-
#include "flamegpu/detail/compute_capability.cuh"
4+
#include "flamegpu/detail/gpu/cuda/compute_capability.cuh"
55
#include "flamegpu/detail/gpu/macros.hpp"
66
#include "flamegpu/detail/gpu/gpu_api_error_checking.cuh"
77

src/flamegpu/simulation/CUDAEnsemble.cu

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
#include "flamegpu/version.h"
2323
#include "flamegpu/model/ModelDescription.h"
2424
#include "flamegpu/simulation/RunPlanVector.h"
25-
#include "flamegpu/detail/compute_capability.cuh"
25+
#include "flamegpu/detail/gpu/cuda/compute_capability.cuh"
2626
#include "flamegpu/detail/SteadyClockTimer.h"
2727
#include "flamegpu/simulation/CUDASimulation.h"
2828
#include "flamegpu/io/StateWriterFactory.h"
@@ -174,21 +174,22 @@ unsigned int CUDAEnsemble::simulate(const RunPlanVector& plans) {
174174
devices = mpi->devicesForThisRank(devices);
175175
#endif // ifdef FLAMEGPU_ENABLE_MPI
176176

177-
// Check that each device is capable, and init cuda context
177+
// Check that each device is capable (CUDA only), and init cuda context
178178
for (auto d = devices.begin(); d != devices.end(); ++d) {
179-
// todo: HIP equiavalent
180-
#ifdef FLAMEGPU_USE_CUDA
181-
if (!detail::compute_capability::checkComputeCapability(*d)) {
182-
#else // FLAMEGPU_USE_CUDA
183-
if (false) {
184-
#endif // FLAMEGPU_USE_CUDA
179+
bool compatible_gpu_arch = true;
180+
// if CUDA, we can check the compute capability and emit a useful error if not compatible
181+
#if defined(FLAMEGPU_USE_CUDA)
182+
compatible_gpu_arch = detail::gpu::cuda::compute_capability::checkComputeCapability(*d)
183+
#endif // defined(FLAMEGPU_USE_CUDA)
184+
if (!compatible_gpu_arch) {
185185
// Emit a warning unless quiet verbosity was specified.
186186
if (config.verbosity >= Verbosity::Default) {
187187
fprintf(stderr, "FLAMEGPU2 has not been built with an appropriate compute capability for device %d, this device will not be used.\n", *d);
188188
}
189189
d = devices.erase(d);
190190
--d;
191191
} else {
192+
// Initialise the context on the device
192193
flamegpu::detail::gpuCheck(FLAMEGPU_GPU_RUNTIME_SYMBOL(SetDevice)(*d));
193194
flamegpu::detail::gpuCheck(flamegpu::detail::cuda::cudaFree(nullptr));
194195
}

src/flamegpu/simulation/CUDASimulation.cu

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
#include "flamegpu/simulation/detail/CUDAEnvironmentDirectedGraphBuffers.cuh"
2626
#include "flamegpu/simulation/detail/CUDAScanCompaction.h"
2727
#include "flamegpu/util/nvtx.h"
28-
#include "flamegpu/detail/compute_capability.cuh"
28+
#include "flamegpu/detail/gpu/cuda/compute_capability.cuh"
2929
#include "flamegpu/detail/SignalHandlers.h"
3030
#include "flamegpu/detail/wddm.cuh"
3131
#include "flamegpu/detail/SteadyClockTimer.h"
@@ -1570,16 +1570,15 @@ void CUDASimulation::applyConfig_derived() {
15701570
THROW exception::InvalidCUDAdevice("Unable to set CUDA device to '%d' after the CUDASimulation has already initialised on device '%d'.", config.device_id, deviceInitialised);
15711571
}
15721572
1573-
// Todo: HIP equivalent
1574-
#ifdef FLAMEGPU_USE_CUDA
1575-
// Check the compute capability of the device, throw an exception if not valid for the executable.
1576-
if (!detail::compute_capability::checkComputeCapability(static_cast<int>(config.device_id))) {
1577-
int min_cc = detail::compute_capability::minimumCompiledComputeCapability();
1578-
std::string compiled_ccs = detail::compute_capability::compiledCompiledComputeCapabilitiesString();
1579-
int cc = detail::compute_capability::getComputeCapability(static_cast<int>(config.device_id));
1573+
#if defined(FLAMEGPU_USE_CUDA)
1574+
// On CUDA, check the compute capability of the device, throw an exception if not valid for the executable.
1575+
if (!detail::gpu::cuda::compute_capability::checkComputeCapability(static_cast<int>(config.device_id))) {
1576+
int min_cc = detail::gpu::cuda::compute_capability::minimumCompiledComputeCapability();
1577+
std::string compiled_ccs = detail::gpu::cuda::compute_capability::compiledCompiledComputeCapabilitiesString();
1578+
int cc = detail::gpu::cuda::compute_capability::getComputeCapability(static_cast<int>(config.device_id));
15801579
THROW exception::InvalidCUDAComputeCapability("Error application compiled for CUDA Compute Capabilities \"%s\". Rebuild including compute capability <= %d for device %u.", compiled_ccs.c_str(), cc, config.device_id);
15811580
}
1582-
#endif // FLAMEGPU_USE_CUDA
1581+
#endif // defined(FLAMEGPU_USE_CUDA)
15831582
15841583
cudaStatus = FLAMEGPU_GPU_RUNTIME_SYMBOL(SetDevice)(static_cast<int>(config.device_id));
15851584
if (cudaStatus != FLAMEGPU_GPU_RUNTIME_SYMBOL(Success)) {
@@ -1622,17 +1621,15 @@ void CUDASimulation::reseed(const uint64_t seed) {
16221621
void CUDASimulation::initialiseSingletons() {
16231622
// Only do this once.
16241623
if (!singletonsInitialised) {
1625-
// If the device has not been specified, also check the compute capability is OK
1626-
// Check the compute capability of the device, throw an exception if not valid for the executable.
1627-
// todo: HIP equivalent
1628-
#ifdef FLAMEGPU_USE_CUDA
1629-
if (!detail::compute_capability::checkComputeCapability(static_cast<int>(config.device_id))) {
1630-
int min_cc = detail::compute_capability::minimumCompiledComputeCapability();
1631-
std::string compiled_ccs = detail::compute_capability::compiledCompiledComputeCapabilitiesString();
1632-
int cc = detail::compute_capability::getComputeCapability(static_cast<int>(config.device_id));
1624+
#if defined(FLAMEGPU_USE_CUDA)
1625+
// On CUDA, Check the compute capability of the device, throw an exception if not valid for the executable.
1626+
if (!detail::gpu::cuda::compute_capability::checkComputeCapability(static_cast<int>(config.device_id))) {
1627+
int min_cc = detail::gpu::cuda::compute_capability::minimumCompiledComputeCapability();
1628+
std::string compiled_ccs = detail::gpu::cuda::compute_capability::compiledCompiledComputeCapabilitiesString();
1629+
int cc = detail::gpu::cuda::compute_capability::getComputeCapability(static_cast<int>(config.device_id));
16331630
THROW exception::InvalidCUDAComputeCapability("Error application compiled for CUDA Compute Capabilities \"%s\". Rebuild including compute capability <= %d for device %u.", compiled_ccs.c_str(), cc, config.device_id);
16341631
}
1635-
#endif // FLAMEGPU_USE_CUDA
1632+
#endif // defined(FLAMEGPU_USE_CUDA)
16361633
flamegpu::detail::gpuCheck(FLAMEGPU_GPU_RUNTIME_SYMBOL(GetDevice)(&deviceInitialised));
16371634
// Get references to all required singleton and store in the instance.
16381635
singletons = new Singletons((!submodel)?

src/flamegpu/simulation/detail/CUDAAgent.cu

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ namespace cub = hipcub;
5757
#include "flamegpu/runtime/detail/curve/HostCurve.cuh"
5858
#include "flamegpu/runtime/detail/curve/curve_rtc.cuh"
5959
#include "flamegpu/simulation/detail/CUDAScatter.cuh"
60-
#include "flamegpu/detail/compute_capability.cuh"
60+
#include "flamegpu/detail/gpu/cuda/compute_capability.cuh"
6161
#include "flamegpu/util/nvtx.h"
6262
#include "flamegpu/runtime/agent/DeviceAgentVector_impl.h"
6363
#include "flamegpu/simulation/detail/CUDAEnvironmentDirectedGraphBuffers.cuh"

tests/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ endif()
1414
# Prepare source files for the tests target
1515
SET(TESTS_SRC
1616
${CMAKE_CURRENT_SOURCE_DIR}/test_cases/detail/gpu/test_device_name.cu
17-
${CMAKE_CURRENT_SOURCE_DIR}/test_cases/detail/test_compute_capability.cu
17+
${CMAKE_CURRENT_SOURCE_DIR}/test_cases/detail/gpu/cuda/test_compute_capability.cu
1818
${CMAKE_CURRENT_SOURCE_DIR}/test_cases/detail/test_cuda.cu
1919
${CMAKE_CURRENT_SOURCE_DIR}/test_cases/detail/test_wddm.cu
2020
${CMAKE_CURRENT_SOURCE_DIR}/test_cases/detail/test_dependency_versions.cu

0 commit comments

Comments
 (0)