Skip to content

Commit 7a0909f

Browse files
committed
Supported an OPENCL_VISIBLE_DEVICES environment variable inspired from CUDA_VISIBLE_DEVICES.
OPENCL_VISIBLE_DEVICES=descriptor_list descriptor_list -> descriptor | descriptor::descriptor_list descriptor -> driver,platform | driver,platform,type | driver,platform,type,device_list device_list -> device_id | device_id,device_list driver: client driver (foo.icd or foo.so) platform: platform ID type: gpu, cpu, accelerator, custom, or any device_id: device ID in the platform This patch is to land KhronosGroup#45 again. Most of the code is from pull request 45. e.g., OPENCL_VISIBLE_DEVICES=foo.icd,0,gpu,0,1::bar.icd,1,cpu,0 only shows - GPU 0, 1 in the first platform of foo.icd - CPU 0 in the second platform of bar.icd
1 parent 4e65bd5 commit 7a0909f

8 files changed

Lines changed: 614 additions & 14 deletions

File tree

CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ configure_file(${CMAKE_CURRENT_SOURCE_DIR}/loader/icd_cmake_config.h.in
5050
set (OPENCL_ICD_LOADER_SOURCES
5151
loader/icd.c
5252
loader/icd.h
53+
loader/icd_device_visible.h
54+
loader/icd_device_visible.c
5355
loader/icd_dispatch.c
5456
loader/icd_dispatch.h
5557
loader/icd_dispatch_generated.c

loader/icd.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2016-2020 The Khronos Group Inc.
2+
* Copyright (c) 2016-2021 The Khronos Group Inc.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -19,6 +19,7 @@
1919
#include "icd.h"
2020
#include "icd_dispatch.h"
2121
#include "icd_envvars.h"
22+
#include "icd_device_visible.h"
2223
#if defined(CL_ENABLE_LAYERS)
2324
#include <CL/cl_layer.h>
2425
#endif // defined(CL_ENABLE_LAYERS)
@@ -33,6 +34,7 @@ struct KHRLayer *khrFirstLayer = NULL;
3334
// entrypoint to initialize the ICD and add all vendors
3435
void khrIcdInitialize(void)
3536
{
37+
khrIcdOsGetOpenCLVisibleDevicesOnce();
3638
// enumerate vendors present on the system
3739
khrIcdOsVendorsEnumerateOnce();
3840
}
@@ -122,6 +124,12 @@ void khrIcdVendorAdd(const char *libraryName)
122124
{
123125
continue;
124126
}
127+
128+
if (!khrIcdCheckPlatformVisible(libraryName, i))
129+
{
130+
continue;
131+
}
132+
125133
result = platforms[i]->dispatch->clGetPlatformInfo(
126134
platforms[i],
127135
CL_PLATFORM_ICD_SUFFIX_KHR,
@@ -179,8 +187,9 @@ void khrIcdVendorAdd(const char *libraryName)
179187
*prevNextPointer = vendor;
180188
}
181189

182-
KHR_ICD_TRACE("successfully added vendor %s with suffix %s\n", libraryName, suffix);
190+
khrIcdVisibilitySetPlatform(libraryName, i, platforms[i]);
183191

192+
KHR_ICD_TRACE("successfully added vendor %s with suffix %s\n", libraryName, suffix);
184193
}
185194

186195
Done:

0 commit comments

Comments
 (0)