2025-02-12 19:51:51 -08:00
|
|
|
#include "cuda_utils.h"
|
2023-12-08 15:16:52 +08:00
|
|
|
#ifdef USE_ROCM
|
|
|
|
#include <hip/hip_runtime.h>
|
2024-01-26 15:41:10 -05:00
|
|
|
#include <hip/hip_runtime_api.h>
|
2023-12-08 15:16:52 +08:00
|
|
|
#endif
|
2025-02-12 19:51:51 -08:00
|
|
|
|
2024-06-09 16:23:30 -04:00
|
|
|
int64_t get_device_attribute(int64_t attribute, int64_t device_id) {
|
2025-02-12 19:51:51 -08:00
|
|
|
// Return the cached value on subsequent calls
|
|
|
|
static int value = [=]() {
|
|
|
|
int device = static_cast<int>(device_id);
|
|
|
|
if (device < 0) {
|
|
|
|
CUDA_CHECK(cudaGetDevice(&device));
|
|
|
|
}
|
|
|
|
int value;
|
|
|
|
CUDA_CHECK(cudaDeviceGetAttribute(
|
|
|
|
&value, static_cast<cudaDeviceAttr>(attribute), device));
|
|
|
|
return static_cast<int>(value);
|
|
|
|
}();
|
|
|
|
|
2024-05-22 03:18:41 -04:00
|
|
|
return value;
|
2023-09-26 22:27:13 -07:00
|
|
|
}
|
2024-01-26 15:41:10 -05:00
|
|
|
|
2024-06-09 16:23:30 -04:00
|
|
|
int64_t get_max_shared_memory_per_block_device_attribute(int64_t device_id) {
|
|
|
|
int64_t attribute;
|
2024-05-22 03:18:41 -04:00
|
|
|
// https://docs.nvidia.com/cuda/cuda-runtime-api/group__CUDART__TYPES.html
|
|
|
|
// cudaDevAttrMaxSharedMemoryPerBlockOptin = 97 if not is_hip() else 74
|
2024-01-26 15:41:10 -05:00
|
|
|
|
|
|
|
#ifdef USE_ROCM
|
2024-05-22 03:18:41 -04:00
|
|
|
attribute = hipDeviceAttributeMaxSharedMemoryPerBlock;
|
2024-01-26 15:41:10 -05:00
|
|
|
#else
|
2024-05-22 03:18:41 -04:00
|
|
|
attribute = cudaDevAttrMaxSharedMemoryPerBlockOptin;
|
2024-01-26 15:41:10 -05:00
|
|
|
#endif
|
|
|
|
|
2024-05-22 03:18:41 -04:00
|
|
|
return get_device_attribute(attribute, device_id);
|
2024-01-26 15:41:10 -05:00
|
|
|
}
|