Skip to content

Commit f661696

Browse files
committed
Fix for empty device list
1 parent ac507f3 commit f661696

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

index.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1186,7 +1186,7 @@ declare module "opencl-raub" {
11861186
*/
11871187
const getDeviceIDs: (
11881188
platform: TClPlatform,
1189-
device_type: number,
1189+
device_type?: number, // default is `cl.DEVICE_TYPE_ALL`
11901190
) => TDevice[];
11911191

11921192
/**

src/cpp/device.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ JS_METHOD(getDeviceIDs) { NAPI_ENV;
1717
cl_uint n = 0;
1818
CHECK_ERR(clGetDeviceIDs(platform, type, 0, nullptr, &n));
1919

20+
Napi::Array deviceArray = Napi::Array::New(env);
21+
if (!n) {
22+
RET_VALUE(deviceArray);
23+
}
24+
2025
std::unique_ptr<cl_device_id[]> devices(new cl_device_id[n]);
2126
CHECK_ERR(clGetDeviceIDs(
2227
platform,
@@ -26,7 +31,6 @@ JS_METHOD(getDeviceIDs) { NAPI_ENV;
2631
nullptr
2732
));
2833

29-
Napi::Array deviceArray = Napi::Array::New(env);
3034
for (uint32_t i = 0; i < n; i++) {
3135
// This is a noop for root-level devices but properly retains sub-devices.
3236
CHECK_ERR(clRetainDevice(devices[i]));

0 commit comments

Comments
 (0)