Click here to Skip to main content
15,868,141 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Dear all,
I want to create the random number in threads of kernel cudafy from 0-1 (similar ".NextDouble()" in C#) and from 0-18 (similar ".Next(0,18)" in c#). But I have no idea to create the generator CuRand, I already searched this matter but I don't see mention about it.
This is the first time I used Cudafy to GPU programming. Please help me and give me a simple example to do this.
Thank you so much!

What I have tried:

using System;
using Cudafy;
using Cudafy.Host;
using Cudafy.Translator;

using Cudafy.Maths.RAND;

namespace CudafyByExample
{
    public class RandomNumber 
    {
        const ulong a = 30000;
        const int b = 10;
        public static void Execute()
        {
            CudafyModule km = CudafyTranslator.Cudafy();
            GPGPU gpu = CudafyHost.GetDevice(CudafyModes.Target, CudafyModes.DeviceId);
            gpu.LoadModule(km);

            GPGPURAND gPGPURAND = GPGPURAND.Create(gpu, curandRngType.CURAND_RNG_PSEUDO_XORWOW);
            gPGPURAND.SetPseudoRandomGeneratorSeed(a);

            float[] r = new float[b];
            float[] d_r = gpu.Allocate<float>(r);
            gPGPURAND.GenerateUniform(d_r);
            gpu.CopyFromDevice(d_r, r);
            gpu.Free(d_r);
        }

        public static void random(float[] x)
        {
            Console.WriteLine(" element of array");
            for (int i = 0; i < x.Length; i++)
            {
                Console.WriteLine($"x[{i}] = {x[i]}");
            }
        }
    }
}


and I have the problem, technical detail:
System.DllNotFoundException: Unable to load DLL 'curand64_70': The specified module could not be found. (Exception from HRESULT: 0x8007007E)
   at Cudafy.Maths.RAND.CURANDDriver64.curandCreateGenerator(RandGenerator& generator, curandRngType rng_type)
   at Cudafy.Maths.RAND.CURANDDriver64.CreateGenerator(RandGenerator& generator, curandRngType rng_type) in C:\Users\CHAMP-12\Desktop\LBMCA_Cudafy2\Cudafy.Math\RAND\CURANDDriver.cs:line 245
   at Cudafy.Maths.RAND.CudaDeviceRAND..ctor(GPGPU gpu, curandRngType rng_type) in C:\Users\CHAMP-12\Desktop\LBMCA_Cudafy2\Cudafy.Math\RAND\CudaDeviceRAND.cs:line 34
   at Cudafy.Maths.RAND.GPGPURAND.Create(GPGPU gpu, curandRngType rng_type, Boolean host) in C:\Users\CHAMP-12\Desktop\LBMCA_Cudafy2\Cudafy.Math\RAND\GPGPURAND.cs:line 126
   at CudafyByExample.RandomNumber.Execute() in C:\Users\CHAMP-12\Desktop\LBMCA_Cudafy2\CudafyByExample\LBMCA\RandomNumber.cs:line 20
   at CudafyByExample.Program.Main(String[] args) in C:\Users\CHAMP-12\Desktop\LBMCA_Cudafy2\CudafyByExample\Program.cs:line 45


How to fix it? and after that I want to create 2D array random
Posted
Updated 21-Apr-20 22:03pm
v3

1 solution

You need to get a copy of the library that conatains CuRand: cuRAND :: CUDA Toolkit Documentation[^]
 
Share this answer
 
Comments
Văn Đợi Trương 22-Apr-20 4:09am    
excuse me sir, could you instruct to me the detail location of cuRand from ???? to ????
Richard MacCutchan 22-Apr-20 4:19am    
Follow the link above.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900