Skip to content

Commit 44e1423

Browse files
authored
add a simple sample that queries ICD loader info (#69)
* add a sample that queries ICD loader information * small updates to the ICD Loader query
1 parent e3321a5 commit 44e1423

3 files changed

Lines changed: 121 additions & 0 deletions

File tree

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Copyright (c) 2022 Ben Ashbaugh
2+
#
3+
# Permission is hereby granted, free of charge, to any person obtaining a copy
4+
# of this software and associated documentation files (the "Software"), to deal
5+
# in the Software without restriction, including without limitation the rights
6+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
# copies of the Software, and to permit persons to whom the Software is
8+
# furnished to do so, subject to the following conditions:
9+
#
10+
# The above copyright notice and this permission notice shall be included in all
11+
# copies or substantial portions of the Software.
12+
#
13+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19+
# SOFTWARE.
20+
21+
add_opencl_sample(
22+
TEST
23+
NUMBER 00
24+
TARGET loaderinfo
25+
VERSION 100
26+
SOURCES main.cpp)

samples/99_loaderinfo/main.cpp

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
/*
2+
// Copyright (c) 2019-2020 Ben Ashbaugh
3+
//
4+
// Permission is hereby granted, free of charge, to any person obtaining a copy
5+
// of this software and associated documentation files (the "Software"), to deal
6+
// in the Software without restriction, including without limitation the rights
7+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
// copies of the Software, and to permit persons to whom the Software is
9+
// furnished to do so, subject to the following conditions:
10+
//
11+
// The above copyright notice and this permission notice shall be included in all
12+
// copies or substantial portions of the Software.
13+
//
14+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20+
// SOFTWARE.
21+
*/
22+
23+
#include <stdio.h>
24+
#include <vector>
25+
#include <popl/popl.hpp>
26+
27+
#include <CL/cl.h>
28+
29+
typedef cl_uint cl_icdl_info;
30+
31+
#define CL_ICDL_OCL_VERSION 1
32+
#define CL_ICDL_VERSION 2
33+
#define CL_ICDL_NAME 3
34+
#define CL_ICDL_VENDOR 4
35+
36+
typedef cl_int (*pfn_clGetICDLoaderInfoOCLICD)(cl_icdl_info, size_t, void*, size_t*);
37+
pfn_clGetICDLoaderInfoOCLICD clGetICDLoaderInfoOCLICD = NULL;
38+
39+
static void PrintLoaderInfo(const char* label, cl_icdl_info info)
40+
{
41+
size_t sz = 0;
42+
clGetICDLoaderInfoOCLICD(info, 0, nullptr, &sz);
43+
44+
std::vector<char> str(sz);
45+
clGetICDLoaderInfoOCLICD(info, sz, str.data(), nullptr);
46+
47+
printf("Query for for %s (size = %zu) returned: %s\n", label, sz, str.data());
48+
}
49+
50+
int main(
51+
int argc,
52+
char** argv )
53+
{
54+
{
55+
popl::OptionParser op("Supported Options");
56+
57+
bool printUsage = false;
58+
try {
59+
op.parse(argc, argv);
60+
} catch (std::exception& e) {
61+
fprintf(stderr, "Error: %s\n\n", e.what());
62+
printUsage = true;
63+
}
64+
65+
if (printUsage || !op.unknown_options().empty() || !op.non_option_args().empty()) {
66+
fprintf(stderr,
67+
"Usage: loaderinfo [options]\n"
68+
"%s", op.help().c_str());
69+
return -1;
70+
}
71+
}
72+
73+
74+
clGetICDLoaderInfoOCLICD = (pfn_clGetICDLoaderInfoOCLICD)
75+
clGetExtensionFunctionAddress("clGetICDLoaderInfoOCLICD");
76+
77+
if (clGetICDLoaderInfoOCLICD == NULL) {
78+
printf("Couldn't get function pointer to clGetICDLoaderInfoOCLICD!\n");
79+
printf("This is normal and some ICD loaders do not support this functionality.\n");
80+
printf("Exiting...\n");
81+
return 0;
82+
}
83+
84+
#define QUERY_AND_PRINT_LOADER_INFO(_info) \
85+
PrintLoaderInfo(#_info, _info);
86+
87+
QUERY_AND_PRINT_LOADER_INFO(CL_ICDL_OCL_VERSION);
88+
QUERY_AND_PRINT_LOADER_INFO(CL_ICDL_VERSION);
89+
QUERY_AND_PRINT_LOADER_INFO(CL_ICDL_NAME);
90+
QUERY_AND_PRINT_LOADER_INFO(CL_ICDL_VENDOR);
91+
92+
return 0;
93+
}

samples/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,3 +101,5 @@ if(BUILD_EXTENSION_SAMPLES)
101101
add_subdirectory( 13_mutablecommandbuffers )
102102
add_subdirectory( 14_ooqcommandbuffers )
103103
endif()
104+
105+
add_subdirectory( 99_loaderinfo )

0 commit comments

Comments
 (0)