Skip to content

Commit 5ff246a

Browse files
committed
tests:cuda: have ctest output SKIPPED when no device is available at
runtime
1 parent f6a46b9 commit 5ff246a

7 files changed

Lines changed: 36 additions & 30 deletions

File tree

tests/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ function(parsec_addtest_cmd target)
7070
# restrict memory use for oversubscribed runners
7171
set_tests_properties(${target} PROPERTIES ENVIRONMENT
7272
"PARSEC_MCA_device_cuda_enabled=0;PARSEC_MCA_device_hip_enabled=0;PARSEC_MCA_device_level_zero_enabled=0;PARSEC_MCA_device_cuda_memory_use=10;PARSEC_MCA_device_hip_memory_use=10;PARSEC_MCA_device_level_zero_memory_use=10")
73+
# skip tests that fail because the device is not available */
74+
set_tests_properties(${target} PROPERTIES SKIP_RETURN_CODE 10) # 10 is -PARSEC_ERR_DEVICE, positive 7bit return codes are more portable
7375
endfunction(parsec_addtest_cmd)
7476

7577
check_function_exists(erand48 PARSEC_HAVE_ERAND48)

tests/runtime/cuda/nvlink_main.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright (c) 2019-2020 The University of Tennessee and The University
2+
* Copyright (c) 2019-2024 The University of Tennessee and The University
33
* of Tennessee Research Foundation. All rights
44
* reserved.
55
*/
@@ -34,6 +34,14 @@ int main(int argc, char *argv[])
3434

3535
parsec = parsec_init(-1, &argc, &argv);
3636

