CUDA Texture Memory Error: Unrecognized Texture_cuda

Source: Internet
Author: User


CUDA cannot recognize texture


Just began to learn cuda texture memory, from the Internet to find learning materials, but the test, the program is prompted error:


Texture<float, cudatexturetype2d, cudareadmodeelementtype> texref;

Output[y*width + x] = tex2d (Texref, TU, TV);


Texture,tex2d not recognized


The first thought was to find the definition of the function, which was defined in the Cuda_texture_types.h file, defined as

Template<class T, int textype = cudatexturetype1d, enum cudatexturereadmode mode = cudareadmodeelementtype> struct _                         _device_builtin_texture_type__ texture:public texturereference {#if!defined (__cudacc_rtc__) __host__ Texture (int
                   Norm = 0, enum Cudatexturefiltermode fmode = Cudafiltermodepoint,
    Enum Cudatextureaddressmode Amode = cudaaddressmodeclamp) {normalized = norm;
    FilterMode = Fmode;
    Addressmode[0] = Amode;
    ADDRESSMODE[1] = Amode;
    ADDRESSMODE[2] = Amode;
    Channeldesc = cudacreatechanneldesc<t> ();
  SRGB = 0;
                   } __host__ Texture (int norm, enum Cudatexturefiltermode Fmode,     Enum Cudatextureaddressmode amode, struct Cudachannelformatdesc desc) {Normalized
    = Norm;
    FilterMode = Fmode;
    Addressmode[0] = Amode;
    ADDRESSMODE[1] = Amode; AddressMODE[2] = Amode;
    CHANNELDESC = desc;
  SRGB = 0; #endif/*!__cudacc_rtc__ */};


, so the header file is included in the project, and the result is still out of the question.


After a variety of search and consultation, online can not find solutions, and finally thank friends to help solve this problem.


Now write down the solution


Should contain cpu_anim.h this header file,


namely #include "cpu_anim.h"


This file I also uploaded to the resources, the need for the basin friends can download


Here's an example of a texture that's been found elsewhere.


#include "cuda_runtime.h" #include "device_launch_parameters.h" #include <stdio.h> #include <stdlib.h> #
Include "Cuda_texture_types.h" #include <math.h> #include "cuda.h" #include "cpu_anim.h"//call texture must be added to this header file

#define SIZE 256 texture<float, cudatexturetype2d, cudareadmodeelementtype> texref; __global__ void Transformkernel (float* output, int width, int height, float theta) {unsigned int x = Blockidx.x*blockdim
	. x + threadidx.x;
	unsigned int y = blockidx.y*blockdim.y + threadidx.y;
	float u = x/(float) width;
	Float v = y/(float) height;
	U-= 0.5f;
	V-= 0.5f;
	Float tu = U*COSF (theta)-V*sin (theta) + 0.5f;
	Float TV = V*COSF (theta) + U*sinf (theta) + 0.5f;
Output[y*width + x] = tex2d (Texref, TU, TV);
	} void Main () {int width = 25;
	Cudachannelformatdesc Channeldesc = cudacreatechanneldesc (0, 0, 0, cudachannelformatkindfloat);
	Cudaarray*cuarray;
	Cudamallocarray (&cuarray, &channeldesc, width, height); Float*h_data = (float*) malloc (width*height*sizeof (float));
		for (int i = 0; i 



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.