| 1 | #include "cuda_utils.h" |
| 2 | #ifdef USE_ROCM |
| 3 | #include <hip/hip_runtime.h> |
| 4 | #include <hip/hip_runtime_api.h> |
| 5 | #endif |
| 6 | |
| 7 | int64_t get_device_attribute(int64_t attribute, int64_t device_id) { |
| 8 | // Return the cached value on subsequent calls |
| 9 | static int value = [=]() { |
| 10 | int device = static_cast<int>(device_id); |
| 11 | if (device < 0) { |
| 12 | CUDA_CHECK(cudaGetDevice(&device)); |
| 13 | } |
| 14 | int value; |
| 15 | CUDA_CHECK(cudaDeviceGetAttribute( |
| 16 | &value, static_cast<cudaDeviceAttr>(attribute), device)); |
| 17 | return static_cast<int>(value); |
| 18 | }(); |
| 19 | |
| 20 | return value; |
| 21 | } |
| 22 | |
| 23 | int64_t get_max_shared_memory_per_block_device_attribute(int64_t device_id) { |
| 24 | int64_t attribute; |
| 25 | // https://docs.nvidia.com/cuda/cuda-runtime-api/group__CUDART__TYPES.html |
| 26 | // cudaDevAttrMaxSharedMemoryPerBlockOptin = 97 if not is_hip() else 74 |
| 27 | |
| 28 | #ifdef USE_ROCM |
| 29 | attribute = hipDeviceAttributeMaxSharedMemoryPerBlock; |
| 30 | #else |
| 31 | attribute = cudaDevAttrMaxSharedMemoryPerBlockOptin; |
| 32 | #endif |
| 33 | |
| 34 | return get_device_attribute(attribute, device_id); |
| 35 | } |