diff --git a/include/util.hpp b/include/util.hpp index d0f87e6..8947dc9 100644 --- a/include/util.hpp +++ b/include/util.hpp @@ -67,3 +67,20 @@ static bool checkDeviceForExtension( return supported; } + +static bool checkPlatformIndex( + const std::vector& platforms, + int platformIndex) +{ + if (platforms.size() == 0) { + fprintf(stderr, "Error: No OpenCL platforms found.\n"); + return false; + } + if (platformIndex >= (int)platforms.size()) { + fprintf(stderr, "Error: Invalid platform index %d specified (max %d)\n", + platformIndex, + (int)(platforms.size() - 1) ); + return false; + } + return true; +} diff --git a/samples/01_copybuffer/main.cpp b/samples/01_copybuffer/main.cpp index 8aba750..a5b962f 100644 --- a/samples/01_copybuffer/main.cpp +++ b/samples/01_copybuffer/main.cpp @@ -8,6 +8,8 @@ #include +#include "util.hpp" + const size_t gwx = 1024*1024; int main( @@ -41,6 +43,10 @@ int main( std::vector platforms; cl::Platform::get(&platforms); + if (!checkPlatformIndex(platforms, platformIndex)) { + return -1; + } + printf("Running on platform: %s\n", platforms[platformIndex].getInfo().c_str() ); diff --git a/samples/02_copybufferkernel/main.cpp b/samples/02_copybufferkernel/main.cpp index a16eaa5..aadcbe5 100644 --- a/samples/02_copybufferkernel/main.cpp +++ b/samples/02_copybufferkernel/main.cpp @@ -8,6 +8,8 @@ #include +#include "util.hpp" + const size_t gwx = 1024*1024; static const char kernelString[] = R"CLC( @@ -49,6 +51,10 @@ int main( std::vector platforms; cl::Platform::get(&platforms); + if (!checkPlatformIndex(platforms, platformIndex)) { + return -1; + } + printf("Running on platform: %s\n", platforms[platformIndex].getInfo().c_str() ); diff --git a/samples/03_mandelbrot/main.cpp b/samples/03_mandelbrot/main.cpp index 10e0f1e..6e65f86 100644 --- a/samples/03_mandelbrot/main.cpp +++ b/samples/03_mandelbrot/main.cpp @@ -11,6 +11,8 @@ #include +#include "util.hpp" + const char* filename = "mandelbrot.bmp"; const cl_uint width = 768; @@ -83,6 +85,10 @@ int main( std::vector platforms; cl::Platform::get(&platforms); + if (!checkPlatformIndex(platforms, platformIndex)) { + return -1; + } + printf("Running on platform: %s\n", platforms[platformIndex].getInfo().c_str() ); diff --git a/samples/04_julia/main.cpp b/samples/04_julia/main.cpp index ebd87ff..ed5d281 100644 --- a/samples/04_julia/main.cpp +++ b/samples/04_julia/main.cpp @@ -13,6 +13,8 @@ #include +#include "util.hpp" + const char* filename = "julia.bmp"; const float cr = -0.123f; @@ -104,6 +106,10 @@ int main( std::vector platforms; cl::Platform::get(&platforms); + if (!checkPlatformIndex(platforms, platformIndex)) { + return -1; + } + printf("Running on platform: %s\n", platforms[platformIndex].getInfo().c_str() ); diff --git a/samples/04_sobel/main.cpp b/samples/04_sobel/main.cpp index 9a7903c..ba2cf02 100644 --- a/samples/04_sobel/main.cpp +++ b/samples/04_sobel/main.cpp @@ -13,6 +13,8 @@ #include +#include "util.hpp" + const char* filename = "sobel.bmp"; const float cr = -0.123f; @@ -151,6 +153,10 @@ int main( std::vector platforms; cl::Platform::get(&platforms); + if (!checkPlatformIndex(platforms, platformIndex)) { + return -1; + } + printf("Running on platform: %s\n", platforms[platformIndex].getInfo().c_str() ); diff --git a/samples/05_kernelfromfile/main.cpp b/samples/05_kernelfromfile/main.cpp index c189e54..4a665bc 100644 --- a/samples/05_kernelfromfile/main.cpp +++ b/samples/05_kernelfromfile/main.cpp @@ -11,6 +11,8 @@ #include #include +#include "util.hpp" + static std::string readStringFromFile( const std::string& filename ) { @@ -71,6 +73,10 @@ int main( std::vector platforms; cl::Platform::get(&platforms); + if (!checkPlatformIndex(platforms, platformIndex)) { + return -1; + } + printf("Running on platform: %s\n", platforms[platformIndex].getInfo().c_str() ); diff --git a/samples/05_spirvkernelfromfile/main.cpp b/samples/05_spirvkernelfromfile/main.cpp index de3d628..43ac03c 100644 --- a/samples/05_spirvkernelfromfile/main.cpp +++ b/samples/05_spirvkernelfromfile/main.cpp @@ -134,6 +134,10 @@ int main( std::vector platforms; cl::Platform::get(&platforms); + if (!checkPlatformIndex(platforms, platformIndex)) { + return -1; + } + printf("Running on platform: %s\n", platforms[platformIndex].getInfo().c_str() ); diff --git a/samples/06_ndrangekernelfromfile/main.cpp b/samples/06_ndrangekernelfromfile/main.cpp index 8bd9efc..9968079 100644 --- a/samples/06_ndrangekernelfromfile/main.cpp +++ b/samples/06_ndrangekernelfromfile/main.cpp @@ -11,6 +11,8 @@ #include #include +#include "util.hpp" + static std::string readStringFromFile( const std::string& filename ) { @@ -86,6 +88,10 @@ int main( std::vector platforms; cl::Platform::get(&platforms); + if (!checkPlatformIndex(platforms, platformIndex)) { + return -1; + } + printf("Running on platform: %s\n", platforms[platformIndex].getInfo().c_str() ); diff --git a/samples/10_queueexperiments/main.cpp b/samples/10_queueexperiments/main.cpp index 7f903b6..6c7369b 100644 --- a/samples/10_queueexperiments/main.cpp +++ b/samples/10_queueexperiments/main.cpp @@ -413,6 +413,10 @@ int main( std::vector platforms; cl::Platform::get(&platforms); + if (!checkPlatformIndex(platforms, platformIndex)) { + return -1; + } + printf("Running on platform: %s\n", platforms[platformIndex].getInfo().c_str() ); diff --git a/samples/11_semaphores/main.cpp b/samples/11_semaphores/main.cpp index df59bcc..b487b71 100644 --- a/samples/11_semaphores/main.cpp +++ b/samples/11_semaphores/main.cpp @@ -71,6 +71,10 @@ int main( std::vector platforms; cl::Platform::get(&platforms); + if (!checkPlatformIndex(platforms, platformIndex)) { + return -1; + } + printf("Running on platform: %s\n", platforms[platformIndex].getInfo().c_str() ); diff --git a/samples/12_commandbuffers/main.cpp b/samples/12_commandbuffers/main.cpp index 8acaf11..f176a5c 100644 --- a/samples/12_commandbuffers/main.cpp +++ b/samples/12_commandbuffers/main.cpp @@ -97,6 +97,10 @@ int main( std::vector platforms; cl::Platform::get(&platforms); + if (!checkPlatformIndex(platforms, platformIndex)) { + return -1; + } + printf("Running on platform: %s\n", platforms[platformIndex].getInfo().c_str() ); diff --git a/samples/12_commandbufferspp/main.cpp b/samples/12_commandbufferspp/main.cpp index 1bb432b..9e566b7 100644 --- a/samples/12_commandbufferspp/main.cpp +++ b/samples/12_commandbufferspp/main.cpp @@ -92,6 +92,10 @@ int main( std::vector platforms; cl::Platform::get(&platforms); + if (!checkPlatformIndex(platforms, platformIndex)) { + return -1; + } + printf("Running on platform: %s\n", platforms[platformIndex].getInfo().c_str() ); diff --git a/samples/13_mutablecommandbuffers/main.cpp b/samples/13_mutablecommandbuffers/main.cpp index dc6875d..45c3dc0 100644 --- a/samples/13_mutablecommandbuffers/main.cpp +++ b/samples/13_mutablecommandbuffers/main.cpp @@ -114,6 +114,10 @@ int main( std::vector platforms; cl::Platform::get(&platforms); + if (!checkPlatformIndex(platforms, platformIndex)) { + return -1; + } + printf("Running on platform: %s\n", platforms[platformIndex].getInfo().c_str() ); diff --git a/samples/14_ooqcommandbuffers/main.cpp b/samples/14_ooqcommandbuffers/main.cpp index e7c2864..abed0ff 100644 --- a/samples/14_ooqcommandbuffers/main.cpp +++ b/samples/14_ooqcommandbuffers/main.cpp @@ -67,6 +67,10 @@ int main( std::vector platforms; cl::Platform::get(&platforms); + if (!checkPlatformIndex(platforms, platformIndex)) { + return -1; + } + printf("Running on platform: %s\n", platforms[platformIndex].getInfo().c_str() ); diff --git a/samples/15_mutablecommandbufferasserts/main.cpp b/samples/15_mutablecommandbufferasserts/main.cpp index 33983a1..2fb4ded 100644 --- a/samples/15_mutablecommandbufferasserts/main.cpp +++ b/samples/15_mutablecommandbufferasserts/main.cpp @@ -67,6 +67,10 @@ int main( std::vector platforms; cl::Platform::get(&platforms); + if (!checkPlatformIndex(platforms, platformIndex)) { + return -1; + } + printf("Running on platform: %s\n", platforms[platformIndex].getInfo().c_str() ); diff --git a/samples/16_floatatomics/main.cpp b/samples/16_floatatomics/main.cpp index 1d4899e..ebd24c3 100644 --- a/samples/16_floatatomics/main.cpp +++ b/samples/16_floatatomics/main.cpp @@ -124,6 +124,10 @@ int main( std::vector platforms; cl::Platform::get(&platforms); + if (!checkPlatformIndex(platforms, platformIndex)) { + return -1; + } + printf("Running on platform: %s\n", platforms[platformIndex].getInfo().c_str() ); diff --git a/samples/images/00_enumimageformats/main.cpp b/samples/images/00_enumimageformats/main.cpp index 7449e95..81d1f0e 100644 --- a/samples/images/00_enumimageformats/main.cpp +++ b/samples/images/00_enumimageformats/main.cpp @@ -10,6 +10,8 @@ #include +#include "util.hpp" + #define CASE_TO_STRING(_e) case _e: return #_e; const char* mem_object_type_to_string(cl_mem_object_type mem_object_type) @@ -159,6 +161,10 @@ int main( std::vector platforms; cl::Platform::get(&platforms); + if (!checkPlatformIndex(platforms, platformIndex)) { + return -1; + } + printf("Querying platform: %s\n", platforms[platformIndex].getInfo().c_str() ); diff --git a/samples/opengl/00_juliagl/main.cpp b/samples/opengl/00_juliagl/main.cpp index 856cb81..2e8614d 100644 --- a/samples/opengl/00_juliagl/main.cpp +++ b/samples/opengl/00_juliagl/main.cpp @@ -493,6 +493,10 @@ int main( std::vector platforms; cl::Platform::get(&platforms); + if (!checkPlatformIndex(platforms, platformIndex)) { + return -1; + } + printf("Running on platform: %s\n", platforms[platformIndex].getInfo().c_str() ); diff --git a/samples/opengl/01_nbodygl/main.cpp b/samples/opengl/01_nbodygl/main.cpp index ebc8589..1241bfe 100644 --- a/samples/opengl/01_nbodygl/main.cpp +++ b/samples/opengl/01_nbodygl/main.cpp @@ -280,6 +280,10 @@ int main( std::vector platforms; cl::Platform::get(&platforms); + if (!checkPlatformIndex(platforms, platformIndex)) { + return -1; + } + printf("Running on platform: %s\n", platforms[platformIndex].getInfo().c_str() ); diff --git a/samples/opengl/02_sobelgl/main.cpp b/samples/opengl/02_sobelgl/main.cpp index f4378cb..f05fa39 100644 --- a/samples/opengl/02_sobelgl/main.cpp +++ b/samples/opengl/02_sobelgl/main.cpp @@ -540,6 +540,10 @@ int main( std::vector platforms; cl::Platform::get(&platforms); + if (!checkPlatformIndex(platforms, platformIndex)) { + return -1; + } + printf("Running on platform: %s\n", platforms[platformIndex].getInfo().c_str() ); diff --git a/samples/python/01_copybuffer/copybuffer.py b/samples/python/01_copybuffer/copybuffer.py index b38968d..098a2e6 100644 --- a/samples/python/01_copybuffer/copybuffer.py +++ b/samples/python/01_copybuffer/copybuffer.py @@ -7,6 +7,7 @@ import numpy as np import pyopencl as cl import argparse +import sys gwx = 1024 * 1024 @@ -20,6 +21,8 @@ deviceIndex = args.device platforms = cl.get_platforms() + if platformIndex >= len(platforms): + sys.exit('Invalid platform index: {}'.format(platformIndex)) print('Running on platform: ' + platforms[platformIndex].get_info(cl.platform_info.NAME)) devices = platforms[platformIndex].get_devices() diff --git a/samples/python/02_copybufferkernel/copybufferkernel.py b/samples/python/02_copybufferkernel/copybufferkernel.py index 9d611a8..099b250 100644 --- a/samples/python/02_copybufferkernel/copybufferkernel.py +++ b/samples/python/02_copybufferkernel/copybufferkernel.py @@ -7,6 +7,7 @@ import numpy as np import pyopencl as cl import argparse +import sys gwx = 1024 * 1024 @@ -28,6 +29,8 @@ deviceIndex = args.device platforms = cl.get_platforms() + if platformIndex >= len(platforms): + sys.exit('Invalid platform index: {}'.format(platformIndex)) print('Running on platform: ' + platforms[platformIndex].get_info(cl.platform_info.NAME)) devices = platforms[platformIndex].get_devices() diff --git a/samples/python/03_mandelbrot/mandelbrot.py b/samples/python/03_mandelbrot/mandelbrot.py index 6e26e63..3c9cf43 100644 --- a/samples/python/03_mandelbrot/mandelbrot.py +++ b/samples/python/03_mandelbrot/mandelbrot.py @@ -10,6 +10,7 @@ import pyopencl as cl import argparse import PIL +import sys filename = 'mandelbrot.bmp' @@ -63,6 +64,8 @@ deviceIndex = args.device platforms = cl.get_platforms() + if platformIndex >= len(platforms): + sys.exit('Invalid platform index: {}'.format(platformIndex)) print('Running on platform: ' + platforms[platformIndex].get_info(cl.platform_info.NAME)) devices = platforms[platformIndex].get_devices() diff --git a/samples/python/04_julia/julia.py b/samples/python/04_julia/julia.py index 83ceb0a..494dec5 100644 --- a/samples/python/04_julia/julia.py +++ b/samples/python/04_julia/julia.py @@ -10,6 +10,7 @@ import pyopencl as cl import argparse import PIL +import sys import time filename = 'julia.bmp' @@ -87,6 +88,8 @@ lwy = args.lwy platforms = cl.get_platforms() + if platformIndex >= len(platforms): + sys.exit('Invalid platform index: {}'.format(platformIndex)) print('Running on platform: ' + platforms[platformIndex].get_info(cl.platform_info.NAME)) devices = platforms[platformIndex].get_devices() diff --git a/samples/svm/100_cgsvmhelloworld/main.cpp b/samples/svm/100_cgsvmhelloworld/main.cpp index 4c05642..5a34168 100644 --- a/samples/svm/100_cgsvmhelloworld/main.cpp +++ b/samples/svm/100_cgsvmhelloworld/main.cpp @@ -8,6 +8,8 @@ #include +#include "util.hpp" + const size_t gwx = 1024*1024; static const char kernelString[] = R"CLC( @@ -48,6 +50,10 @@ int main( std::vector platforms; cl::Platform::get(&platforms); + if (!checkPlatformIndex(platforms, platformIndex)) { + return -1; + } + printf("Running on platform: %s\n", platforms[platformIndex].getInfo().c_str() ); diff --git a/samples/svm/101_cgsvmlinkedlist/main.cpp b/samples/svm/101_cgsvmlinkedlist/main.cpp index e050e38..ce2961b 100644 --- a/samples/svm/101_cgsvmlinkedlist/main.cpp +++ b/samples/svm/101_cgsvmlinkedlist/main.cpp @@ -8,6 +8,8 @@ #include +#include "util.hpp" + cl::CommandQueue commandQueue; cl::Kernel kernel; @@ -196,6 +198,10 @@ int main( std::vector platforms; cl::Platform::get(&platforms); + if (!checkPlatformIndex(platforms, platformIndex)) { + return -1; + } + printf("Running on platform: %s\n", platforms[platformIndex].getInfo().c_str() ); diff --git a/samples/svm/200_fgsvmhelloworld/main.cpp b/samples/svm/200_fgsvmhelloworld/main.cpp index 4a90199..07b2849 100644 --- a/samples/svm/200_fgsvmhelloworld/main.cpp +++ b/samples/svm/200_fgsvmhelloworld/main.cpp @@ -8,6 +8,8 @@ #include +#include "util.hpp" + const size_t gwx = 1024*1024; static const char kernelString[] = R"CLC( @@ -48,6 +50,10 @@ int main( std::vector platforms; cl::Platform::get(&platforms); + if (!checkPlatformIndex(platforms, platformIndex)) { + return -1; + } + printf("Running on platform: %s\n", platforms[platformIndex].getInfo().c_str() ); diff --git a/samples/svm/201_fgsvmlinkedlist/main.cpp b/samples/svm/201_fgsvmlinkedlist/main.cpp index b03f672..657bc2d 100644 --- a/samples/svm/201_fgsvmlinkedlist/main.cpp +++ b/samples/svm/201_fgsvmlinkedlist/main.cpp @@ -8,6 +8,8 @@ #include +#include "util.hpp" + cl::CommandQueue commandQueue; cl::Kernel kernel; @@ -190,6 +192,10 @@ int main( std::vector platforms; cl::Platform::get(&platforms); + if (!checkPlatformIndex(platforms, platformIndex)) { + return -1; + } + printf("Running on platform: %s\n", platforms[platformIndex].getInfo().c_str() ); diff --git a/samples/usm/01_usmmeminfo/main.cpp b/samples/usm/01_usmmeminfo/main.cpp index 4db23b7..11d994e 100644 --- a/samples/usm/01_usmmeminfo/main.cpp +++ b/samples/usm/01_usmmeminfo/main.cpp @@ -8,6 +8,8 @@ #include +#include "util.hpp" + // Each of these functions should eventually move into opencl.hpp: static cl_unified_shared_memory_type_intel @@ -110,6 +112,10 @@ int main( std::vector platforms; cl::Platform::get(&platforms); + if (!checkPlatformIndex(platforms, platformIndex)) { + return -1; + } + printf("Running on platform: %s\n", platforms[platformIndex].getInfo().c_str() ); diff --git a/samples/usm/100_dmemhelloworld/main.cpp b/samples/usm/100_dmemhelloworld/main.cpp index 4b90c53..266bb96 100644 --- a/samples/usm/100_dmemhelloworld/main.cpp +++ b/samples/usm/100_dmemhelloworld/main.cpp @@ -8,6 +8,8 @@ #include +#include "util.hpp" + const size_t gwx = 1024*1024; static const char kernelString[] = R"CLC( @@ -48,6 +50,10 @@ int main( std::vector platforms; cl::Platform::get(&platforms); + if (!checkPlatformIndex(platforms, platformIndex)) { + return -1; + } + printf("Running on platform: %s\n", platforms[platformIndex].getInfo().c_str() ); diff --git a/samples/usm/101_dmemlinkedlist/main.cpp b/samples/usm/101_dmemlinkedlist/main.cpp index bb8b7b2..462f995 100644 --- a/samples/usm/101_dmemlinkedlist/main.cpp +++ b/samples/usm/101_dmemlinkedlist/main.cpp @@ -8,6 +8,8 @@ #include +#include "util.hpp" + cl::CommandQueue commandQueue; cl::Kernel kernel; @@ -212,6 +214,10 @@ int main( std::vector platforms; cl::Platform::get(&platforms); + if (!checkPlatformIndex(platforms, platformIndex)) { + return -1; + } + printf("Running on platform: %s\n", platforms[platformIndex].getInfo().c_str() ); diff --git a/samples/usm/200_hmemhelloworld/main.cpp b/samples/usm/200_hmemhelloworld/main.cpp index 266b499..4081d4d 100644 --- a/samples/usm/200_hmemhelloworld/main.cpp +++ b/samples/usm/200_hmemhelloworld/main.cpp @@ -8,6 +8,8 @@ #include +#include "util.hpp" + const size_t gwx = 1024*1024; static const char kernelString[] = R"CLC( @@ -48,6 +50,10 @@ int main( std::vector platforms; cl::Platform::get(&platforms); + if (!checkPlatformIndex(platforms, platformIndex)) { + return -1; + } + printf("Running on platform: %s\n", platforms[platformIndex].getInfo().c_str() ); diff --git a/samples/usm/201_hmemlinkedlist/main.cpp b/samples/usm/201_hmemlinkedlist/main.cpp index c62c090..99a4a06 100644 --- a/samples/usm/201_hmemlinkedlist/main.cpp +++ b/samples/usm/201_hmemlinkedlist/main.cpp @@ -8,6 +8,8 @@ #include +#include "util.hpp" + cl::CommandQueue commandQueue; cl::Kernel kernel; @@ -192,6 +194,10 @@ int main( std::vector platforms; cl::Platform::get(&platforms); + if (!checkPlatformIndex(platforms, platformIndex)) { + return -1; + } + printf("Running on platform: %s\n", platforms[platformIndex].getInfo().c_str() ); diff --git a/samples/usm/300_smemhelloworld/main.cpp b/samples/usm/300_smemhelloworld/main.cpp index 0c12a2b..86fffae 100644 --- a/samples/usm/300_smemhelloworld/main.cpp +++ b/samples/usm/300_smemhelloworld/main.cpp @@ -8,6 +8,8 @@ #include +#include "util.hpp" + const size_t gwx = 1024*1024; static const char kernelString[] = R"CLC( @@ -48,6 +50,10 @@ int main( std::vector platforms; cl::Platform::get(&platforms); + if (!checkPlatformIndex(platforms, platformIndex)) { + return -1; + } + printf("Running on platform: %s\n", platforms[platformIndex].getInfo().c_str() ); diff --git a/samples/usm/301_smemlinkedlist/main.cpp b/samples/usm/301_smemlinkedlist/main.cpp index 45d1afb..a469e34 100644 --- a/samples/usm/301_smemlinkedlist/main.cpp +++ b/samples/usm/301_smemlinkedlist/main.cpp @@ -8,6 +8,8 @@ #include +#include "util.hpp" + cl::CommandQueue commandQueue; cl::Kernel kernel; @@ -194,6 +196,10 @@ int main( std::vector platforms; cl::Platform::get(&platforms); + if (!checkPlatformIndex(platforms, platformIndex)) { + return -1; + } + printf("Running on platform: %s\n", platforms[platformIndex].getInfo().c_str() ); diff --git a/samples/usm/310_usmmigratemem/main.cpp b/samples/usm/310_usmmigratemem/main.cpp index c7000d1..e1008c7 100644 --- a/samples/usm/310_usmmigratemem/main.cpp +++ b/samples/usm/310_usmmigratemem/main.cpp @@ -8,6 +8,8 @@ #include +#include "util.hpp" + const size_t gwx = 1024*1024; static const char kernelString[] = R"CLC( @@ -48,6 +50,10 @@ int main( std::vector platforms; cl::Platform::get(&platforms); + if (!checkPlatformIndex(platforms, platformIndex)) { + return -1; + } + printf("Running on platform: %s\n", platforms[platformIndex].getInfo().c_str() ); diff --git a/samples/usm/400_sysmemhelloworld/main.cpp b/samples/usm/400_sysmemhelloworld/main.cpp index 69d5d4a..806722a 100644 --- a/samples/usm/400_sysmemhelloworld/main.cpp +++ b/samples/usm/400_sysmemhelloworld/main.cpp @@ -8,6 +8,8 @@ #include +#include "util.hpp" + const size_t gwx = 1024*1024; static const char kernelString[] = R"CLC( @@ -48,6 +50,10 @@ int main( std::vector platforms; cl::Platform::get(&platforms); + if (!checkPlatformIndex(platforms, platformIndex)) { + return -1; + } + printf("Running on platform: %s\n", platforms[platformIndex].getInfo().c_str() ); diff --git a/samples/vulkan/00_juliavk/main.cpp b/samples/vulkan/00_juliavk/main.cpp index c7bd0cf..27a7642 100644 --- a/samples/vulkan/00_juliavk/main.cpp +++ b/samples/vulkan/00_juliavk/main.cpp @@ -303,6 +303,10 @@ class JuliaVKApplication { std::vector platforms; cl::Platform::get(&platforms); + if (!checkPlatformIndex(platforms, platformIndex)) { + throw std::runtime_error("couldn't get OpenCL platform"); + } + printf("Running on platform: %s\n", platforms[platformIndex].getInfo().c_str() ); diff --git a/samples/vulkan/01_nbodyvk/main.cpp b/samples/vulkan/01_nbodyvk/main.cpp index 71f309c..a18586d 100644 --- a/samples/vulkan/01_nbodyvk/main.cpp +++ b/samples/vulkan/01_nbodyvk/main.cpp @@ -290,6 +290,10 @@ class NBodyVKApplication { std::vector platforms; cl::Platform::get(&platforms); + if (!checkPlatformIndex(platforms, platformIndex)) { + throw std::runtime_error("couldn't get OpenCL platform"); + } + printf("Running on platform: %s\n", platforms[platformIndex].getInfo().c_str() ); diff --git a/tutorials/interceptlayer/main-part1solution.cpp b/tutorials/interceptlayer/main-part1solution.cpp index a3286aa..c61836e 100644 --- a/tutorials/interceptlayer/main-part1solution.cpp +++ b/tutorials/interceptlayer/main-part1solution.cpp @@ -13,6 +13,8 @@ #include +#include "util.hpp" + const char* filename = "sinjulia.bmp"; size_t iterations = 16; @@ -193,6 +195,10 @@ int main( std::vector platforms; cl::Platform::get(&platforms); + if (!checkPlatformIndex(platforms, platformIndex)) { + return -1; + } + printf("Running on platform: %s\n", platforms[platformIndex].getInfo().c_str() ); diff --git a/tutorials/interceptlayer/main-part2solution.cpp b/tutorials/interceptlayer/main-part2solution.cpp index a854730..2c50622 100644 --- a/tutorials/interceptlayer/main-part2solution.cpp +++ b/tutorials/interceptlayer/main-part2solution.cpp @@ -13,6 +13,8 @@ #include +#include "util.hpp" + const char* filename = "sinjulia.bmp"; size_t iterations = 16; @@ -193,6 +195,10 @@ int main( std::vector platforms; cl::Platform::get(&platforms); + if (!checkPlatformIndex(platforms, platformIndex)) { + return -1; + } + printf("Running on platform: %s\n", platforms[platformIndex].getInfo().c_str() ); diff --git a/tutorials/interceptlayer/main-part3solution.cpp b/tutorials/interceptlayer/main-part3solution.cpp index 16d094a..4163a0b 100644 --- a/tutorials/interceptlayer/main-part3solution.cpp +++ b/tutorials/interceptlayer/main-part3solution.cpp @@ -13,6 +13,8 @@ #include +#include "util.hpp" + const char* filename = "sinjulia.bmp"; size_t iterations = 16; @@ -192,6 +194,10 @@ int main( std::vector platforms; cl::Platform::get(&platforms); + if (!checkPlatformIndex(platforms, platformIndex)) { + return -1; + } + printf("Running on platform: %s\n", platforms[platformIndex].getInfo().c_str() ); diff --git a/tutorials/interceptlayer/main-part4solution.cpp b/tutorials/interceptlayer/main-part4solution.cpp index 369b49c..b44afc6 100644 --- a/tutorials/interceptlayer/main-part4solution.cpp +++ b/tutorials/interceptlayer/main-part4solution.cpp @@ -13,6 +13,8 @@ #include +#include "util.hpp" + const char* filename = "sinjulia.bmp"; size_t iterations = 16; @@ -188,6 +190,10 @@ int main( std::vector platforms; cl::Platform::get(&platforms); + if (!checkPlatformIndex(platforms, platformIndex)) { + return -1; + } + printf("Running on platform: %s\n", platforms[platformIndex].getInfo().c_str() ); diff --git a/tutorials/interceptlayer/main-part5solution.cpp b/tutorials/interceptlayer/main-part5solution.cpp index c7812ee..ece8ec0 100644 --- a/tutorials/interceptlayer/main-part5solution.cpp +++ b/tutorials/interceptlayer/main-part5solution.cpp @@ -13,6 +13,8 @@ #include +#include "util.hpp" + const char* filename = "sinjulia.bmp"; size_t iterations = 16; @@ -188,6 +190,10 @@ int main( std::vector platforms; cl::Platform::get(&platforms); + if (!checkPlatformIndex(platforms, platformIndex)) { + return -1; + } + printf("Running on platform: %s\n", platforms[platformIndex].getInfo().c_str() ); diff --git a/tutorials/interceptlayer/main-start.cpp b/tutorials/interceptlayer/main-start.cpp index 0c82e74..d439509 100644 --- a/tutorials/interceptlayer/main-start.cpp +++ b/tutorials/interceptlayer/main-start.cpp @@ -13,6 +13,8 @@ #include +#include "util.hpp" + const char* filename = "sinjulia.bmp"; size_t iterations = 16; @@ -197,6 +199,10 @@ int main( printf("This is the Intercept Layer Tutorial application.\n"); printf("It will crash initially! Please see the tutorial README for details.\n"); + if (!checkPlatformIndex(platforms, platformIndex)) { + return -1; + } + printf("Running on platform: %s\n", platforms[platformIndex].getInfo().c_str() ); diff --git a/tutorials/interceptlayer/main.cpp b/tutorials/interceptlayer/main.cpp index 0c82e74..d439509 100644 --- a/tutorials/interceptlayer/main.cpp +++ b/tutorials/interceptlayer/main.cpp @@ -13,6 +13,8 @@ #include +#include "util.hpp" + const char* filename = "sinjulia.bmp"; size_t iterations = 16; @@ -197,6 +199,10 @@ int main( printf("This is the Intercept Layer Tutorial application.\n"); printf("It will crash initially! Please see the tutorial README for details.\n"); + if (!checkPlatformIndex(platforms, platformIndex)) { + return -1; + } + printf("Running on platform: %s\n", platforms[platformIndex].getInfo().c_str() );