MCPcopy Create free account
hub / github.com/ERGO-Code/HiGHS / main

Function main

check/cublas_example.cpp:19–76  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

17}
18
19int main(void) {
20 cudaError_t cudaStat;
21 cublasStatus_t stat;
22 cublasHandle_t handle;
23 int i, j;
24 float* devPtrA;
25 float* a = 0;
26 a = (float*)malloc(M * N * sizeof(*a));
27 if (!a) {
28 printf("host memory allocation failed");
29 return EXIT_FAILURE;
30 }
31 for (j = 0; j < N; j++) {
32 for (i = 0; i < M; i++) {
33 a[IDX2C(i, j, M)] = (float)(i * N + j + 1);
34 }
35 }
36 cudaStat = cudaMalloc((void**)&devPtrA, M * N * sizeof(*a));
37 if (cudaStat != cudaSuccess) {
38 printf("device memory allocation failed");
39 free(a);
40 return EXIT_FAILURE;
41 }
42 stat = cublasCreate(&handle);
43 if (stat != CUBLAS_STATUS_SUCCESS) {
44 printf("CUBLAS initialization failed\n");
45 free(a);
46 cudaFree(devPtrA);
47 return EXIT_FAILURE;
48 }
49 stat = cublasSetMatrix(M, N, sizeof(*a), a, M, devPtrA, M);
50 if (stat != CUBLAS_STATUS_SUCCESS) {
51 printf("data download failed");
52 free(a);
53 cudaFree(devPtrA);
54 cublasDestroy(handle);
55 return EXIT_FAILURE;
56 }
57 modify(handle, devPtrA, M, N, 1, 2, 16.0f, 12.0f);
58 stat = cublasGetMatrix(M, N, sizeof(*a), devPtrA, M, a, M);
59 if (stat != CUBLAS_STATUS_SUCCESS) {
60 printf("data upload failed");
61 free(a);
62 cudaFree(devPtrA);
63 cublasDestroy(handle);
64 return EXIT_FAILURE;
65 }
66 cudaFree(devPtrA);
67 cublasDestroy(handle);
68 for (j = 0; j < N; j++) {
69 for (i = 0; i < M; i++) {
70 printf("%7.0f", a[IDX2C(i, j, M)]);
71 }
72 printf("\n");
73 }
74 free(a);
75 return EXIT_SUCCESS;
76}

Callers

nothing calls this directly

Calls 1

modifyFunction · 0.85

Tested by

no test coverage detected