8000 [SYCL][ROCm] Add ROCm to get_device_count_by_type by npmiller · Pull Request #4113 · intel/llvm · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

[SYCL][ROCm] Add ROCm to get_device_count_by_type #4113

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions sycl/tools/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,13 @@ target_compile_definitions(get_device_count_by_type
PRIVATE
$<$<BOOL:${SYCL_BUILD_PI_CUDA}>:USE_PI_CUDA>
$<$<BOOL:${SYCL_BUILD_PI_ROCM}>:USE_PI_ROCM>
# For ROCm set the HIP define depending on the platform
$<$<AND:$<BOOL:${SYCL_BUILD_PI_ROCM}>,$<STREQUAL:${SYCL_BUILD_PI_ROCM_PLATFORM},AMD>>:__HIP_PLATFORM_AMD__>
$<$<AND:$<BOOL:${SYCL_BUILD_PI_ROCM}>,$<STREQUAL:${SYCL_BUILD_PI_ROCM_PLATFORM},NVIDIA>>:__HIP_PLATFORM_NVIDIA__>
)

if(SYCL_BUILD_PI_ROCM)
target_include_directories(get_device_count_by_type
PRIVATE
${SYCL_BUILD_PI_ROCM_INCLUDE_DIR})
endif()
51 changes: 50 additions & 1 deletion sycl/tools/get_device_count_by_type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
#include <cuda.h>
#endif // USE_PI_CUDA

#ifdef USE_PI_ROCM
#include <hip/hip_runtime.h>
#endif // USE_PI_ROCM

#include <algorithm>
#include <cstdlib>
#include <cstring>
Expand All @@ -32,7 +36,7 @@ static const std::string help =
" Help\n"
" Example: ./get_device_count_by_type cpu opencl\n"
" Supported device types: cpu/gpu/accelerator/default/all\n"
" Supported backends: PI_CUDA/PI_OPENCL/PI_LEVEL_ZERO \n"
" Supported backends: PI_CUDA/PI_ROCM/PI_OPENCL/PI_LEVEL_ZERO \n"
" Output format: <number_of_devices>:<additional_Information>";

// Return the string with all characters translated to lower case.
Expand Down Expand Up @@ -224,6 +228,49 @@ static bool queryCUDA(cl_device_type deviceType, cl_uint &deviceCount,
#endif
}

static bool queryROCm(cl_device_type deviceType, cl_uint &deviceCount,
std::string &msg) {
deviceCount = 0u;
#ifdef USE_PI_ROCM
switch (deviceType) {
case CL_DEVICE_TYPE_DEFAULT: // Fall through.
case CL_DEVICE_TYPE_ALL: // Fall through.
case CL_DEVICE_TYPE_GPU: {
int count = 0;
hipError_t err = hipGetDeviceCount(&count);
if (err != hipSuccess || count < 0) {
msg = "ERROR: ROCm error querying device count";
return false;
}
if (count < 1) {
msg = "ERROR: ROCm no device found";
return false;
}
deviceCount = static_cast<cl_uint>(count);
#if defined(__HIP_PLATFORM_AMD__)
msg = "rocm-amd ";
#elif defined(__HIP_PLATFORM_NVIDIA__)
msg = "rocm-nvidia ";
#else
#error("Must define one of __HIP_PLATFORM_AMD__ or __HIP_PLATFORM_NVIDIA__");
#endif
msg += deviceTypeToString(deviceType);
return true;
} break;
default:
msg = "WARNING: ROCm unsupported device type ";
msg += deviceTypeToString(deviceType);
return true;
}
#else
(void)deviceType;
msg = "ERROR: ROCm not supported";
deviceCount = 0u;

return false;
#endif
}

int main(int argc, char *argv[]) {
if (argc < 3) {
std::cout << "0:ERROR: Please set a device type and backend to find"
Expand Down Expand Up @@ -264,6 +311,8 @@ int main(int argc, char *argv[]) {
querySuccess = queryLevelZero(deviceType, deviceCount, msg);
} else if (backend == "cuda" || backend == "pi_cuda") {
querySuccess = queryCUDA(deviceType, deviceCount, msg);
} else if (backend == "rocm" || backend == "pi_rocm") {
querySuccess = queryROCm(deviceType, deviceCount, msg);
} else {
msg = "ERROR: Unknown backend " + backend + "\n" + help + "\n";
}
Expand Down
0