Reputation: 5659
I have a 2D array allocated on GPU and I need to use the cuPy's nanargmax()
function to find the maximum value's index in each row. Some of the values could be NaN. Since the 2D array is quite large (here is in the sample, I have am showing a smaller one), I don't want to transfer it to the CPU and then use numpy's nanargmax()
(which is working but transfer to CPU takes long time).
Minimum Working Example:
import cupy as cp
import numpy as np
# Create a test array with a shape similar to (1250, 552)
# test_array should have some NaN values and some non-NaN values
test_array_gpu = cp.array(np.random.randn(1250, 552)) # Random values
# Set some values to NaN for testing purposes
test_array_gpu[200, 100] = cp.nan
test_array_gpu[500, 200] = cp.nan
test_array_gpu[1000, 300] = cp.nan
# Apply cp.nanargmax along axis=1 (find the index of the max element in each row ignoring NaNs)
best_fit_indices_gpu = cp.nanargmax(test_array_gpu, axis=1)
# Print the result
print("Best fit indices (indices of max values, ignoring NaNs):")
print(best_fit_indices_gpu)
--- JIT compile log for cupy_jitify_exercise --- --------------------------------------------------- cub/util_cpp_dialect.cuh(143): warning #161-D: unrecognized #pragma CUB_COMPILER_DEPRECATION_SOFT(C++14, C++11); ^
Remark: The warnings can be suppressed with "-diag-suppress "
cooperative_groups/details/helpers.h(454): error: identifier "cudaCGGetIntrinsicHandle" is undefined return (cudaCGGetIntrinsicHandle(cudaCGScopeMultiGrid)); ^
cooperative_groups/details/helpers.h(459): error: identifier "cudaCGSynchronize" is undefined cudaError_t err = cudaCGSynchronize(handle, 0); ^
cooperative_groups/details/helpers.h(465): error: identifier "cudaCGGetSize" is undefined cudaCGGetSize(&numThreads, NULL, handle); ^
cooperative_groups/details/helpers.h(472): error: identifier "cudaCGGetRank" is undefined cudaCGGetRank(&threadRank, NULL, handle); ^
cooperative_groups/details/helpers.h(479): error: identifier "cudaCGGetRank" is undefined cudaCGGetRank(NULL, &gridRank, handle); ^
cooperative_groups/details/helpers.h(486): error: identifier "cudaCGGetSize" is undefined cudaCGGetSize(NULL, &numGrids, handle); ^
6 errors detected in the compilation of "cupy_jitify_exercise".
Upvotes: 0
Views: 25