Hi,
I’m trting to bind a pointer in my device global memory to a texture memory so i can do 2D interpolation. However, when i load from the texture memory, everything is zero.
here is my code.
#include <cuda_runtime.h>
#include "device_launch_parameters.h"
#include <stdio.h>
#include "cuda.h"
texture<float, 2, cudaReadModeElementType> tex;
#define gpuErrchk(ans) { gpuAssert((ans), __FILE__, __LINE__); }
inline void gpuAssert(cudaError_t code, const char* file, int line, bool abort = true)
{
if (code != cudaSuccess)
{
fprintf(stderr, "GPUassert: %s %s %d\n", cudaGetErrorString(code), file, line);
if (abort) exit(code);
}
}
__global__ void kernel_ArrivalTimeCalculation(float* Device_ConvArrivalTime) {
int TID = threadIdx.y * blockDim.x + threadIdx.x;
int BlockOFFset = blockDim.x * blockDim.y * blockIdx.x;
int GID_RowBased = BlockOFFset + TID;
int RowOFFset = blockDim.x * blockDim.y * gridDim.x * blockIdx.y;
int GID = RowOFFset + BlockOFFset + TID;
Device_ConvArrivalTime[GID_RowBased] = (float)(GID/2);
}
__global__ void kernel_ArrivalTimeCalculation_Show() {
int TID = threadIdx.y * blockDim.x + threadIdx.x;
int BlockOFFset = blockDim.x * blockDim.y * blockIdx.x;
int GID_RowBased = BlockOFFset + TID;
int Px_man = (GID_RowBased) % (256);
int Pz_man = (GID_RowBased) / (256);
float value;
value = tex2D(tex, (float)(Px_man/3.0), (float)(Pz_man/3.0) );
printf("The value in the texture memory: %.6f \n", value);
}
int main()
{
float* Device_ConvArrivalTime; // Device pointer
int m = 512*96;
int n = 256;
size_t pitch, tex_ofs;
gpuErrchk(cudaMallocPitch((void**)&Device_ConvArrivalTime, &pitch, n * sizeof(float), m));
tex.normalized = false;
tex.filterMode = cudaFilterModeLinear;
gpuErrchk(cudaBindTexture2D(&tex_ofs, &tex, Device_ConvArrivalTime, &tex.channelDesc, n, m, pitch));
dim3 block(1024, 1);
dim3 grid((m * n / block.x), 1);
kernel_ArrivalTimeCalculation << <grid, block>> > (Device_ConvArrivalTime);
cudaDeviceSynchronize();
kernel_ArrivalTimeCalculation_Show << <1, 256>> > ();
cudaDeviceSynchronize();
gpuErrchk(cudaFree(Device_ConvArrivalTime));
cudaDeviceReset();
return 0;}
So, the problem is that i get 0 printed. what could be wrong here?
Moein.