Skip to content

Commit 2a29e4a

Browse files
committed
gh-235: add pocl cpu support
1 parent 46b8a01 commit 2a29e4a

4 files changed

Lines changed: 85 additions & 34 deletions

File tree

src/opencl/cl_accelerator.cpp

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -105,47 +105,53 @@ namespace spla {
105105
m_max_local_mem = m_device.getInfo<CL_DEVICE_LOCAL_MEM_SIZE>();
106106
m_addr_align = m_device.getInfo<CL_DEVICE_MEM_BASE_ADDR_ALIGN>() / 8;// from bits to bytes
107107

108+
m_is_pocl = false;
108109
m_is_nvidia = false;
109110
m_is_amd = false;
110111
m_is_intel = false;
111112
m_is_img = false;
112113

113-
if (m_vendor_name.find("Intel") != std::string::npos ||
114-
m_vendor_name.find("intel") != std::string::npos ||
115-
m_vendor_name.find("INTEL") != std::string::npos ||
116-
m_vendor_id == 32902) {
114+
auto dev_type = m_device.getInfo<CL_DEVICE_TYPE>();
115+
116+
if (m_vendor_id == 0x10006 &&
117+
dev_type == CL_DEVICE_TYPE_CPU) {
118+
m_vendor_code = VENDOR_CODE_POCL_CPU;
119+
m_default_wgs = 64;
120+
m_wave_size = 1;
121+
m_is_pocl = true;
122+
} else if (m_vendor_name.find("Intel") != std::string::npos ||
123+
m_vendor_name.find("intel") != std::string::npos ||
124+
m_vendor_name.find("INTEL") != std::string::npos ||
125+
m_vendor_id == 32902) {
117126
m_vendor_code = VENDOR_CODE_INTEL;
118127
m_default_wgs = 64;
119128
m_wave_size = 8;
120129
m_is_intel = true;
121-
}
122-
if (m_vendor_name.find("Nvidia") != std::string::npos ||
123-
m_vendor_name.find("nvidia") != std::string::npos ||
124-
m_vendor_name.find("NVIDIA") != std::string::npos ||
125-
m_vendor_id == 4318) {
130+
} else if (m_vendor_name.find("Nvidia") != std::string::npos ||
131+
m_vendor_name.find("nvidia") != std::string::npos ||
132+
m_vendor_name.find("NVIDIA") != std::string::npos ||
133+
m_vendor_id == 4318) {
126134
m_vendor_code = VENDOR_CODE_NVIDIA;
127135
m_default_wgs = 64;
128136
m_wave_size = 32;
129137
m_is_nvidia = true;
130-
}
131-
if (m_vendor_name.find("Amd") != std::string::npos ||
132-
m_vendor_name.find("amd") != std::string::npos ||
133-
m_vendor_name.find("AMD") != std::string::npos ||
134-
m_vendor_name.find("Advanced Micro Devices") != std::string::npos ||
135-
m_vendor_name.find("advanced micro devices") != std::string::npos ||
136-
m_vendor_name.find("ADVANCED MICRO DEVICES") != std::string::npos) {
138+
} else if (m_vendor_name.find("Amd") != std::string::npos ||
139+
m_vendor_name.find("amd") != std::string::npos ||
140+
m_vendor_name.find("AMD") != std::string::npos ||
141+
m_vendor_name.find("Advanced Micro Devices") != std::string::npos ||
142+
m_vendor_name.find("advanced micro devices") != std::string::npos ||
143+
m_vendor_name.find("ADVANCED MICRO DEVICES") != std::string::npos) {
137144
m_vendor_code = VENDOR_CODE_AMD;
138145
m_default_wgs = 64;
139146
m_wave_size = 64;
140147
m_is_amd = true;
141148

142149
// Likely, it is an integrated amd device
143150
if (m_max_wgs <= 256 || m_max_cu == 1) m_wave_size = 16;
144-
}
145-
if (m_vendor_name.find("Imagination Technologies") != std::string::npos ||
146-
m_vendor_name.find("IMG") != std::string::npos ||
147-
m_vendor_name.find("img") != std::string::npos ||
148-
m_vendor_id == 0x1010) {
151+
} else if (m_vendor_name.find("Imagination Technologies") != std::string::npos ||
152+
m_vendor_name.find("IMG") != std::string::npos ||
153+
m_vendor_name.find("img") != std::string::npos ||
154+
m_vendor_id == 0x1010) {
149155
m_vendor_code = VENDOR_CODE_IMG;
150156
m_default_wgs = 32;
151157
m_wave_size = 32;

src/opencl/cl_accelerator.hpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,11 @@
4646
#define CL_HPP_TARGET_OPENCL_VERSION 120
4747
#include <CL/opencl.hpp>
4848

49-
#define VENDOR_CODE_NVIDIA "nvidia"
50-
#define VENDOR_CODE_INTEL "intel"
51-
#define VENDOR_CODE_AMD "amd"
52-
#define VENDOR_CODE_IMG "img"
49+
#define VENDOR_CODE_NVIDIA "nvidia"
50+
#define VENDOR_CODE_INTEL "intel"
51+
#define VENDOR_CODE_AMD "amd"
52+
#define VENDOR_CODE_IMG "img"
53+
#define VENDOR_CODE_POCL_CPU "pocl_cpu"
5354

5455
namespace spla {
5556

@@ -122,6 +123,7 @@ namespace spla {
122123
uint m_default_wgs = 64;
123124
uint m_wave_size = 32;
124125
uint m_num_of_mem_banks = 32;
126+
bool m_is_pocl = false;
125127
bool m_is_nvidia = false;
126128
bool m_is_amd = false;
127129
bool m_is_intel = false;

tests/test_opencl.cpp

Lines changed: 38 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
/**********************************************************************************/
2727

2828
#include "test_common.hpp"
29+
#include <gtest/gtest.h>
2930

3031
#define CL_HPP_MINIMUM_OPENCL_VERSION 120
3132
#define CL_HPP_TARGET_OPENCL_VERSION 120
@@ -37,13 +38,19 @@
3738
#include <thread>
3839
#include <vector>
3940

40-
TEST(opencl, basic_gpu) {
41+
TEST(opencl, basic) {
4142
std::vector<cl::Platform> platforms;
4243
cl::Platform::get(&platforms);
44+
if (platforms.empty()) {
45+
GTEST_SKIP() << "No platforms found";
46+
}
4347
cl::Platform platform = platforms.front();
4448

4549
std::vector<cl::Device> devices;
46-
platform.getDevices(CL_DEVICE_TYPE_GPU, &devices);
50+
platform.getDevices(CL_DEVICE_TYPE_ALL, &devices);
51+
if (devices.empty()) {
52+
GTEST_SKIP() << "No devices found";
53+
}
4754
cl::Device device = devices.front();
4855

4956
cl::Context context(device);
@@ -87,10 +94,16 @@ TEST(opencl, basic_gpu) {
8794
TEST(opencl, bitonic_sort_local) {
8895
std::vector<cl::Platform> platforms;
8996
cl::Platform::get(&platforms);
97+
if (platforms.empty()) {
98+
GTEST_SKIP() << "No platforms found";
99+
}
90100
cl::Platform platform = platforms.front();
91101

92102
std::vector<cl::Device> devices;
93-
platform.getDevices(CL_DEVICE_TYPE_GPU, &devices);
103+
platform.getDevices(CL_DEVICE_TYPE_ALL, &devices);
104+
if (devices.empty()) {
105+
GTEST_SKIP() << "No devices found";
106+
}
94107
cl::Device device = devices.front();
95108

96109
cl::Context context(device);
@@ -137,10 +150,16 @@ TEST(opencl, bitonic_sort_local) {
137150
TEST(opencl, bitonic_sort_global) {
138151
std::vector<cl::Platform> platforms;
139152
cl::Platform::get(&platforms);
153+
if (platforms.empty()) {
154+
GTEST_SKIP() << "No platforms found";
155+
}
140156
cl::Platform platform = platforms.front();
141157

142158
std::vector<cl::Device> devices;
143-
platform.getDevices(CL_DEVICE_TYPE_GPU, &devices);
159+
platform.getDevices(CL_DEVICE_TYPE_ALL, &devices);
160+
if (devices.empty()) {
161+
GTEST_SKIP() << "No devices found";
162+
}
144163
cl::Device device = devices.front();
145164

146165
cl::Context context(device);
@@ -188,10 +207,16 @@ TEST(opencl, bitonic_sort_global) {
188207
TEST(opencl, custom_value) {
189208
std::vector<cl::Platform> platforms;
190209
cl::Platform::get(&platforms);
210+
if (platforms.empty()) {
211+
GTEST_SKIP() << "No platforms found";
212+
}
191213
cl::Platform platform = platforms.front();
192214

193215
std::vector<cl::Device> devices;
194-
platform.getDevices(CL_DEVICE_TYPE_GPU, &devices);
216+
platform.getDevices(CL_DEVICE_TYPE_ALL, &devices);
217+
if (devices.empty()) {
218+
GTEST_SKIP() << "No devices found";
219+
}
195220
cl::Device device = devices.front();
196221

197222
cl::Context context(device);
@@ -236,10 +261,16 @@ TEST(opencl, custom_value) {
236261
TEST(opencl, reduce_by_key_small) {
237262
std::vector<cl::Platform> platforms;
238263
cl::Platform::get(&platforms);
264+
if (platforms.empty()) {
265+
GTEST_SKIP() << "No platforms found";
266+
}
239267
cl::Platform platform = platforms.front();
240268

241269
std::vector<cl::Device> devices;
242-
platform.getDevices(CL_DEVICE_TYPE_GPU, &devices);
270+
platform.getDevices(CL_DEVICE_TYPE_ALL, &devices);
271+
if (devices.empty()) {
272+
GTEST_SKIP() << "No devices found";
273+
}
243274
cl::Device device = devices.front();
244275

245276
cl::Context context(device);
@@ -367,4 +398,4 @@ TEST(opencl, reduce_by_key_small) {
367398
}
368399
}
369400

370-
SPLA_GTEST_MAIN
401+
SPLA_GTEST_MAIN

tests/test_opencl_merge.cpp

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,9 @@ void cl_merge_v2(const cl::CommandQueue& queue,
412412
TEST(opencl_merge, merge_path_v1) {
413413
std::vector<cl::Platform> platforms;
414414
cl::Platform::get(&platforms);
415+
if (platforms.empty()) {
416+
GTEST_SKIP() << "No platforms found";
417+
}
415418
cl::Platform platform = platforms.back();
416419

417420
std::cout << "Platforms: " << std::endl;
@@ -422,7 +425,10 @@ TEST(opencl_merge, merge_path_v1) {
422425
std::cout << "Current platform: " << platform.getInfo<CL_PLATFORM_NAME>() << std::endl;
423426

424427
std::vector<cl::Device> devices;
425-
platform.getDevices(CL_DEVICE_TYPE_GPU, &devices);
428+
platform.getDevices(CL_DEVICE_TYPE_ALL, &devices);
429+
if (devices.empty()) {
430+
GTEST_SKIP() << "No devices found";
431+
}
426432
cl::Device device = devices[0];
427433

428434
std::cout << "Devices: " << std::endl;
@@ -502,6 +508,9 @@ TEST(opencl_merge, merge_path_v1) {
502508
TEST(opencl_merge, merge_path_v2) {
503509
std::vector<cl::Platform> platforms;
504510
cl::Platform::get(&platforms);
511+
if (platforms.empty()) {
512+
GTEST_SKIP() << "No platforms found";
513+
}
505514
cl::Platform platform = platforms.back();
506515

507516
std::cout << "Platforms: " << std::endl;
@@ -512,7 +521,10 @@ TEST(opencl_merge, merge_path_v2) {
512521
std::cout << "Current platform: " << platform.getInfo<CL_PLATFORM_NAME>() << std::endl;
513522

514523
std::vector<cl::Device> devices;
515-
platform.getDevices(CL_DEVICE_TYPE_GPU, &devices);
524+
platform.getDevices(CL_DEVICE_TYPE_ALL, &devices);
525+
if (devices.empty()) {
526+
GTEST_SKIP() << "No devices found";
527+
}
516528
cl::Device device = devices[0];
517529

518530
std::cout << "Devices: " << std::endl;

0 commit comments

Comments
 (0)