Skip to content

Commit 21ca091

Browse files
committed
Remove the maximum number of platforms limitation.
Signed-off-by: Dmitri Mokhov <[email protected]>
1 parent d83edd4 commit 21ca091

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

opencl-aot/source/utils.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -178,19 +178,23 @@ getOpenCLPlatform(DeviceType Type) {
178178
cl_int CLErr(CL_SUCCESS);
179179
std::string PlatformName;
180180

181-
const cl_uint MaxPlatformsCount = 10;
182-
std::vector<cl_platform_id> Platforms(MaxPlatformsCount);
183-
184181
cl_uint PlatformsCount = 0;
185-
CLErr =
186-
clGetPlatformIDs(MaxPlatformsCount, Platforms.data(), &PlatformsCount);
182+
CLErr = clGetPlatformIDs(0, nullptr, &PlatformsCount);
183+
if (clFailed(CLErr)) {
184+
return std::make_tuple(
185+
nullptr, "",
186+
formatCLError("Failed to retrieve OpenCL platform count", CLErr),
187+
CLErr);
188+
}
189+
190+
std::vector<cl_platform_id> Platforms{PlatformsCount};
191+
CLErr = clGetPlatformIDs(PlatformsCount, Platforms.data(), nullptr);
187192
if (clFailed(CLErr)) {
188193
return std::make_tuple(
189194
nullptr, "",
190195
formatCLError("Failed to retrieve OpenCL platform IDs", CLErr), CLErr);
191196
}
192197

193-
Platforms.resize(PlatformsCount);
194198
for (const auto &Platform : Platforms) {
195199
size_t PlatformNameLength = 0;
196200
CLErr = clGetPlatformInfo(Platform, CL_PLATFORM_NAME, 0, nullptr,

0 commit comments

Comments
 (0)