cuSPARSE segfault for device side constants

I am getting a seg fault when swapping out a host side constant for a device side constant in cuBLAS and cuSPARSE routines such as cusparseAxpby (see cuSPARSE). This routine takes a constant parameter alpha for the operation Y = alpha * X + beta * Y with alpha being either HOST or DEVICE memory. This works fine when I use a host side constant, like

double alpha = 1.0;
double beta = 1.0;
cusparseAxpby(handle, &alpha,  devX, &beta, devY);

but seg faults when I do

double *devalpha;
cudaMalloc((void**)&devalpha, sizeof(double));
cusparseAxpby(handle, devalpha,  devX, &beta, devY);

This is straight from the examples repo (see cuSPARSE examples).

The function signature is

cusparseAxpby(cusparseHandle_t          handle,
              const void*               alpha,
              cusparseConstSpVecDescr_t vecX,  // non-const descriptor supported
              const void*               beta,
              cusparseDnVecDescr_t      vecY)

Unfortunately I can’t do any stack track or run cuda-gdb as I’m developing on Windows work computer running WSL2.


You need to set the Pointer mode to Device mode:
Pointer mode enums:
Note that both alpha and beta have to be on the same memory (HOST or DEVICE).