Hi,
I’m trying to get the maximum of a matrix. But using cublasIsamax() I get an error. Here is my code:
/* Includes, system */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/* Includes, cuda */
#include "cublas.h"
/* Matrix size */
#define N (4)
/* Main */
int main(int argc, char** argv)
{
cublasStatus status;
float* x;
float ind;
int n2 = N * N;
int i;
int incx;
/* Initialize CUBLAS */
printf("simpleCUBLAS test running..\n");
status = cublasInit();
if (status != CUBLAS_STATUS_SUCCESS) {
fprintf (stderr, "!!!! CUBLAS initialization error\n");
return EXIT_FAILURE;
}
/* Index of maximum*/
x = (float*)malloc(n2 * sizeof(float));
/* Fill the matrices with test data */
for (i = 0; i < n2; i++)
x[i] = (float) i;
incx =1;
ind = cublasIsamax (n2, x, incx);
status= cublasGetError();
if (status != CUBLAS_STATUS_SUCCESS) {
fprintf (stderr, "!!!! CUBLAS error\n");
return EXIT_FAILURE;
}
printf ("\n Index is %d\n", ind);
/* Memory clean up */
free(x);
/* Shutdown */
status = cublasShutdown();
if (status != CUBLAS_STATUS_SUCCESS) {
fprintf (stderr, "!!!! shutdown error (A)\n");
return EXIT_FAILURE;
}
if (argc > 1) {
if (!strcmp(argv[1], "-noprompt") ||
!strcmp(argv[1], "-qatest") )
{
return EXIT_SUCCESS;
}
}
else
{
printf("\nPress ENTER to exit...\n");
getchar();
}
return EXIT_SUCCESS;
}
I get “CUDA error”, but I printed the matrix and it was ok.
Thanks in advance.