From 6e0611029691ece867faf28d6af98f1e788eb9e0 Mon Sep 17 00:00:00 2001 From: Cory Levels Date: Thu, 5 Mar 2020 11:37:18 -0800 Subject: [PATCH 1/2] Rewrite OpenCL device discovery to SYCL. Signed-off-by: Cory Levels --- sycl/tools/CMakeLists.txt | 2 ++ sycl/tools/get_device_count_by_type.cpp | 48 +++++++------------------ 2 files changed, 15 insertions(+), 35 deletions(-) diff --git a/sycl/tools/CMakeLists.txt b/sycl/tools/CMakeLists.txt index dd921f969c66b..1ea85e69e81fb 100644 --- a/sycl/tools/CMakeLists.txt +++ b/sycl/tools/CMakeLists.txt @@ -4,7 +4,9 @@ set(CMAKE_CXX_EXTENSIONS OFF) add_executable(get_device_count_by_type get_device_count_by_type.cpp) add_dependencies(get_device_count_by_type ocl-headers ocl-icd) +target_include_directories(get_device_count_by_type PRIVATE "${sycl_inc_dir}") target_link_libraries(get_device_count_by_type + PRIVATE sycl PRIVATE OpenCL::Headers PRIVATE ${OpenCL_LIBRARIES} ) diff --git a/sycl/tools/get_device_count_by_type.cpp b/sycl/tools/get_device_count_by_type.cpp index 5611685889fac..bf876dd7e0f9b 100644 --- a/sycl/tools/get_device_count_by_type.cpp +++ b/sycl/tools/get_device_count_by_type.cpp @@ -8,6 +8,7 @@ #include #include +#include #ifdef USE_PI_CUDA #include @@ -17,6 +18,8 @@ #include #include +using namespace cl::sycl; + static const std::string help = " Help\n" " Example: ./get_device_count_by_type cpu opencl\n" @@ -61,54 +64,29 @@ int main(int argc, char* argv[]) { } #endif // USE_PI_CUDA - cl_device_type device_type; + info::device_type device_type; if (type == "cpu") { - device_type = CL_DEVICE_TYPE_CPU; + device_type = info::device_type::cpu; } else if (type == "gpu") { - device_type = CL_DEVICE_TYPE_GPU; + device_type = info::device_type::gpu; } else if (type == "accelerator") { - device_type = CL_DEVICE_TYPE_ACCELERATOR; + device_type = info::device_type::accelerator; } else if (type == "default") { - device_type = CL_DEVICE_TYPE_DEFAULT; + device_type = info::device_type::automatic; } else if (type == "all") { - device_type = CL_DEVICE_TYPE_ALL; + device_type = info::device_type::all; } else { std::cout << "0:Incorrect device type." << std::endl << help << std::endl; return 0; } - cl_int iRet = CL_SUCCESS; - cl_uint platformCount = 0; - - iRet = clGetPlatformIDs(0, nullptr, &platformCount); - if (iRet != CL_SUCCESS) { - if (iRet == CL_PLATFORM_NOT_FOUND_KHR) { - std::cout << "0:OpenCL runtime not found " << std::endl; - } else { - std::cout << "0:A problem at calling function clGetPlatformIDs count " - << iRet << std::endl; - } - return 0; - } - - std::vector platforms(platformCount); - - iRet = clGetPlatformIDs(platformCount, &platforms[0], nullptr); - if (iRet != CL_SUCCESS) { - std::cout << "0:A problem at when calling function clGetPlatformIDs ids " << iRet << std::endl; - return 0; - } - - for (cl_uint i = 0; i < platformCount; i++) { - cl_uint deviceCountPart = 0; - iRet = clGetDeviceIDs(platforms[i], device_type, 0, nullptr, &deviceCountPart); - if (iRet == CL_SUCCESS) { - deviceCount += deviceCountPart; - } + std::vector platforms(platform::get_platforms()); + for (cl_uint i = 0; i < platforms.size(); i++) { + std::vector result = platforms[i].get_devices(device_type); + deviceCount += result.size(); } std::cout << deviceCount << ":" << backend << std::endl; - return 0; } From 4882fa6259997cd56d926c26d13cbc5dae20eac7 Mon Sep 17 00:00:00 2001 From: clevels <59889830+clevels@users.noreply.github.com> Date: Tue, 28 Apr 2020 10:45:34 -0500 Subject: [PATCH 2/2] Update sycl/tools/get_device_count_by_type.cpp Co-Authored-By: Alexey Bader --- sycl/tools/get_device_count_by_type.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/sycl/tools/get_device_count_by_type.cpp b/sycl/tools/get_device_count_by_type.cpp index bf876dd7e0f9b..092476beddf57 100644 --- a/sycl/tools/get_device_count_by_type.cpp +++ b/sycl/tools/get_device_count_by_type.cpp @@ -6,8 +6,6 @@ // //===----------------------------------------------------------------------===// -#include -#include #include #ifdef USE_PI_CUDA