Skip to content

Commit 561f236

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 561f236

10 files changed

Lines changed: 715 additions & 92 deletions

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: 10 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)
@@ -122,6 +123,12 @@ void khrIcdVendorAdd(const char *libraryName)
122123
{
123124
continue;
124125
}
126+
127+
if (!khrIcdCheckPlatformVisible(libraryName, i))
128+
{
129+
continue;
130+
}
131+
125132
result = platforms[i]->dispatch->clGetPlatformInfo(
126133
platforms[i],
127134
CL_PLATFORM_ICD_SUFFIX_KHR,
@@ -179,8 +186,9 @@ void khrIcdVendorAdd(const char *libraryName)
179186
*prevNextPointer = vendor;
180187
}
181188

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

191+
KHR_ICD_TRACE("successfully added vendor %s with suffix %s\n", libraryName, suffix);
184192
}
185193

186194
Done:

0 commit comments

Comments
 (0)