how to use curand with CURAND_RNG_QUASI_SOBOL32 option?

this is my first time to use curand libs, I find that the help doc give an example for CURAND_RNG_PSEUDO_DEFAULT option.
but when I change it to CURAND_RNG_QUASI_SOBOL32, error appeared. below is my code:

error happened in calling “curandGenerate”, any suggestions?

size_t n = number;
    size_t i;
    curandGenerator_t gen;
    uint *devData, *hostData;

    /* Allocate n floats on host */
    hostData = (uint *)calloc(n, sizeof(uint));

    /* Allocate n floats on device */
    CUDA_CALL(cudaMalloc((void **)&devData, n*sizeof(uint)));

    /* Create pseudo-random number generator */
    //CURAND_CALL(curandCreateGenerator(&gen, CURAND_RNG_PSEUDO_DEFAULT));
    CURAND_CALL(curandCreateGenerator(&gen, CURAND_RNG_QUASI_SOBOL32));

    /* Set seed */
    //CURAND_CALL(curandSetPseudoRandomGeneratorSeed(gen, 1234ULL));
    CURAND_CALL(curandSetQuasiRandomGeneratorDimensions(gen, 10));

    /* Generate n int on device */
    CURAND_CALL(curandGenerate(gen, devData, n));

    /* Copy device memory to host */
    CUDA_CALL(cudaMemcpy(hostData, devData, n * sizeof(uint), cudaMemcpyDeviceToHost));

    /* Show result */
    for(i = 0; i < n; i++) {
        printf("%u, ", (hostData[i]));
        randArray.push_back(hostData[i]);
    }
    printf("\n");

there is no more error info, but
Error at xxx.cpp:148 -> here I call ‘curandGenerate’
Segmentation fault (core dumped)

Your code appears to work without a seg fault for me. Note that the choice of n matters, which you haven’t shown.

$ cat t1550.cu
#include <curand.h>
#define CUDA_CALL(x) x
#define CURAND_CALL(x) x
#include <stdio.h>

int main(){

    size_t n = 100;
    size_t i;
    curandGenerator_t gen;
    uint *devData, *hostData;

    /* Allocate n floats on host */
    hostData = (uint *)calloc(n, sizeof(uint));

    /* Allocate n floats on device */
    CUDA_CALL(cudaMalloc((void **)&devData, n*sizeof(uint)));

    /* Create pseudo-random number generator */
    //CURAND_CALL(curandCreateGenerator(&gen, CURAND_RNG_PSEUDO_DEFAULT));
    CURAND_CALL(curandCreateGenerator(&gen, CURAND_RNG_QUASI_SOBOL32));

    /* Set seed */
    //CURAND_CALL(curandSetPseudoRandomGeneratorSeed(gen, 1234ULL));
    CURAND_CALL(curandSetQuasiRandomGeneratorDimensions(gen, 10));

    /* Generate n int on device */
    CURAND_CALL(curandGenerate(gen, devData, n));

    /* Copy device memory to host */
    CUDA_CALL(cudaMemcpy(hostData, devData, n * sizeof(uint), cudaMemcpyDeviceToHost));

    /* Show result */
    for(i = 0; i < n; i++) {
        printf("%u, ", (hostData[i]));
        //randArray.push_back(hostData[i]);
    }
    printf("\n");
}
$ nvcc -o t1550 t1550.cu -lcurand
$ cuda-memcheck ./t1550
========= CUDA-MEMCHECK
0, 2147483648, 3221225472, 1073741824, 1610612736, 3758096384, 2684354560, 536870912, 805306368, 2952790016, 0, 2147483648, 1073741824, 3221225472, 1610612736, 3758096384, 536870912, 2684354560, 1342177280, 3489660928, 0, 2147483648, 1073741824, 3221225472, 2684354560, 536870912, 3758096384, 1610612736, 4026531840, 1879048192, 0, 2147483648, 1073741824, 3221225472, 3758096384, 1610612736, 2684354560, 536870912, 1879048192, 4026531840, 0, 2147483648, 3221225472, 1073741824, 1610612736, 3758096384, 2684354560, 536870912, 2415919104, 268435456, 0, 2147483648, 3221225472, 1073741824, 536870912, 2684354560, 3758096384, 1610612736, 1342177280, 3489660928, 0, 2147483648, 1073741824, 3221225472, 1610612736, 3758096384, 536870912, 2684354560, 1879048192, 4026531840, 0, 2147483648, 3221225472, 1073741824, 3758096384, 1610612736, 536870912, 2684354560, 4026531840, 1879048192, 0, 2147483648, 3221225472, 1073741824, 3758096384, 1610612736, 536870912, 2684354560, 4026531840, 1879048192, 0, 2147483648, 3221225472, 1073741824, 2684354560, 536870912, 1610612736, 3758096384, 1342177280, 3489660928,
========= ERROR SUMMARY: 0 errors
$

Is there any requirement to set the value of ‘n’?
I guess that the root cause of my problem is that the value of ‘n’ is not a multiple of 10.
The issue disappeared when I update the value of ‘n’ from 34 to 40.

Yes, its covered in the curand docs. It has to be a multiple of the dimension

https://docs.nvidia.com/cuda/curand/host-api-overview.html#order

"32 and 64 bit SOBOL and Scrambled SOBOL quasirandom generators

CURAND_ORDERING_QUASI_DEFAULT

When generating n results in d dimensions, the output will consist of n / d results from dimension 1, followed by n / d results from dimension 2, and so on up to dimension d . Only exact multiples of the dimension size may be generated. The dimension parameter d is set with curandSetQuasiRandomGeneratorDimensions() and defaults to 1."

ok, got it, thanks for your reply!