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..092476beddf57 100644 --- a/sycl/tools/get_device_count_by_type.cpp +++ b/sycl/tools/get_device_count_by_type.cpp @@ -6,8 +6,7 @@ // //===----------------------------------------------------------------------===// -#include -#include +#include #ifdef USE_PI_CUDA #include @@ -17,6 +16,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 +62,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; }