0

I am having trouble getting texture read to work using Cuda [4.2] on Windows.

My program reads a ptx file containing all the kernel modules. In addition the compilation process spits out an additional ptx file from a short routine of Host code. Here is the .cuh file and .cu file with host only code:

/////////////// "textureDefs.cuh"   file ///////////////////////////////////////////
#ifndef _TEXTUREDEFS_CUH
#define _TEXTUREDEFS_CUH
texture < float, cudaTextureType2D, cudaReadModeElementType> texRefEachRes_1;
texture <float, cudaTextureType2D, cudaReadModeElementType> texRefEachResPrev;
///////////////////////////////////////////////////////////////////////////////
///       myBind.cu
/////////////////////////////////////////////////

#include "cuda.h"
#include "textureDefs.cuh"
extern cudaPitchedPtr gYAllFramesForEachRes[ME_NUM_RES], gPrevYForEachRes[ME_NUM_RES];
//
extern "C"  cudaError_t bindTextures(int resNum)
{
    cudaChannelFormatDesc channelDesc = cudaCreateChannelDesc(32, 0, 0, 0, cudaChannelFormatKindFloat); // x is 32 bit float

    size_t offset;
    texRefEachResPrev.addressMode[0] = cudaAddressModeClamp;
    texRefEachResPrev.addressMode[1] = cudaAddressModeClamp;
    texRefEachResPrev.filterMode = cudaFilterModeLinear;
    texRefEachResPrev.normalized = false;
    cudaError_t err = cudaBindTexture2D(&offset, &texRefEachResPrev, 
            (unsigned char *)gPrevYForEachRes[resNum].ptr, &channelDesc, 
    gPrevYForEachRes[resNum].xsize, gPrevYForEachRes[resNum].ysize,   
           gPrevYForEachRes[resNum].pitch);  // jm bug 1/5
    return err;
}

every call to tex2d in my kernel code returns value 0 but i have checked and there is valid data in the array.

i am wondering if i need to also load myBind.ptx and if so how and when and where does it get loaded? or is this not needed?

thanks for your help.

JPM
  • 445
  • 1
  • 5
  • 15

1 Answers1

1

Before CUDA 5.0 all references to a texture need to be from within the same compilation unit, otherwise you will be dealing with separate textures that happen to have the same name but live in different namespaces.

Your options are either to include all .ptx code into a single file before compilation, or to upgrade to CUDA 5.0.

tera
  • 7,080
  • 1
  • 21
  • 32