Allocate persistent memory

I am trying to set the simulation parameters in read only memory, but without luck (CUDA.NET). The cudaMemcpyToSymbol function returns cudaErrorInvalidSymbol. The first parameter in cudaMemcpyToSymbol is the string ... Is this the name of the character? In fact, I do not understand how this can be solved. Any help was appreciated.

//init, load .cubin float[] arr = new float[1]; arr[0] = 0.0f; int size = Marshal.SizeOf(arr[0]) * arr.Length; IntPtr ptr = Marshal.AllocHGlobal(size); Marshal.Copy(arr, 0, ptr, arr.Length); var error = CUDARuntime.cudaMemcpyToSymbol("param", ptr, 4, 0, cudaMemcpyKind.cudaMemcpyHostToDevice); 

My .cu file contains

 __constant__ float param; 

Working solution

  cuda.LoadModule(Path.Combine(Environment.CurrentDirectory, "name.cubin")); simParams = cuda.GetModuleGlobal("params"); float[] parameters = new float[N]{...} cuda.CopyHostToDevice<float>(simParams, parameters); 
+4
source share
3 answers

Unfortunately, __ constant __ must be in the same file size as memcpy, and in your case, your __ constant __ is in a separate .cu file.

An easy way to solve this problem is to provide a wrapper function in your .cu file, for example:

 __constant__ float param; // Host function to set the constant void setParam(float value) { cudaMemcpyToSymbol("param", ptr, 4, 0, cudaMemcpyHostToDevice); } // etc. __global__ void ... 
+3
source

read-only memory has a hidden local connection. make sure the ad is in the same file where you use it. It looks like you have two files. can also declare param array (or maybe not)

+1
source

If this question is relevant, you can use cuModuleGetGlobal and the following cudaMemcpy as follows:

 private bool setValueToSymbol(CUmodule module, string symbol, int value) { CUdeviceptr devPtr = new CUdeviceptr(); uint lenBytes = 0; CUResult result = CUDADriver.cuModuleGetGlobal(ref devPtr, ref lenBytes, module, symbol); if (result == CUResult.Success) { int[] src = new int[] { value }; cudaError error = CUDARuntime.cudaMemcpy(devPtr, src, lenBytes, cudaMemcpyKind.cudaMemcpyHostToDevice); if (error == cudaError.cudaSuccess) return true; else return false; } else { return false; } } 

where module CUmodule = cuda.LoadModule ("MyCode.cubin"); This code works with NVIDIA GPU Computing SDK 3.1 and CUDA.NET 3.0.

+1
source

Source: https://habr.com/ru/post/1304204/


All Articles