Hi. You can directly access the max value using a cudaMemcpy to a single value.
Suppose you have a device array devArray of array size arraySize and want to store the maximum value in the host memory variable max. You will also need an int variable to get the max value index: maxIndex.
// Host variable that will store the maximum value.
// Array maximum index (in FORTRAN base).
// Call cublas to get maxIndex: note that maxIndex is passed as a pointer to the cublas call.
cublasIdamax(cublasHandle, arraySize, devArray, 1, &maxIndex);
// Copy max value onto host variable: variable must be passed as pointer.
// We offset our array by the index returned by cublas. It is important to notice that
// we must reduce also by one since this is FORTRAN based indexing.
cudaMemcpy(&max, devArray+maxIndex-1, sizeof(double), cudaMemcpyDeviceToHost);
// We are not done yet, since the value may be negative.
max = (max >= 0) ? max : -max;
printf("Absolute maximum value of array is %lf.\n", max);
I hope this proves useful.