MCPcopy Create free account
hub / github.com/NVIDIA/cuda-samples / test_gemm_loop

Function test_gemm_loop

cpp/4_CUDA_Libraries/batchCUBLAS/batchCUBLAS.cpp:395–621  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

393
394template <typename T_ELEM>
395int test_gemm_loop(struct gemmOpts &opts, float err, double max_relative_error, cublasHandle_t handle)
396{
397 struct gemmTestParams<T_ELEM> params;
398 cudaStream_t *streamArray = 0;
399 cublasStatus_t status1, status2, status3;
400 T_ELEM *A = NULL;
401 T_ELEM *B = NULL;
402 T_ELEM *C = NULL;
403 T_ELEM **devPtrA = 0;
404 T_ELEM **devPtrB = 0;
405 T_ELEM **devPtrC = 0;
406 T_ELEM **devPtrA_dev = NULL;
407 T_ELEM **devPtrB_dev = NULL;
408 T_ELEM **devPtrC_dev = NULL;
409 int matrixM, matrixN, matrixK;
410 int rowsA, rowsB, rowsC;
411 int colsA, colsB, colsC;
412 int matrixSizeA, matrixSizeB, matrixSizeC;
413 int errors;
414 double start, stop;
415
416 printf("Testing %cgemm\n", *opts.elem_type);
417
418 matrixM = (opts.m) ? opts.m : BENCH_MATRIX_M;
419 matrixN = (opts.n) ? opts.n : BENCH_MATRIX_N;
420 matrixK = (opts.k) ? opts.k : BENCH_MATRIX_K;
421
422 rowsA = imax(1, matrixM);
423 colsA = imax(1, matrixK);
424 rowsB = imax(1, matrixK);
425 colsB = imax(1, matrixN);
426 rowsC = imax(1, matrixM);
427 colsC = imax(1, matrixN);
428
429 matrixSizeA = rowsA * colsA;
430 matrixSizeB = rowsB * colsB;
431 matrixSizeC = rowsC * colsC;
432
433 devPtrA = (T_ELEM **)malloc(opts.N * sizeof(*devPtrA));
434 devPtrB = (T_ELEM **)malloc(opts.N * sizeof(*devPtrB));
435 devPtrC = (T_ELEM **)malloc(opts.N * sizeof(*devPtrC));
436
437 for (int i = 0; i < opts.N; i++) {
438 cudaError_t err1 = cudaMalloc((void **)&devPtrA[i], matrixSizeA * sizeof(devPtrA[0][0]));
439 cudaError_t err2 = cudaMalloc((void **)&devPtrB[i], matrixSizeB * sizeof(devPtrB[0][0]));
440 cudaError_t err3 = cudaMalloc((void **)&devPtrC[i], matrixSizeC * sizeof(devPtrC[0][0]));
441
442 if ((err1 != cudaSuccess) || (err2 != cudaSuccess) || (err3 != cudaSuccess)) {
443 CLEANUP();
444 fprintf(stderr, "!!!! GPU memory allocation error\n");
445 return CUBLASTEST_FAILED;
446 }
447 }
448
449 // For batched processing we need those arrays on the device
450 if (opts.test_method == tmBatched) {
451 cudaError_t err1 = cudaMalloc((void **)&devPtrA_dev, opts.N * sizeof(*devPtrA));
452 cudaError_t err2 = cudaMalloc((void **)&devPtrB_dev, opts.N * sizeof(*devPtrB));

Callers

nothing calls this directly

Calls 7

imaxFunction · 0.85
fillupMatrixDebugFunction · 0.85
fillupMatrixFunction · 0.85
cuEqualFunction · 0.85
cublasXgemmBatchedFunction · 0.85
cublasXgemmFunction · 0.85
secondFunction · 0.70

Tested by

no test coverage detected