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 7893725
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T07:12:25+00:00 2026-06-03T07:12:25+00:00

I’ve got a problem with cudaBindTexture2D. Following code I created to reproduce this issue,

  • 0

I’ve got a problem with cudaBindTexture2D. Following code I created to reproduce this issue, but this one… works:

#include "cuda.h"
#include <stdio.h>

// This will output the proper CUDA error strings in the event that a CUDA host call returns an error
#define checkCudaErrors(err)  __checkCudaErrors (err, __FILE__, __LINE__)

inline void __checkCudaErrors(cudaError err, const char *file, const int line )
{
    if(cudaSuccess != err)
    {
        fprintf(stderr, "%s(%i) : CUDA Runtime API error %d: %s.\n",file, line, (int)err, cudaGetErrorString( err ) );
        exit(-1);        
    }
}

texture<float,2> myTex;

int main(int argc, char* argv[])
{
    float* input;
    input = new float[656 * 480];
    for(int i = 0; i < 656*480; ++i)
    {
        input[i] = i;
    }
    float* inputDevice;
    checkCudaErrors(cudaMalloc ((void**)&inputDevice, 656 * 480 * sizeof(float) ));
    checkCudaErrors(cudaMemcpy(inputDevice, input, 656 * 480 * sizeof(float), cudaMemcpyHostToDevice));

    cudaChannelFormatDesc desc = cudaCreateChannelDesc<float>();

    checkCudaErrors(cudaBindTexture2D(0, myTex, inputDevice, desc, 656, 480, sizeof(float) * 656));

    cudaUnbindTexture(myTex);
    cudaFree(inputDevice);

    return 0;
}

But in my real project, the presumably same code ain’t working.

texture<float,2> texInput;

/* a lot of code here, but nothing with texInput */

    void CUDAConv::DoConvolution(float* input, float* kernel1D, float* resultMap, unsigned char* rMap, unsigned char* orientMap, int width, int height, int kernelSize)
    {
        int fDim = (int)(floor((sqrt((float)(width * width + height * height)) / 2 + 0.5f)));
        //Lock* locks = new Lock[width * height];
        int dim = fDim * 2 + 1;
        devWidth = width;
        devHeight = height;

        // allocate memory on GPU for the summing images
        checkCudaErrors(cudaMalloc((void**)&inputDevice, width * height * sizeof(float)));

        checkCudaErrors(cudaMemcpy(inputDevice, input, width * height * sizeof(float), cudaMemcpyHostToDevice));

        cudaChannelFormatDesc desc = cudaCreateChannelDesc<float>();
        checkCudaErrors(cudaMalloc((void**)&kernel1DDevice, kernelSize));

        checkCudaErrors(cudaBindTexture2D(0, texInput, inputDevice, desc, width, height, sizeof(float) * width));

        checkCudaErrors(cudaMalloc((void**)&radiusDevice, width * height));
        checkCudaErrors(cudaMalloc((void**)&orientationDevice, width * height));
        checkCudaErrors(cudaMalloc((void**)&resultDevice, width * height * sizeof(float)));
        checkCudaErrors(cudaMemset(resultDevice, 0x00, width * height * sizeof(float)));
        checkCudaErrors(cudaMemcpy(kernel1DDevice, kernel1D, kernelSize * sizeof(float), cudaMemcpyHostToDevice));
        for(int i = 0; i < angles; ++i)
        {
            checkCudaErrors(cudaMalloc((void**)&sumUpImage[i], angles * width * height * sizeof(float)));
            checkCudaErrors(cudaMemset(&sumUpImage[i], 0x00, width * height * angles * sizeof(float)));
            checkCudaErrors(cudaMalloc((void**)&rotationImage[i], angles * dim * dim * sizeof(float)));
            checkCudaErrors(cudaMemset(&rotationImage[i], 0x00, dim * dim * angles * sizeof(float)));
        }

        // do all convolution calculations in the Convolution function
        convolution <<<1, angles>>> (/*locks, */inputDevice, kernel1DDevice, rotationImage, sumUpImage, resultDevice, radiusDevice, orientationDevice, devWidth, devHeight, angles);

        checkCudaErrors(cudaMemcpy(resultMap, resultDevice, width * height * sizeof(float), cudaMemcpyDeviceToHost));

        // free memory allocated on the GPU
        for(int i = 0; i < angles; ++i)
        {
            checkCudaErrors(cudaFree(sumUpImage[i]));
        }

        //free(locks);
        cudaUnbindTexture(texInput);
        cudaFree(inputDevice);
        cudaFree(kernel1DDevice);
        cudaFree(radiusDevice);
        cudaFree(orientationDevice);
        cudaFree(resultDevice);
    }

The error I would get consequently on cudaBindTexture2D is:

CUDA_Conv.cu(203) : CUDA Runtime API error 18: invalid texture reference.

When debugging the texInput looks just like myTex, and I can’t figure out what’s happening here.

Using CUDA4.2 with VS2010.

  • 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-03T07:12:26+00:00Added an answer on June 3, 2026 at 7:12 am

    The answer was in the comments, I used a sm that my GPU wasn’t compatible to, strangely enough it wouldn’t throw the error on cudaMalloc, but only on cudaBindTexture, but setting both the same sm / arch, and they behaved the same.

    Thanks Roger!

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

Sidebar

Related Questions

I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I want to count how many characters a certain string has in PHP, but
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I've got a string that has curly quotes in it. I'd like to replace
this is what i have right now Drawing an RSS feed into the php,

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.