37+
/* can the test run? */
38+
int nb_gpus = parsec_context_query(parsec, PARSEC_CONTEXT_QUERY_DEVICES, PARSEC_DEV_CUDA);
39+
assert(nb_gpus >= 0);
40+
if(nb_gpus == 0) {
41+
parsec_warning("This test can only run if at least one GPU device is present");
42+
exit(-PARSEC_ERR_DEVICE);
43+
}
44+
3745
tp = testing_nvlink_New(parsec, 10, 512);
3846
if( NULL != tp ) {
3947
parsec_context_add_taskpool(parsec, tp);

tests/runtime/cuda/nvlink_wrapper.c

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
21
/**
3-
* Copyright (c) 2019-2021 The University of Tennessee and The University
2+
* Copyright (c) 2019-2024 The University of Tennessee and The University
43
* of Tennessee Research Foundation. All rights
54
* reserved.
65
* Copyright (c) 2024 NVIDIA Corporation. All rights reserved.
@@ -104,10 +103,7 @@ parsec_taskpool_t* testing_nvlink_New( parsec_context_t *ctx, int depth, int mb
104103

105104
/** Find all CUDA devices */
106105
nb = parsec_context_query(ctx, PARSEC_CONTEXT_QUERY_DEVICES, PARSEC_DEV_CUDA);
107-
if(nb <= 0) {
108-
parsec_warning("ABORTED: This test requires at least one CUDA device per node (query returned %d)\n", nb);
109-
return NULL;
110-
}
106+
assert(nb >= 0);
111107
dev_index = (int*)malloc(nb * sizeof(int));
112108
nb = 0;
113109
for(dev = 0; dev < (int)parsec_nb_devices; dev++) {
@@ -147,7 +143,7 @@ parsec_taskpool_t* testing_nvlink_New( parsec_context_t *ctx, int depth, int mb
147143

148144
/* GEMM1 tasks will create one data copy per GPU, and work on those.
149145
* see nvlink.jdf:MAKE_C tasks */
150-
146+
151147
/* userM is a user-managed matrix: the user creates the data copies
152148
* only on the GPU they want the GEMM2 to run. To simplify the code,
153149
* we use parsec_matrix_block_cyclic that requires to also have a CPU data
@@ -199,14 +195,14 @@ parsec_taskpool_t* testing_nvlink_New( parsec_context_t *ctx, int depth, int mb
199195
g++;
200196
}
201197
}
202-
198+
203199
testing_handle = parsec_nvlink_new(dcA, userM, ctx->nb_nodes, CuHI, nb, dev_index);
204200

205201
parsec_add2arena( &testing_handle->arenas_datatypes[PARSEC_nvlink_DEFAULT_ADT_IDX],
206202
parsec_datatype_double_complex_t,
207203
PARSEC_MATRIX_FULL, 1, mb, mb, mb,
208204
PARSEC_ARENA_ALIGNMENT_SSE, -1 );
209-
205+
210206
return &testing_handle->super;
211207
}
212208

tests/runtime/cuda/stage_custom.jdf

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
extern "C" %{
22
/*
3-
* Copyright (c) 2019-2023 The University of Tennessee and The University
3+
* Copyright (c) 2019-2024 The University of Tennessee and The University
44
* of Tennessee Research Foundation. All rights
55
* reserved.
66
* Copyright (c) 2024 NVIDIA Corporation. All rights reserved.
@@ -162,7 +162,7 @@ BODY [type=CUDA
162162
lbeta, (double*)A, ldam );
163163
status = cublasGetError();
164164
PARSEC_CUDA_CHECK_ERROR( "cublasDgemm", status,
165-
{return -1;} );
165+
{return PARSEC_HOOK_RETURN_ERROR;} );
166166
}
167167
END
168168

@@ -203,7 +203,7 @@ BODY [type=CUDA
203203
lbeta, (double*)B, ldbm );
204204
status = cublasGetError();
205205
PARSEC_CUDA_CHECK_ERROR( "cublasDgemm", status,
206-
{return -1;} );
206+
{return PARSEC_HOOK_RETURN_ERROR;} );
207207

208208
}
209209
END
@@ -256,12 +256,6 @@ parsec_taskpool_t* testing_stage_custom_New( parsec_context_t *ctx, int M, int N
256256
int KP = 1;
257257
int KQ = 1;
258258

259-
int nb_gpus = parsec_context_query(ctx, PARSEC_CONTEXT_QUERY_DEVICES, PARSEC_DEV_CUDA);
260-
if(nb_gpus <= 0) {
261-
parsec_warning("ABORTED: This test can only run if at least one GPU device is present (query returned %d)\n", nb_gpus);
262-
return NULL;
263-
}
264-
265259
parsec_matrix_block_cyclic_t *descA;
266260
descA = (parsec_matrix_block_cyclic_t*)calloc(1, sizeof(parsec_matrix_block_cyclic_t));
267261
parsec_matrix_block_cyclic_init(descA, PARSEC_MATRIX_DOUBLE, PARSEC_MATRIX_TILE,

tests/runtime/cuda/stage_main.c

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ int main(int argc, char *argv[])
2121
int MB;
2222
int NB;
2323
int P = 1;
24-
int ret = EXIT_SUCCESS;
24+
int ret = 0;
2525

2626
#if defined(DISTRIBUTED)
2727
{
@@ -40,7 +40,15 @@ int main(int argc, char *argv[])
4040
exit(-1);
4141
}
4242

43+
/* can the test run? */
4344
assert(size == 1);
45+
int nb_gpus = parsec_context_query(parsec, PARSEC_CONTEXT_QUERY_DEVICES, PARSEC_DEV_CUDA);
46+
assert(nb_gpus >= 0);
47+
if(nb_gpus == 0) {
48+
parsec_warning("This test can only run if at least one GPU device is present");
49+
printf("TEST SKIPPED\n");
50+
exit(-PARSEC_ERR_DEVICE);
51+
}
4452

4553
/* Test: comparing results when:
4654
- tile matrix transfered to GPU with default stage_in/stage_out
@@ -86,9 +94,9 @@ int main(int argc, char *argv[])
8694
parsec_taskpool_free(tp);
8795
}
8896

89-
if(ret!= 0){
90-
printf("TEST FAILED\n");
91-
}else{
97+
if( ret != 0) {
98+
printf("TEST FAILED (%d errors)\n", ret);
99+
} else {
92100
printf("TEST PASSED\n");
93101
}
94102

@@ -97,5 +105,5 @@ int main(int argc, char *argv[])
97105
MPI_Finalize();
98106
#endif /* DISTRIBUTED */
99107

100-
return ret;
108+
return (0 == ret)? EXIT_SUCCESS: EXIT_FAILURE;
101109
}

tests/runtime/cuda/stress_wrapper.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,8 @@ parsec_taskpool_t* testing_stress_New( parsec_context_t *ctx, int depth, int mb
2929

3030
/** Find all CUDA devices */
3131
nb = parsec_context_query(ctx, PARSEC_CONTEXT_QUERY_DEVICES, PARSEC_DEV_CUDA);
32-
if(nb < 0) {
33-
parsec_fatal("parsec_context_query returned %d", nb);
34-
}
35-
else if(nb == 0) {
32+
assert(nb >= 0);
33+
if(nb == 0) {
3634
/* We just simulate a run on CPUs, with an arbitrary number of pseudo-GPUs */
3735
nb = 8;
3836
dev_index = (int*)malloc(nb * sizeof(int));

tests/runtime/cuda/testing_get_best_device.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ int main(int argc, char *argv[])
159159

160160
/* Check result */
161161
if( 0 == rank && info != 0 ) {
162-
fprintf(stderr, "Result is Wrong !!!\n");
162+
fprintf(stderr, "Result is Wrong (info %d) !!!\n", info);
163163
}
164164

165165
parsec_data_free(dcA.mat);
@@ -172,5 +172,5 @@ int main(int argc, char *argv[])
172172
MPI_Finalize();
173173
#endif
174174

175-
return info;
175+
return (0 == info)? EXIT_SUCCESS: EXIT_FAILURE;
176176
}

0 commit comments

Comments
 (0)