From 8957558e69447fe70b4f39604d256bb01b320e0e Mon Sep 17 00:00:00 2001 From: Kris Rowe Date: Thu, 14 Dec 2023 21:24:47 -0600 Subject: [PATCH] Refactor OpenCL mode and update CI testing (#730) * Refactor OpenCL utilities and device creation. * Update OpenCL default device type. * Only run math function test for active modes. * Update GitHub workflows. * Remove OpenCL from math function tests. --- .github/workflows/build.yml | 7 +- src/occa/internal/modes/opencl/device.cpp | 38 +-- src/occa/internal/modes/opencl/device.hpp | 5 +- src/occa/internal/modes/opencl/polyfill.hpp | 11 +- .../internal/modes/opencl/registration.cpp | 81 +++++-- src/occa/internal/modes/opencl/utils.cpp | 219 ++++++------------ src/occa/internal/modes/opencl/utils.hpp | 43 ++-- tests/src/math/fpMath.cpp | 21 +- tests/src/math/intMath.cpp | 19 +- 9 files changed, 191 insertions(+), 253 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 4c513a299..b9aabd753 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -54,6 +54,7 @@ jobs: os: ubuntu-22.04 CC: icx CXX: icpx + FC: ifx CXXFLAGS: -Wno-uninitialized OCCA_COVERAGE: 0 useCMake: true @@ -124,14 +125,16 @@ jobs: OCCA_CXX: ${{ matrix.CXX }} run: | source /opt/intel/oneapi/setvars.sh + export SYCL_ROOT=/opt/intel/oneapi/compiler/latest cmake -S . -B build \ -DCMAKE_BUILD_TYPE="RelWithDebInfo" \ -DCMAKE_INSTALL_PREFIX=install \ -DCMAKE_C_COMPILER=${CC} \ -DCMAKE_CXX_COMPILER=${CXX} \ + -DCMAKE_Fortran_COMPILER=${FC} \ -DENABLE_TESTS=ON \ -DENABLE_EXAMPLES=ON \ - -DCMAKE_PREFIX_PATH="/opt/intel/oneapi/compiler/latest/linux;/opt/intel/oneapi/compiler/latest/linux/compiler" + -DENABLE_FORTRAN=ON - name: CMake build if: ${{ matrix.useCMake && !matrix.useoneAPI}} @@ -179,7 +182,7 @@ jobs: run: | source /opt/intel/oneapi/setvars.sh export ONEAPI_DEVICE_SELECTOR=*:cpu - ctest --test-dir build --progress --output-on-failure --parallel 8 --schedule-random -E "examples_cpp_arrays-opencl|examples_cpp_for_loops-opencl|examples_cpp_generic_inline_kernel-opencl|examples_cpp_shared_memory-opencl|examples_cpp_nonblocking_streams-opencl|examples_cpp_for_loops-dpcpp|examples_cpp_arrays-dpcpp|examples_cpp_generic_inline_kernel-dpcpp|examples_cpp_nonblocking_streams-dpcpp" + ctest --test-dir build --progress --output-on-failure --parallel 8 --schedule-random -E "opencl-*|examples_cpp_for_loops-dpcpp|examples_cpp_arrays-dpcpp|examples_cpp_generic_inline_kernel-dpcpp|examples_cpp_nonblocking_streams-dpcpp" - name: Upload code coverage if: ${{ matrix.OCCA_COVERAGE }} diff --git a/src/occa/internal/modes/opencl/device.cpp b/src/occa/internal/modes/opencl/device.cpp index f328dc943..15139d890 100644 --- a/src/occa/internal/modes/opencl/device.cpp +++ b/src/occa/internal/modes/opencl/device.cpp @@ -17,27 +17,10 @@ namespace occa { namespace opencl { - device::device(const occa::json &properties_) : - occa::launchedModeDevice_t(properties_) { + device::device(const occa::json &properties_, cl_device_id clDevice_) : + occa::launchedModeDevice_t(properties_), clDevice(clDevice_) { - if (!properties.has("wrapped")) { - cl_int error; - OCCA_ERROR("[OpenCL] device not given a [platform_id] integer", - properties.has("platform_id") && - properties["platform_id"].isNumber()); - - OCCA_ERROR("[OpenCL] device not given a [device_id] integer", - properties.has("device_id") && - properties["device_id"].isNumber()); - - platformID = properties.get("platform_id"); - deviceID = properties.get("device_id"); - - clDevice = opencl::deviceID(platformID, deviceID); - - clContext = clCreateContext(NULL, 1, &clDevice, NULL, NULL, &error); - OCCA_OPENCL_ERROR("Device: Creating Context", error); - } + clContext = createContextFromDevice(clDevice); occa::json &kernelProps = properties["kernel"]; std::string compilerFlags; @@ -68,7 +51,7 @@ namespace occa { kernelProps["compiler_flags"] = compilerFlags; - arch = deviceName(platformID, deviceID); + arch = opencl::deviceStrInfo(clDevice, CL_DEVICE_NAME); } device::~device() { @@ -85,13 +68,14 @@ namespace occa { hash_t device::hash() const { if (!hash_.initialized) { + cl_platform_id platform_id = getPlatformFromDevice(clDevice); std::stringstream ss; - ss << "platform name: " << opencl::platformName(platformID) - << " platform vendor: " << opencl::platformVendor(platformID) - << " platform version: " << opencl::platformVersion(platformID) - << " device name: " << opencl::deviceName(platformID,deviceID) - << " device vendor: " << opencl::deviceVendor(platformID,deviceID) - << " device version: " << opencl::deviceVersion(platformID,deviceID); + ss << "platform name: " << opencl::platformName(platform_id) + << " platform vendor: " << opencl::platformVendor(platform_id) + << " platform version: " << opencl::platformVersion(platform_id) + << " device name: " << opencl::deviceName(clDevice) + << " device vendor: " << opencl::deviceVendor(clDevice) + << " device version: " << opencl::deviceVersion(clDevice); hash_ = occa::hash(ss.str()); } return hash_; diff --git a/src/occa/internal/modes/opencl/device.hpp b/src/occa/internal/modes/opencl/device.hpp index 34e4182b5..24098e70c 100644 --- a/src/occa/internal/modes/opencl/device.hpp +++ b/src/occa/internal/modes/opencl/device.hpp @@ -9,18 +9,15 @@ namespace occa { class info_t; class device : public occa::launchedModeDevice_t { - friend cl_context getContext(occa::device device); private: mutable hash_t hash_; public: - int platformID, deviceID; - cl_device_id clDevice; cl_context clContext; - device(const occa::json &properties_); + device(const occa::json &properties_, cl_device_id clDevice_); virtual ~device(); bool hasSeparateMemorySpace() const override; diff --git a/src/occa/internal/modes/opencl/polyfill.hpp b/src/occa/internal/modes/opencl/polyfill.hpp index 31d701b3a..197615acf 100644 --- a/src/occa/internal/modes/opencl/polyfill.hpp +++ b/src/occa/internal/modes/opencl/polyfill.hpp @@ -82,12 +82,13 @@ namespace occa { static cl_device_info CL_DEVICE_VERSION = 5; static cl_device_info CL_DEVICE_MAX_WORK_ITEM_DIMENSIONS = 6; static cl_device_info CL_DEVICE_MAX_WORK_ITEM_SIZES = 7; + static cl_device_info CL_DEVICE_PLATFORM = 8; - static cl_device_type CL_DEVICE_TYPE_ACCELERATOR = 0; - static cl_device_type CL_DEVICE_TYPE_CPU = 1; - static cl_device_type CL_DEVICE_TYPE_GPU = 2; - static cl_device_type CL_DEVICE_TYPE_ALL = 3; - static cl_device_type CL_DEVICE_TYPE_DEFAULT = 4; + static constexpr cl_device_type CL_DEVICE_TYPE_ACCELERATOR = 0; + static constexpr cl_device_type CL_DEVICE_TYPE_CPU = 1; + static constexpr cl_device_type CL_DEVICE_TYPE_GPU = 2; + static constexpr cl_device_type CL_DEVICE_TYPE_ALL = 3; + static constexpr cl_device_type CL_DEVICE_TYPE_DEFAULT = 4; static cl_kernel_work_group_info CL_KERNEL_WORK_GROUP_SIZE = 0; diff --git a/src/occa/internal/modes/opencl/registration.cpp b/src/occa/internal/modes/opencl/registration.cpp index 8c7bff234..bde3265d9 100644 --- a/src/occa/internal/modes/opencl/registration.cpp +++ b/src/occa/internal/modes/opencl/registration.cpp @@ -17,46 +17,54 @@ namespace occa { } styling::section& openclMode::getDescription() { - static styling::section section("OpenCL"); + static styling::section section(modeName); if (section.size() == 0) { - int platformCount = getPlatformCount(); - for (int platformId = 0; platformId < platformCount; ++platformId) { - std::string platform_name_str = platformName(platformId); + int platform_id{0}; + auto platform_list = getPlatforms(); + for (auto& p : platform_list) { + std::string platform_name_str = platformName(p); section - .add("Platform " + toString(platformId), platform_name_str) + .add("Platform " + toString(platform_id), platform_name_str) .addDivider(); - int deviceCount = getDeviceCountInPlatform(platformId); - for (int deviceId = 0; deviceId < deviceCount; ++deviceId) { - std::string device_name_str = deviceName(platformId, deviceId); - info::device_type type = deviceType(platformId, deviceId); + int device_id{0}; + auto device_list = getDevicesInPlatform(p); + for (auto& d : device_list) { + std::string device_name_str = deviceName(d); + cl_device_type device_type = deviceType(d); std::string device_type_str; - switch (type) { - case info::device_type::cpu: + switch (device_type) { + case CL_DEVICE_TYPE_CPU: device_type_str = "cpu"; break; - case info::device_type::gpu: + case CL_DEVICE_TYPE_GPU: device_type_str = "gpu"; break; - case info::device_type::accelerator: + case CL_DEVICE_TYPE_ACCELERATOR: device_type_str = "accelerator"; break; - case info::device_type::all: - device_type_str = "all!?"; + case CL_DEVICE_TYPE_ALL: + device_type_str = "all"; + break; + default: + device_type_str = "???"; break; } - int compute_cores = deviceCoreCount(platformId, deviceId); - udim_t global_memory_B = deviceGlobalMemSize(platformId, deviceId); + int compute_cores = deviceCoreCount(d); + udim_t global_memory_B = deviceGlobalMemSize(d); std::string global_memory_str = stringifyBytes(global_memory_B); section - .add("Device " + toString(deviceId), device_name_str) + .add("Device " + toString(device_id), device_name_str) .add("Device Type", device_type_str) .add("Compute Cores", toString(compute_cores)) .add("Global Memory", global_memory_str) .addDivider(); + + ++device_id; } + ++platform_id; } // Remove last divider section.groups.pop_back(); @@ -64,18 +72,41 @@ namespace occa { return section; } - modeDevice_t* openclMode::newDevice(const occa::json &props) { - return new device(setModeProp(props)); + modeDevice_t* openclMode::newDevice(const occa::json& properties) { + OCCA_ERROR("[OpenCL] device not given a [platform_id] integer", + properties.has("platform_id") && + properties["platform_id"].isNumber()); + int platform_id = properties.get("platform_id"); + + auto platforms{getPlatforms()}; + OCCA_ERROR("Invalid platform number (" + toString(platform_id) + ")", + (static_cast(platform_id) < platforms.size())); + auto& platform = platforms[platform_id]; + + OCCA_ERROR("[OpenCL] device not given a [device_id] integer", + properties.has("device_id") && + properties["device_id"].isNumber()); + int device_id = properties.get("device_id"); + + auto devices{getDevicesInPlatform(platform)}; + OCCA_ERROR("Invalid device number (" + toString(device_id) + ")", + (static_cast(device_id) < devices.size())); + auto& opencl_device = devices[device_id]; + + return new device(setModeProp(properties), opencl_device); } - int openclMode::getDeviceCount(const occa::json &props) { + int openclMode::getDeviceCount(const occa::json& properties) { OCCA_ERROR("[OpenCL] getDeviceCount not given a [platform_id] integer", - props.has("platform_id") && - props["platform_id"].isNumber()); + properties.has("platform_id") && properties["platform_id"].isNumber()); + int platform_id = properties.get("platform_id"); - int platformId = props.get("platform_id"); + auto platforms{getPlatforms()}; + OCCA_ERROR("Invalid platform number (" + toString(platform_id) + ")", + (static_cast(platform_id) < platforms.size())); + auto& platform = platforms[platform_id]; - return getDeviceCountInPlatform(platformId); + return getDeviceCountInPlatform(platform); } openclMode mode; diff --git a/src/occa/internal/modes/opencl/utils.cpp b/src/occa/internal/modes/opencl/utils.cpp index 63aaf3cde..00d312710 100644 --- a/src/occa/internal/modes/opencl/utils.cpp +++ b/src/occa/internal/modes/opencl/utils.cpp @@ -17,19 +17,7 @@ namespace occa { clProgram(NULL), clKernel(NULL) {} - bool isEnabled() { - cl_uint platformCount = 0; - cl_int error = clGetPlatformIDs(0, NULL, &platformCount); - // Only count as enabled if there is a device available - if (!error) { - for (cl_uint platformId = 0; platformId < platformCount; ++platformId) { - if (getDeviceCountInPlatform(platformId)) { - return true; - } - } - } - return false; - } + bool isEnabled() {return (0 < getDeviceCount());} int getPlatformCount() { cl_uint platformCount = 0; @@ -40,21 +28,29 @@ namespace occa { return platformCount; } - cl_platform_id platformID(int pID) { - cl_platform_id *platforms = new cl_platform_id[pID + 1]; - + std::vector getPlatforms(cl_device_type device_type) { + int platform_count = getPlatformCount(); + std::vector all_platforms(platform_count); + OCCA_OPENCL_ERROR("OpenCL: Get Platform ID", - clGetPlatformIDs(pID + 1, platforms, NULL)); - - cl_platform_id ret = platforms[pID]; - - delete [] platforms; + clGetPlatformIDs(platform_count, all_platforms.data(), NULL)); + + std::vector platforms; + for (auto& p : all_platforms) { + if (0 < getDeviceCountInPlatform(p, device_type)) platforms.push_back(p); + } + return platforms; + } - return ret; + cl_platform_id getPlatformFromDevice(cl_device_id device_id) { + cl_platform_id platform_id; + OCCA_OPENCL_ERROR("OpenCL: Get Platform From Device", + clGetDeviceInfo(device_id,CL_DEVICE_PLATFORM,sizeof(cl_platform_id),&platform_id,NULL)); + return platform_id; } std::string platformStrInfo(cl_platform_id clPID, - cl_platform_info clInfo) { + cl_platform_info clInfo) { size_t bytes = 0; OCCA_OPENCL_ERROR("OpenCL: Getting Platform String Info", @@ -107,76 +103,46 @@ namespace occa { return ret.substr(firstNS, (lastNS - firstNS + 1)); } - std::string platformName(int pID) { - cl_platform_id clPID = platformID(pID); - return platformStrInfo(clPID, CL_PLATFORM_NAME); + std::string platformName(cl_platform_id platform_id) { + return platformStrInfo(platform_id, CL_PLATFORM_NAME); } - std::string platformVendor(int pID) { - cl_platform_id clPID = platformID(pID); - return platformStrInfo(clPID, CL_PLATFORM_VENDOR); + std::string platformVendor(cl_platform_id platform_id) { + return platformStrInfo(platform_id, CL_PLATFORM_VENDOR); } - std::string platformVersion(int pID) { - cl_platform_id clPID = platformID(pID); - return platformStrInfo(clPID, CL_PLATFORM_VERSION); + std::string platformVersion(cl_platform_id platform_id) { + return platformStrInfo(platform_id, CL_PLATFORM_VERSION); } - cl_device_type deviceType(info::device_type type) { - cl_device_type dtype = CL_DEVICE_TYPE_DEFAULT; - switch (type) { - case info::device_type::cpu: - dtype = CL_DEVICE_TYPE_CPU; - break; - case info::device_type::gpu: - dtype = CL_DEVICE_TYPE_GPU; - break; - case info::device_type::accelerator: - dtype = CL_DEVICE_TYPE_ACCELERATOR; - break; - case info::device_type::all: - dtype = CL_DEVICE_TYPE_ALL; - break; + int getDeviceCount(cl_device_type device_type) { + auto platforms{getPlatforms()}; + int device_count{0}; + for (auto& p : platforms) { + device_count += getDeviceCountInPlatform(p, device_type); } - return dtype; - } - - int getDeviceCount(info::device_type type) { - int pCount = opencl::getPlatformCount(); - int ret = 0; - - for (int p = 0; p < pCount; ++p) - ret += getDeviceCountInPlatform(p, type); - - return ret; + return device_count; } - int getDeviceCountInPlatform(int pID, info::device_type type) { - cl_platform_id clPID = platformID(pID); + int getDeviceCountInPlatform(cl_platform_id platform_id, cl_device_type device_type) { cl_uint deviceCount = 0; - clGetDeviceIDs(clPID, deviceType(type), - 0, NULL, &deviceCount); + + cl_int err = clGetDeviceIDs(platform_id, device_type, 0, NULL, &deviceCount); + if (CL_DEVICE_NOT_FOUND != err) OCCA_OPENCL_ERROR("OpenCL: getDeviceCountIntPlatform", err); return deviceCount; } - cl_device_id deviceID(int pID, int dID, info::device_type type) { - cl_device_id *devices = new cl_device_id[dID + 1]; - - cl_platform_id clPID = platformID(pID); - - OCCA_OPENCL_ERROR("OpenCL: Get Device ID Count", - clGetDeviceIDs(clPID, - deviceType(type), - dID + 1, devices, NULL)); - - cl_device_id ret = devices[dID]; - - delete [] devices; - - return ret; + std::vector getDevicesInPlatform(cl_platform_id platform_id, cl_device_type device_type) { + int device_count = getDeviceCountInPlatform(platform_id, device_type); + std::vector devices(device_count); + if (0 < device_count) { + OCCA_OPENCL_ERROR("OpenCL: getDevicesInPlatform", + clGetDeviceIDs(platform_id, device_type, device_count, devices.data(), NULL)); + } + return devices; } - + std::string deviceStrInfo(cl_device_id clDID, cl_device_info clInfo) { size_t bytes = 0; @@ -231,67 +197,49 @@ namespace occa { return ret.substr(firstNS, (lastNS - firstNS + 1)); } - std::string deviceName(int pID, int dID) { - cl_device_id clDID = deviceID(pID, dID); - return deviceStrInfo(clDID, CL_DEVICE_NAME); + std::string deviceName(cl_device_id device_id) { + return deviceStrInfo(device_id, CL_DEVICE_NAME); } - info::device_type deviceType(int pID, int dID) { - cl_device_id clDID = deviceID(pID, dID); - cl_device_type clDeviceType = CL_DEVICE_TYPE_ALL; + cl_device_type deviceType(cl_device_id device_id) { + cl_device_type clDeviceType; - OCCA_OPENCL_ERROR( - "OpenCL: Get Device Type", - clGetDeviceInfo(clDID,CL_DEVICE_TYPE,sizeof(clDeviceType), &clDeviceType, NULL) + OCCA_OPENCL_ERROR("OpenCL: Get Device Type", + clGetDeviceInfo(device_id,CL_DEVICE_TYPE,sizeof(clDeviceType), &clDeviceType, NULL) ); - if (clDeviceType & CL_DEVICE_TYPE_CPU) - return info::device_type::cpu; - if (clDeviceType & CL_DEVICE_TYPE_GPU) - return info::device_type::gpu; - if (clDeviceType & CL_DEVICE_TYPE_ACCELERATOR) - return info::device_type::accelerator; - - return info::device_type::all; + return clDeviceType; } - std::string deviceVendor(int pID, int dID) { - cl_device_id clDID = deviceID(pID, dID); - return deviceStrInfo(clDID, CL_DEVICE_VENDOR); + std::string deviceVendor(cl_device_id device_id) { + return deviceStrInfo(device_id, CL_DEVICE_VENDOR); } - std::string deviceVersion(int pID, int dID) { - cl_device_id clDID = deviceID(pID, dID); - return deviceStrInfo(clDID, CL_DEVICE_VERSION); + std::string deviceVersion(cl_device_id device_id) { + return deviceStrInfo(device_id, CL_DEVICE_VERSION); } - int deviceCoreCount(int pID, int dID) { - cl_device_id clDID = deviceID(pID, dID); + int deviceCoreCount(cl_device_id device_id) { cl_uint ret = 0; OCCA_OPENCL_ERROR("OpenCL: Get Device Core Count", - clGetDeviceInfo(clDID, - CL_DEVICE_MAX_COMPUTE_UNITS, - sizeof(ret), &ret, NULL)); - + clGetDeviceInfo(device_id,CL_DEVICE_MAX_COMPUTE_UNITS,sizeof(ret), &ret, NULL) + ); return ret; } - udim_t deviceGlobalMemSize(cl_device_id dID) { + udim_t deviceGlobalMemSize(cl_device_id device_id) { cl_ulong ret = 0; - OCCA_OPENCL_ERROR("OpenCL: Get Device Available Memory", - clGetDeviceInfo(dID, - CL_DEVICE_GLOBAL_MEM_SIZE, - sizeof(ret), &ret, NULL)); - + clGetDeviceInfo(device_id, CL_DEVICE_GLOBAL_MEM_SIZE, sizeof(ret), &ret, NULL)); return ret; } - udim_t deviceGlobalMemSize(int pID, int dID) { - cl_device_id clDID = deviceID(pID, dID); - - return deviceGlobalMemSize(clDID); + cl_context createContextFromDevice(cl_device_id device_id) { + cl_int error; + cl_context context = clCreateContext(NULL, 1, &device_id, NULL, NULL, &error); + OCCA_OPENCL_ERROR("OpenCL: Create ContextFromDevice", error); + return context; } void buildProgramFromSource(info_t &info, @@ -458,41 +406,18 @@ namespace occa { return true; } - cl_context getCLContext(occa::device device) { - return ((opencl::device*) device.getModeDevice())->clContext; - } - - cl_mem getCLMemory(occa::memory memory) { - return ((opencl::memory*) memory.getModeMemory())->clMem; - } - - cl_kernel getCLKernel(occa::kernel kernel) { - return ((opencl::kernel*) kernel.getModeKernel())->clKernel; - } - - occa::device wrapDevice(cl_device_id clDevice, - cl_context context, + occa::device wrapDevice(cl_device_id device_id, const occa::json &props) { - occa::json allProps; - allProps["mode"] = "OpenCL"; - allProps["platform_id"] = -1; - allProps["device_id"] = -1; - allProps["wrapped"] = true; + allProps["mode"] = "OpenCL"; + allProps["wrapped"] = true; allProps += props; - opencl::device &dev = *(new opencl::device(allProps)); - dev.dontUseRefs(); - - dev.platformID = (int) allProps["platform_id"]; - dev.deviceID = (int) allProps["device_id"]; - - dev.clDevice = clDevice; - dev.clContext = context; - - dev.currentStream = dev.createStream(allProps["stream"]); + auto* wrapper{new opencl::device(allProps, device_id)}; + wrapper->dontUseRefs(); - return occa::device(&dev); + wrapper->currentStream = wrapper->createStream(allProps["stream"]); + return occa::device(wrapper); } void warn(cl_int errorCode, diff --git a/src/occa/internal/modes/opencl/utils.hpp b/src/occa/internal/modes/opencl/utils.hpp index 1f8217383..eb435872f 100644 --- a/src/occa/internal/modes/opencl/utils.hpp +++ b/src/occa/internal/modes/opencl/utils.hpp @@ -20,39 +20,36 @@ namespace occa { info_t(); }; - namespace info { - enum class device_type { - cpu, gpu, accelerator, all = cpu | gpu | accelerator - }; - } + constexpr cl_device_type default_device_type = (CL_DEVICE_TYPE_CPU | CL_DEVICE_TYPE_GPU); bool isEnabled(); - int getPlatformCount(); - cl_platform_id platformID(int pID); + std::vector getPlatforms(cl_device_type device_type = default_device_type); + cl_platform_id getPlatformFromDevice(cl_device_id device_id); std::string platformStrInfo(cl_platform_id clPID, cl_platform_info clInfo); - std::string platformName(int pID); - std::string platformVendor(int pID); - std::string platformVersion(int pID); + + std::string platformName(cl_platform_id platform_id); + std::string platformVendor(cl_platform_id platform_id); + std::string platformVersion(cl_platform_id platform_id); - int getDeviceCount(info::device_type deviceType = info::device_type::all); - int getDeviceCountInPlatform(int pID, info::device_type type = info::device_type::all); + int getDeviceCount(cl_device_type device_type = default_device_type); + int getDeviceCountInPlatform(cl_platform_id, cl_device_type device_type = default_device_type); - cl_device_id deviceID(int pID, int dID, info::device_type deviceType = info::device_type::all); + std::vector getDevicesInPlatform(cl_platform_id platform_id, cl_device_type device_type = default_device_type); std::string deviceStrInfo(cl_device_id clDID, cl_device_info clInfo); - std::string deviceName(int pID, int dID); - std::string deviceVendor(int pID, int dID); - std::string deviceVersion(int pID, int dID); + std::string deviceName(cl_device_id device_id); + std::string deviceVendor(cl_device_id device_id); + std::string deviceVersion(cl_device_id device_id); - cl_device_type deviceType(info::device_type type); - info::device_type deviceType(int pID, int dID); + cl_device_type deviceType(cl_device_id device_type); - int deviceCoreCount(int pID, int dID); + int deviceCoreCount(cl_device_id device_id); udim_t deviceGlobalMemSize(cl_device_id dID); - udim_t deviceGlobalMemSize(int pID, int dID); + + cl_context createContextFromDevice(cl_device_id device_id); void buildProgramFromSource(info_t &info, const std::string &source, @@ -76,12 +73,6 @@ namespace occa { bool saveProgramBinary(info_t &info, const std::string &binaryFile); - cl_context getCLContext(occa::device device); - - cl_mem getCLMemory(occa::memory memory); - - cl_kernel getCLKernel(occa::kernel kernel); - occa::device wrapDevice(cl_device_id clDevice, cl_context context, const occa::json &props = occa::json()); diff --git a/tests/src/math/fpMath.cpp b/tests/src/math/fpMath.cpp index 91a8dc99f..3dd64f0e1 100644 --- a/tests/src/math/fpMath.cpp +++ b/tests/src/math/fpMath.cpp @@ -102,15 +102,18 @@ void testTernaryFunctions(const occa::device& d) { } int main() { - std::vector devices = { - occa::device({{"mode", "Serial"}}), - occa::device({{"mode", "OpenMP"}}), - occa::device({{"mode", "CUDA"},{"device_id", 0}}), - occa::device({{"mode", "HIP"},{"device_id", 0}}), - occa::device({{"mode", "OpenCL"},{"platform_id",0},{"device_id", 0}}), - occa::device({{"mode", "dpcpp"},{"platform_id",0},{"device_id", 0}}) - }; - + std::vector devices; + if (occa::modeIsEnabled("Serial")) + devices.push_back(occa::device({{"mode", "Serial"}})); + if (occa::modeIsEnabled("OpenMP")) + devices.push_back(occa::device({{"mode", "OpenMP"}})); + if (occa::modeIsEnabled("CUDA")) + devices.push_back(occa::device({{"mode", "CUDA"},{"device_id", 0}})); + if (occa::modeIsEnabled("HIP")) + devices.push_back(occa::device({{"mode", "HIP"},{"device_id", 0}})); + if (occa::modeIsEnabled("dpcpp")) + devices.push_back(occa::device({{"mode", "dpcpp"},{"platform_id",0},{"device_id", 0}})); + for(auto &d : devices) { std::cout << "Testing mode: " << d.mode() << "\n"; testUnaryFunctions(d); diff --git a/tests/src/math/intMath.cpp b/tests/src/math/intMath.cpp index 520ae5d14..140890f99 100644 --- a/tests/src/math/intMath.cpp +++ b/tests/src/math/intMath.cpp @@ -61,14 +61,17 @@ void testBinaryFunctions(const occa::device& d) { } int main() { - std::vector devices = { - occa::device({{"mode", "Serial"}}), - occa::device({{"mode", "OpenMP"}}), - occa::device({{"mode", "CUDA"},{"device_id", 0}}), - occa::device({{"mode", "HIP"},{"device_id", 0}}), - occa::device({{"mode", "OpenCL"},{"platform_id",0},{"device_id", 0}}), - occa::device({{"mode", "dpcpp"},{"platform_id",0},{"device_id", 0}}) - }; + std::vector devices; + if (occa::modeIsEnabled("Serial")) + devices.push_back(occa::device({{"mode", "Serial"}})); + if (occa::modeIsEnabled("OpenMP")) + devices.push_back(occa::device({{"mode", "OpenMP"}})); + if (occa::modeIsEnabled("CUDA")) + devices.push_back(occa::device({{"mode", "CUDA"},{"device_id", 0}})); + if (occa::modeIsEnabled("HIP")) + devices.push_back(occa::device({{"mode", "HIP"},{"device_id", 0}})); + if (occa::modeIsEnabled("dpcpp")) + devices.push_back(occa::device({{"mode", "dpcpp"},{"platform_id",0},{"device_id", 0}})); for(auto &d : devices) { std::cout << "Testing mode: " << d.mode() << "\n";