Skip to content

Commit

Permalink
add loader shutdown example
Browse files Browse the repository at this point in the history
  • Loading branch information
bashbaug committed Aug 19, 2023
1 parent a9c39e8 commit 2f59c21
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 0 deletions.
10 changes: 10 additions & 0 deletions samples/00_loadershutdown/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Copyright (c) 2023 Ben Ashbaugh
#
# SPDX-License-Identifier: MIT

add_opencl_sample(
TEST
NUMBER 00
TARGET loadershutdown
VERSION 100
SOURCES main.cpp)
78 changes: 78 additions & 0 deletions samples/00_loadershutdown/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/*
// Copyright (c) 2023 Ben Ashbaugh
//
// SPDX-License-Identifier: MIT
*/

#include <stdio.h>
#include <vector>
#include <popl/popl.hpp>

#include <CL/opencl.hpp>

typedef cl_int (*pfn_clShutdownOCLICD)(void);
pfn_clShutdownOCLICD clShutdownOCLICD = NULL;

int main(
int argc,
char** argv )
{
{
popl::OptionParser op("Supported Options");

bool printUsage = false;
try {
op.parse(argc, argv);
} catch (std::exception& e) {
fprintf(stderr, "Error: %s\n\n", e.what());
printUsage = true;
}

if (printUsage || !op.unknown_options().empty() || !op.non_option_args().empty()) {
fprintf(stderr,
"Usage: loadershutdown [options]\n"
"%s", op.help().c_str());
return -1;
}
}


clShutdownOCLICD = (pfn_clShutdownOCLICD)
clGetExtensionFunctionAddress("clShutdownOCLICD");

if (clShutdownOCLICD == NULL) {
printf("Couldn't get function pointer to clShutdownOCLICD!\n");
printf("This is normal and some ICD loaders do not support this functionality.\n");
printf("Exiting...\n");
return 0;
}

std::vector<cl::Platform> platforms;
cl::Platform::get(&platforms);

printf("Before shutting down: queried %zu platforms.\n", platforms.size());
for (const auto& platform: platforms) {
cl_int errorCode = CL_SUCCESS;
auto name = platform.getInfo<CL_PLATFORM_NAME>(&errorCode);
if (errorCode == CL_SUCCESS) {
printf("\tPlatform: %s\n", name.c_str());
} else {
printf("\tQuery returned %d\n", errorCode);
}
}

clShutdownOCLICD();

printf("\nAfter shutting down:\n");
for (const auto& platform: platforms) {
cl_int errorCode = CL_SUCCESS;
auto name = platform.getInfo<CL_PLATFORM_NAME>(&errorCode);
if (errorCode == CL_SUCCESS) {
printf("\tPlatform: %s\n", name.c_str());
} else {
printf("\tQuery returned %d\n", errorCode);
}
}

return 0;
}
1 change: 1 addition & 0 deletions samples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ add_subdirectory( 00_enumopenclpp )
add_subdirectory( 00_enumqueuefamilies )
add_subdirectory( 00_extendeddevicequeries )
add_subdirectory( 00_loaderinfo )
add_subdirectory( 00_loadershutdown )
add_subdirectory( 00_newqueries )
add_subdirectory( 00_newqueriespp )
add_subdirectory( 01_copybuffer )
Expand Down

0 comments on commit 2f59c21

Please sign in to comment.