因为电脑前些日子装了CUDA 5.0,发现运行以前含有cutil.h头文件的代码出问题了,百度了一下,说是5.0不再支持这些头文件了,现在该怎么办呢?
#include "cuda_runtime.h"
#include "device_launch_parameters.h"
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include "cutil_inline.h"
texture<float, 2, cudaReadModeElementType> texRef;
__global__ void transformKernel(float* output, int width, int height, float theta)
{
// Calculate normalized texture coordinates
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;
// Transform coordinates
u -= 0.5f;
v -= 0.5f;
float tu = u*cosf(theta)- v*sinf(theta) + 0.5f;
float tv = v*cosf(theta)+ u*sinf(theta) + 0.5f;
// Read from texture and write to global memory
output[y * width + x] = tex2D(texRef, tu, tv);
}
// Host code
int main()
{
float angle = 0.5f; // angle to rotate image by (in radians)
// load image from disk
float* h_data = NULL;
unsigned int width, height;
cutLoadPGMf("lena_bw.pgm", &h_data, &width, &height);
// Allocate CUDA array in device memory
cudaChannelFormatDesc channelDesc = cudaCreateChannelDesc(32, 0, 0, 0, cudaChannelFormatKindFloat);
cudaArray* cuArray;
cudaMallocArray(&cuArray, &channelDesc, width, height);
// Copy to device memory some data located at address h_data
// in host memory
unsigned int size = width * height * sizeof(float);
cudaMemcpyToArray(cuArray, 0, 0, h_data, size, cudaMemcpyHostToDevice);
// Set texture parameters
texRef.addressMode[0] = cudaAddressModeWrap;
texRef.addressMode[1] = cudaAddressModeWrap;
texRef.filterMode = cudaFilterModeLinear;
texRef.normalized = true;
// Bind the array to the texture reference
cudaBindTextureToArray(texRef, cuArray, channelDesc);
// Allocate result of transformation in device memory
float* output;
cudaMalloc(&output, width * height * sizeof(float));
// Invoke kernel
dim3 dimBlock(16, 16);
dim3 dimGrid(width / dimBlock.x, height / dimBlock.y);
transformKernel<<<dimGrid, dimBlock>>>(output, width, height, angle);
// Free device memory
cudaFreeArray(cuArray);
cudaFree(output);
}