@@ -22,9 +22,6 @@ static void check_cu(CUresult status, const char* message) {
2222
2323int main (int argc, char ** argv) {
2424 bench::Options options = bench::parse_args (argc, argv);
25- if (options.benchmark_name .empty ()) {
26- options.benchmark_name = " ctx_device.ctx_get_current" ;
27- }
2825
2926 // Setup: init CUDA and create a context
3027 check_cu (cuInit (0 ), " cuInit failed" );
@@ -36,30 +33,55 @@ int main(int argc, char** argv) {
3633 CUctxCreateParams ctxParams = {};
3734 check_cu (cuCtxCreate (&ctx, &ctxParams, 0 , device), " cuCtxCreate failed" );
3835
39- CUcontext current_ctx = nullptr ;
36+ bench::BenchmarkSuite suite (options) ;
4037
41- // Run benchmark
42- auto results = bench::run_benchmark (options, [&]() {
43- check_cu (
44- cuCtxGetCurrent (¤t_ctx),
45- " cuCtxGetCurrent failed"
46- );
47- });
38+ // --- ctx_get_current ---
39+ {
40+ CUcontext current_ctx = nullptr ;
41+ suite. run ( " ctx_device.ctx_get_current " , [&]() {
42+ check_cu ( cuCtxGetCurrent (¤t_ctx), " cuCtxGetCurrent failed" );
43+ } );
44+ }
4845
49- // Sanity check: the call actually returned our context
50- if (current_ctx != ctx) {
51- std::cerr << " unexpected: cuCtxGetCurrent returned a different context\n " ;
46+ // --- ctx_set_current ---
47+ {
48+ suite.run (" ctx_device.ctx_set_current" , [&]() {
49+ check_cu (cuCtxSetCurrent (ctx), " cuCtxSetCurrent failed" );
50+ });
5251 }
5352
54- // Cleanup
55- check_cu (cuCtxDestroy (ctx), " cuCtxDestroy failed" );
53+ // --- ctx_get_device ---
54+ {
55+ CUdevice dev;
56+ suite.run (" ctx_device.ctx_get_device" , [&]() {
57+ check_cu (cuCtxGetDevice (&dev), " cuCtxGetDevice failed" );
58+ });
59+ }
5660
57- // Output
58- bench::print_summary (options.benchmark_name , results);
61+ // --- device_get ---
62+ {
63+ CUdevice dev;
64+ suite.run (" ctx_device.device_get" , [&]() {
65+ check_cu (cuDeviceGet (&dev, 0 ), " cuDeviceGet failed" );
66+ });
67+ }
5968
60- if (!options.output_path .empty ()) {
61- bench::write_pyperf_json (options.output_path , options.benchmark_name , options.loops , results);
69+ // --- device_get_attribute ---
70+ {
71+ int value = 0 ;
72+ suite.run (" ctx_device.device_get_attribute" , [&]() {
73+ check_cu (
74+ cuDeviceGetAttribute (&value, CU_DEVICE_ATTRIBUTE_COMPUTE_CAPABILITY_MAJOR, device),
75+ " cuDeviceGetAttribute failed"
76+ );
77+ });
6278 }
6379
80+ // Cleanup
81+ check_cu (cuCtxDestroy (ctx), " cuCtxDestroy failed" );
82+
83+ // Write all results
84+ suite.write ();
85+
6486 return 0 ;
6587}
0 commit comments