7 #include <curand_kernel.h>
8 #include <cuda_runtime.h>
18 int idx = blockIdx.x * blockDim.x + threadIdx.x;
24 curand_init(seed, idx, 0, &state);
27 double randomValue = curand_uniform(&state) - 0.5;
30 data[idx] = randomValue;
39 int threadsPerBlock = 256;
43 int blocksPerGrid = (rows + threadsPerBlock - 1) / threadsPerBlock;
47 unsigned long seed = time(NULL);
50 randomizeKernel<<<blocksPerGrid, threadsPerBlock>>>(d_data, rows, seed);
54 cudaDeviceSynchronize();
void randomize()
Randomize the vector elements with values between -0.5 and 0.5.
Defines the Vector class for GPU-accelerated vector operations.
__global__ void randomizeKernel(double *data, int rows, unsigned long seed)
CUDA kernel function that fills each element in the vector with a random value between -0....