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
|
2024-06-09 16:23:30 -04:00
|
|
|
int64_t get_device_attribute(int64_t attribute, int64_t device_id) {
|
2024-05-22 03:18:41 -04:00
|
|
|
int device, value;
|
|
|
|
if (device_id < 0) {
|
|
|
|
cudaGetDevice(&device);
|
|
|
|
} else {
|
|
|
|
device = device_id;
|
|
|
|
}
|
|
|
|
cudaDeviceGetAttribute(&value, static_cast<cudaDeviceAttr>(attribute),
|
|
|
|
device);
|
|
|
|
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
|
|
|
}
|