Skip to content

Commit 51595fc

Browse files
jbrodmanbader
authored andcommitted
Formatting changes/follow patterns.
Signed-off-by: James Brodman <james.brodman@intel.com>
1 parent 055c607 commit 51595fc

File tree

3 files changed

+43
-65
lines changed

3 files changed

+43
-65
lines changed

sycl/test/usm/clext.cpp

Lines changed: 4 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -9,42 +9,14 @@
99
//===----------------------------------------------------------------------===//
1010

1111
#include <CL/sycl/detail/clusm.hpp>
12+
13+
#include "findplatforms.hpp"
14+
1215
#include <cstring>
1316
#include <iostream>
1417

1518
using namespace cl::sycl::detail::usm;
1619

17-
static int SIZE = 6;
18-
19-
bool findPlatformAndDevice(cl_device_type deviceType,
20-
cl_platform_id& platformOut,
21-
cl_device_id& deviceOut) {
22-
cl_platform_id platforms[SIZE];
23-
cl_uint numPlatforms;
24-
cl_device_id device;
25-
cl_int errorCode;
26-
bool foundDevice = false;
27-
28-
errorCode = clGetPlatformIDs(SIZE, platforms, &numPlatforms);
29-
30-
for (int i = 0; (!foundDevice) && (i < numPlatforms); i++) {
31-
cl_uint numDevices;
32-
errorCode = clGetDeviceIDs(platforms[i],
33-
deviceType,
34-
1,
35-
&device,
36-
&numDevices);
37-
38-
if (numDevices) {
39-
platformOut = platforms[i];
40-
deviceOut = device;
41-
foundDevice = true;
42-
}
43-
}
44-
45-
return foundDevice;
46-
}
47-
4820
int main(int argc, char** argv) {
4921
if (argc != 2) {
5022
std::cerr << "Please specify -cpu or -gpu!" << std::endl;
@@ -72,7 +44,7 @@ int main(int argc, char** argv) {
7244
cl_platform_id platform;
7345
cl_device_id device;
7446

75-
if (!findPlatformAndDevice(deviceType, platform, device)) {
47+
if (!findPlatformAndDevice(deviceType, platform, device, errorCode)) {
7648
return 2;
7749
}
7850

sycl/test/usm/clusm.cpp

Lines changed: 4 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -9,42 +9,14 @@
99
//===----------------------------------------------------------------------===//
1010

1111
#include <CL/sycl/detail/clusm.hpp>
12+
13+
#include "findplatforms.hpp"
14+
1215
#include <cstring>
1316
#include <iostream>
1417

1518
using namespace cl::sycl::detail::usm;
1619

17-
static int SIZE = 6;
18-
19-
bool findPlatformAndDevice(cl_device_type deviceType,
20-
cl_platform_id& platformOut,
21-
cl_device_id& deviceOut) {
22-
cl_platform_id platforms[SIZE];
23-
cl_uint numPlatforms;
24-
cl_device_id device;
25-
cl_int errorCode;
26-
bool foundDevice = false;
27-
28-
errorCode = clGetPlatformIDs(SIZE, platforms, &numPlatforms);
29-
30-
for (int i = 0; (!foundDevice) && (i < numPlatforms); i++) {
31-
cl_uint numDevices;
32-
errorCode = clGetDeviceIDs(platforms[i],
33-
deviceType,
34-
1,
35-
&device,
36-
&numDevices);
37-
38-
if (numDevices) {
39-
platformOut = platforms[i];
40-
deviceOut = device;
41-
foundDevice = true;
42-
}
43-
}
44-
45-
return foundDevice;
46-
}
47-
4820
int main(int argc, char** argv) {
4921
if (argc != 2) {
5022
std::cerr << "Please specify -cpu or -gpu!" << std::endl;
@@ -71,11 +43,10 @@ int main(int argc, char** argv) {
7143
: CL_DEVICE_TYPE_GPU;
7244

7345
cl_int errorCode;
74-
7546
cl_platform_id platform;
7647
cl_device_id device;
7748

78-
if (!findPlatformAndDevice(deviceType, platform, device)) {
49+
if (!findPlatformAndDevice(deviceType, platform, device, errorCode)) {
7950
return 2;
8051
}
8152

sycl/test/usm/findplatforms.hpp

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
//==------------------- findplatforms.hpp ----------------------------------==//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
bool findPlatformAndDevice(cl_device_type deviceType,
9+
cl_platform_id &platformOut, cl_device_id &deviceOut,
10+
cl_int &errorCode) {
11+
cl_uint numPlatforms;
12+
bool foundDevice = false;
13+
14+
errorCode = clGetPlatformIDs(0, nullptr, &numPlatforms);
15+
std::vector<cl_platform_id> platforms(numPlatforms);
16+
errorCode = clGetPlatformIDs(numPlatforms, platforms.data(), nullptr);
17+
18+
for (auto platform : platforms) {
19+
if (!foundDevice) {
20+
cl_uint numDevices = 0;
21+
errorCode =
22+
clGetDeviceIDs(platform, deviceType, 0, nullptr, &numDevices);
23+
std::vector<cl_device_id> devices(numDevices);
24+
errorCode = clGetDeviceIDs(platform, deviceType, numDevices,
25+
devices.data(), nullptr);
26+
if (numDevices) {
27+
platformOut = platform;
28+
deviceOut = devices[0];
29+
foundDevice = true;
30+
}
31+
}
32+
}
33+
34+
return foundDevice;
35+
}

0 commit comments

Comments
 (0)