Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8059107
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T09:34:06+00:00 2026-06-05T09:34:06+00:00

Here, I have two different version of my code. The first one is a

  • 0

Here, I have two different version of my code.

The first one is a complete CUDA program that from CUDA SDK. In kernel, tex3D works well.

The second version is more complex with many OpenGL functions and OpenGL textures. Its .cu file is same as the first one. However, I use a cudaMalloc variable to get the value from tex3D in the same kernel function, I found the tex3D function returns nothing. Actually, two program use the same way to create 3D texture as the code below:

#define  SIZE_X 128 //numbers in elements
#define  SIZE_Y 128
#define  SIZE_Z 128
typedef float  VolumeType;
cudaExtent volumeSize = make_cudaExtent(SIZE_X, SIZE_Y, SIZE_Z); 

cudaArray *d_volumeArray = 0; //for tex
cudaArray *d_transferFuncArray; //for transferTex

texture<VolumeType, 3, cudaReadModeElementType> tex;         // 3D texture
texture<float4, 1, cudaReadModeElementType> transferTex; // 1D transfer function texture

//initialize the 3d texture "tex" with a 3D array "d_volumeArray"
cudaChannelFormatDesc channelDesc = cudaCreateChannelDesc<VolumeType>();
cutilSafeCall( cudaMalloc3DArray(&d_volumeArray, &channelDesc, volumeSize) ); 

// set texture parameters
tex.normalized = true;                      // access with normalized texture coordinates
tex.filterMode = cudaFilterModeLinear;      // linear interpolation
tex.addressMode[0] = cudaAddressModeClamp;  // clamp texture coordinates
tex.addressMode[1] = cudaAddressModeClamp;
CUDA_SAFE_CALL(cudaBindTextureToArray(tex, d_volumeArray, channelDesc));// bind array to 3D texture

//get the real value for 3D texture "tex"
float *d_volumeMem;
cutilSafeCall(cudaMalloc((void**)&d_volumeMem, SIZE_X*SIZE_Y*SIZE_Z*sizeof(float)));

.....//assign value to d_volumeMem in GPU. I've already checked the d_volumeMem is valid

//copy d_volumeMem to 3DArray
cudaMemcpy3DParms copyParams = {0};
copyParams.srcPtr = make_cudaPitchedPtr((void*)d_volumeMem, SIZE_X*sizeof(VolumeType),   SIZE_X, SIZE_Y); 
copyParams.dstArray = d_volumeArray;
copyParams.extent = volumeSize;
copyParams.kin = cudaMemcpyDeviceToDevice;
cutilSafeCall( cudaMemcpy3D(&copyParams) ); 

Code below is the kernel function calling the tex3D. Actually, it’s just the same as the CUDA SDK volumeRender’s kernel, that is a implementation of ray-casting.

__global__ void d_render(....)
{
 ......//ray-casting progress

 float temp = tex3D(tex, pos1, pos2, pos3); 
 //pos1 pos2 pos3 is valid
 //Here actually I use a cudaMalloc variable "s" to store the temp
 //In the first version, s has different value for different position
 //In the second version, temp is 0 all the time

......//ray-casting progress
}

I think these code are good because most of them are from the CUDA SDK volumeRender and work well in my first version code.

But I have no idea why in the second version tex3D is suddenly invalid. Maybe some other OpenGL textures has some negative effects?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T09:34:08+00:00Added an answer on June 5, 2026 at 9:34 am

    Actually, the problem is that I do the bind-texture-stuff before choose CUDA device. So, calling the cudaChooseDevice and cudaSetGLDevice first will make things work well!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have two dropdown list. first drop down:1 enter code here <form:select path=custName id=custName>
I have some Scala code that does something nifty with two different versions of
I have a function that I use on two different machine one a Mac
What is the issue with this code? Here we have two files: classA.h and
here is what my code looks like i have two forms: class Form_1 extends
I have two iterators which i have to merge into one result. Here are
Here are two different pieces of code This is what I started with Vector2
I have two data structure classes (this is a simplified version of my code)
The following pseudo-code is from the first chapter of an online preview version of
I have two tables: entitytype and project . Here are the create table statements:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.