@@ -19,9 +19,6 @@ cl::Platform get_default_platform() { return get_platforms()[0]; }
1919std::vector<cl::Device> get_devices (const cl::Platform &p, int type) {
2020 std::vector<cl::Device> devices;
2121 p.getDevices (type, &devices);
22- if (!devices.size ()) {
23- throw OCLHelpersException (" No device of requested type found!" );
24- }
2522 return devices;
2623}
2724
@@ -55,7 +52,7 @@ cl::Program make_program_from_file(cl::Context &ctx,
5552 return {ctx, kernel_code};
5653}
5754
58- void build (cl::Program &program, cl::Device &device) {
55+ void build (cl::Program &program, const cl::Device &device) {
5956 if (program.build ({device}) != CL_SUCCESS) {
6057 std::stringstream ss;
6158 ss << " Building failed: "
@@ -65,8 +62,8 @@ void build(cl::Program &program, cl::Device &device) {
6562}
6663
6764std::tuple<cl::Platform, cl::Device, cl::Context, cl::Program>
68- compile_file_with (const std::string &filename, cl::Platform &platform,
69- cl::Device &device) {
65+ compile_file_with (const std::string &filename, const cl::Platform &platform,
66+ const cl::Device &device) {
7067 cl::Context ctx ({device});
7168 auto program = make_program_from_file (ctx, filename);
7269 build (program, device);
@@ -83,10 +80,13 @@ compile_file_with_defaults(const std::string &filename) {
8380
8481std::tuple<cl::Platform, cl::Device, cl::Context, cl::Program>
8582compile_file_with_default_cpu (const std::string &filename) {
86- auto platform = get_default_platform ();
87- auto device = get_default_cpu (platform);
83+ for (auto &p : get_platforms ()) {
84+ if (get_cpus (p).size ()) {
85+ return compile_file_with (filename, p, get_default_cpu (p));
86+ }
87+ }
8888
89- return compile_file_with (filename, platform, device );
89+ throw OCLHelpersException ( " No cpu found! " );
9090}
9191
9292std::tuple<cl::Platform, cl::Device, cl::Context, cl::Program>
@@ -96,6 +96,17 @@ compile_file_with_default_cpu(cl::Platform &platform,
9696 return compile_file_with (filename, platform, device);
9797}
9898
99+ std::tuple<cl::Platform, cl::Device, cl::Context, cl::Program>
100+ compile_file_with_default_gpu (const std::string &filename) {
101+ for (auto &p : get_platforms ()) {
102+ if (get_gpus (p).size ()) {
103+ return compile_file_with (filename, p, get_default_gpu (p));
104+ }
105+ }
106+
107+ throw OCLHelpersException (" No gpu found!" );
108+ }
109+
99110std::tuple<cl::Platform, cl::Device, cl::Context, cl::Program>
100111compile_file_with_default_gpu (cl::Platform &platform,
101112 const std::string &filename) {
0 commit comments