Skip to content

Commit a348dea

Browse files
committed
Merge branch 'main' into matrixperf-final
2 parents 5fe7e09 + 196d94c commit a348dea

50 files changed

Lines changed: 260 additions & 52 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

include/util.hpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,3 +90,20 @@ static std::string readStringFromFile(
9090

9191
return source;
9292
}
93+
94+
static bool checkPlatformIndex(
95+
const std::vector<cl::Platform>& platforms,
96+
int platformIndex)
97+
{
98+
if (platforms.size() == 0) {
99+
fprintf(stderr, "Error: No OpenCL platforms found.\n");
100+
return false;
101+
}
102+
if (platformIndex >= (int)platforms.size()) {
103+
fprintf(stderr, "Error: Invalid platform index %d specified (max %d)\n",
104+
platformIndex,
105+
(int)(platforms.size() - 1) );
106+
return false;
107+
}
108+
return true;
109+
}

samples/01_copybuffer/main.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
#include <CL/opencl.hpp>
1010

11+
#include "util.hpp"
12+
1113
const size_t gwx = 1024*1024;
1214

1315
int main(
@@ -41,6 +43,10 @@ int main(
4143
std::vector<cl::Platform> platforms;
4244
cl::Platform::get(&platforms);
4345

46+
if (!checkPlatformIndex(platforms, platformIndex)) {
47+
return -1;
48+
}
49+
4450
printf("Running on platform: %s\n",
4551
platforms[platformIndex].getInfo<CL_PLATFORM_NAME>().c_str() );
4652

samples/02_copybufferkernel/main.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
#include <CL/opencl.hpp>
1010

11+
#include "util.hpp"
12+
1113
const size_t gwx = 1024*1024;
1214

1315
static const char kernelString[] = R"CLC(
@@ -49,6 +51,10 @@ int main(
4951
std::vector<cl::Platform> platforms;
5052
cl::Platform::get(&platforms);
5153

54+
if (!checkPlatformIndex(platforms, platformIndex)) {
55+
return -1;
56+
}
57+
5258
printf("Running on platform: %s\n",
5359
platforms[platformIndex].getInfo<CL_PLATFORM_NAME>().c_str() );
5460

samples/03_mandelbrot/main.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
#include <CL/opencl.hpp>
1313

14+
#include "util.hpp"
15+
1416
const char* filename = "mandelbrot.bmp";
1517

1618
const cl_uint width = 768;
@@ -83,6 +85,10 @@ int main(
8385
std::vector<cl::Platform> platforms;
8486
cl::Platform::get(&platforms);
8587

88+
if (!checkPlatformIndex(platforms, platformIndex)) {
89+
return -1;
90+
}
91+
8692
printf("Running on platform: %s\n",
8793
platforms[platformIndex].getInfo<CL_PLATFORM_NAME>().c_str() );
8894

samples/04_julia/main.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313

1414
#include <chrono>
1515

16+
#include "util.hpp"
17+
1618
const char* filename = "julia.bmp";
1719

1820
const float cr = -0.123f;
@@ -104,6 +106,10 @@ int main(
104106
std::vector<cl::Platform> platforms;
105107
cl::Platform::get(&platforms);
106108

109+
if (!checkPlatformIndex(platforms, platformIndex)) {
110+
return -1;
111+
}
112+
107113
printf("Running on platform: %s\n",
108114
platforms[platformIndex].getInfo<CL_PLATFORM_NAME>().c_str() );
109115

samples/04_sobel/main.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313

1414
#include <chrono>
1515

16+
#include "util.hpp"
17+
1618
const char* filename = "sobel.bmp";
1719

1820
const float cr = -0.123f;
@@ -151,6 +153,10 @@ int main(
151153
std::vector<cl::Platform> platforms;
152154
cl::Platform::get(&platforms);
153155

156+
if (!checkPlatformIndex(platforms, platformIndex)) {
157+
return -1;
158+
}
159+
154160
printf("Running on platform: %s\n",
155161
platforms[platformIndex].getInfo<CL_PLATFORM_NAME>().c_str() );
156162

samples/05_kernelfromfile/main.cpp

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,26 +11,7 @@
1111
#include <fstream>
1212
#include <string>
1313

14-
static std::string readStringFromFile(
15-
const std::string& filename )
16-
{
17-
std::ifstream is(filename, std::ios::binary);
18-
if (!is.good()) {
19-
printf("Couldn't open file '%s'!\n", filename.c_str());
20-
return "";
21-
}
22-
23-
size_t filesize = 0;
24-
is.seekg(0, std::ios::end);
25-
filesize = (size_t)is.tellg();
26-
is.seekg(0, std::ios::beg);
27-
28-
std::string source{
29-
std::istreambuf_iterator<char>(is),
30-
std::istreambuf_iterator<char>() };
31-
32-
return source;
33-
}
14+
#include "util.hpp"
3415

3516
int main(
3617
int argc,
@@ -71,6 +52,10 @@ int main(
7152
std::vector<cl::Platform> platforms;
7253
cl::Platform::get(&platforms);
7354

55+
if (!checkPlatformIndex(platforms, platformIndex)) {
56+
return -1;
57+
}
58+
7459
printf("Running on platform: %s\n",
7560
platforms[platformIndex].getInfo<CL_PLATFORM_NAME>().c_str() );
7661

samples/05_spirvkernelfromfile/main.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,10 @@ int main(
134134
std::vector<cl::Platform> platforms;
135135
cl::Platform::get(&platforms);
136136

137+
if (!checkPlatformIndex(platforms, platformIndex)) {
138+
return -1;
139+
}
140+
137141
printf("Running on platform: %s\n",
138142
platforms[platformIndex].getInfo<CL_PLATFORM_NAME>().c_str() );
139143

samples/06_ndrangekernelfromfile/main.cpp

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,26 +11,7 @@
1111
#include <fstream>
1212
#include <string>
1313

14-
static std::string readStringFromFile(
15-
const std::string& filename )
16-
{
17-
std::ifstream is(filename, std::ios::binary);
18-
if (!is.good()) {
19-
printf("Couldn't open file '%s'!\n", filename.c_str());
20-
return "";
21-
}
22-
23-
size_t filesize = 0;
24-
is.seekg(0, std::ios::end);
25-
filesize = (size_t)is.tellg();
26-
is.seekg(0, std::ios::beg);
27-
28-
std::string source{
29-
std::istreambuf_iterator<char>(is),
30-
std::istreambuf_iterator<char>() };
31-
32-
return source;
33-
}
14+
#include "util.hpp"
3415

3516
int main(
3617
int argc,
@@ -86,6 +67,10 @@ int main(
8667
std::vector<cl::Platform> platforms;
8768
cl::Platform::get(&platforms);
8869

70+
if (!checkPlatformIndex(platforms, platformIndex)) {
71+
return -1;
72+
}
73+
8974
printf("Running on platform: %s\n",
9075
platforms[platformIndex].getInfo<CL_PLATFORM_NAME>().c_str() );
9176

samples/10_queueexperiments/main.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,10 @@ int main(
413413
std::vector<cl::Platform> platforms;
414414
cl::Platform::get(&platforms);
415415

416+
if (!checkPlatformIndex(platforms, platformIndex)) {
417+
return -1;
418+
}
419+
416420
printf("Running on platform: %s\n",
417421
platforms[platformIndex].getInfo<CL_PLATFORM_NAME>().c_str() );
418422

0 commit comments

Comments
 (0)