99#include < cstdlib>
1010#include < iostream>
1111
12-
13- static void check_cu (CUresult status, const char * message) {
12+ static void
13+ check_cu (CUresult status, const char *message)
14+ {
1415 if (status != CUDA_SUCCESS ) {
15- const char * error_name = nullptr ;
16+ const char * error_name = nullptr ;
1617 cuGetErrorName (status, &error_name);
1718 std::cerr << message << " : " << (error_name ? error_name : " unknown" ) << ' \n ' ;
1819 std::exit (1 );
1920 }
2021}
2122
22-
23- int main (int argc, char ** argv) {
23+ int
24+ main (int argc, char **argv)
25+ {
2426 bench::Options options = bench::parse_args (argc, argv);
2527
2628 // Setup: init CUDA and create a context
@@ -45,25 +47,19 @@ int main(int argc, char** argv) {
4547
4648 // --- ctx_set_current ---
4749 {
48- suite.run (" ctx_device.ctx_set_current" , [&]() {
49- check_cu (cuCtxSetCurrent (ctx), " cuCtxSetCurrent failed" );
50- });
50+ suite.run (" ctx_device.ctx_set_current" , [&]() { check_cu (cuCtxSetCurrent (ctx), " cuCtxSetCurrent failed" ); });
5151 }
5252
5353 // --- ctx_get_device ---
5454 {
5555 CUdevice dev;
56- suite.run (" ctx_device.ctx_get_device" , [&]() {
57- check_cu (cuCtxGetDevice (&dev), " cuCtxGetDevice failed" );
58- });
56+ suite.run (" ctx_device.ctx_get_device" , [&]() { check_cu (cuCtxGetDevice (&dev), " cuCtxGetDevice failed" ); });
5957 }
6058
6159 // --- device_get ---
6260 {
6361 CUdevice dev;
64- suite.run (" ctx_device.device_get" , [&]() {
65- check_cu (cuDeviceGet (&dev, 0 ), " cuDeviceGet failed" );
66- });
62+ suite.run (" ctx_device.device_get" , [&]() { check_cu (cuDeviceGet (&dev, 0 ), " cuDeviceGet failed" ); });
6763 }
6864
6965 // --- device_get_attribute ---
@@ -80,21 +76,15 @@ int main(int argc, char** argv) {
8076 // --- device_primary_ctx_retain ---
8177 // Outer retain so the benchmarked retain/release pair just bumps the refcount.
8278 CUcontext primary_outer = nullptr ;
83- check_cu (
84- cuDevicePrimaryCtxRetain (&primary_outer, device),
85- " cuDevicePrimaryCtxRetain (setup) failed"
86- );
79+ check_cu (cuDevicePrimaryCtxRetain (&primary_outer, device), " cuDevicePrimaryCtxRetain (setup) failed" );
8780 {
8881 CUcontext primary = nullptr ;
8982 suite.run (" ctx_device.device_primary_ctx_retain" , [&]() {
9083 check_cu (cuDevicePrimaryCtxRetain (&primary, device), " cuDevicePrimaryCtxRetain failed" );
9184 check_cu (cuDevicePrimaryCtxRelease (device), " cuDevicePrimaryCtxRelease failed" );
9285 });
9386 }
94- check_cu (
95- cuDevicePrimaryCtxRelease (device),
96- " cuDevicePrimaryCtxRelease (teardown) failed"
97- );
87+ check_cu (cuDevicePrimaryCtxRelease (device), " cuDevicePrimaryCtxRelease (teardown) failed" );
9888
9989 // Cleanup
10090 check_cu (cuCtxDestroy (ctx), " cuCtxDestroy failed" );
0 commit comments