Hi,
I am trying to get CUDA.NET work together with textures. But no success for now. Here is the small test code. But it returns only zeros in the fout :(
C# code:
[codebox]using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using GASS.CUDA;
using GASS.CUDA.Types;
namespace CUDA_Texture
{
class Program
{
static void Main(string[] args)
{
CUDA cuda = new CUDA(0, true);
CUmodule module = cuda.LoadModule("texture.cubin");
CUfunction cf = cuda.GetModuleFunction(module, "testTexture");
CUtexref textRef = cuda.GetModuleTexture(module, "ttex");
int n = 32;
uint[] a = new uint[n];
for (int i = 0; i < n; i++)
{
a[i] = (uint)i;
}
CUdeviceptr d_a = cuda.CopyHostToDevice<uint>(a);
cuda.SetTextureAddressMode(textRef, 0, CUAddressMode.Clamp);
cuda.SetTextureFilterMode(textRef, CUFilterMode.Point);
cuda.SetTextureFormat(textRef, CUArrayFormat.UnsignedInt32, 1);
cuda.SetTextureFlags(textRef, CUDADriver.CU_TRSF_READ_AS_INTEGER);
cuda.SetTextureAddress(textRef, d_a, (uint)(n) * sizeof(uint));
uint[] fout = new uint[n];
CUdeviceptr d_out = cuda.Allocate<uint>(fout);
cuda.SetFunctionBlockShape(cf, n, 1, 1);
cuda.SetParameter(cf, 0, d_out.Pointer);
cuda.SetParameterSize(cf, sizeof(uint));
cuda.Launch(cf, 1, 1);
cuda.CopyDeviceToHost<uint>(d_out, fout);
}
}
}[/codebox]
C kernel (compiled into ‘texture.cubin’)
[codebox]typedef unsigned int uint;
texture<unsigned int, 1, cudaReadModeElementType> ttex;
extern “C”
global void testTexture(uint* out)
{
uint index = threadIdx.x;
int i = (int)index;
out[index] = tex1Dfetch(ttex, i);
}[/codebox]
Anybody could help me?
Thanks
EDIT: I am usung CUDA 2.2, CUDA.NET 2.0, GeForce 9800GTX, WinXP, VS2008