OpenGL Error

Hi Im using 9800GT on windows platform, using Visual studios for coding. Im trying to use OpenGL to increase my display rate but there has been a problem on the pixel buffer. Following is my code.

void createVBO(GLuint* pixel_buffer, struct cudaGraphicsResource **cuda_pixel_resource){

if(pixel_buffer){ // create buffer object

glGenBuffers(1, pixel_buffer);

glBindBuffer(GL_ARRAY_BUFFER, *pixel_buffer); //register buffer on cuda

unsigned int size = XDIM * YDIM * 4 * sizeof(float);

glBufferData(GL_ARRAY_BUFFER, size, 0, GL_DYNAMIC_DRAW);

glBindBuffer(GL_ARRAY_BUFFER, 0);

CUT_CHECK_ERROR(cudaGraphicsGLRegisterBuffer(cuda_pixel_resource,

*pixel_buffer, cudaGraphicsMapFlagsWriteDiscard)); }

else{ cutilSafeCall( cudaMalloc( (void **)&d_vbo_buffer, XDIMYDIM4*sizeof(float) ) ); }}

int main(int argc, char *argv) {

// Pre-Calculation

readData();

convertor(); //convert values into single float

calc_resample_coefficients();

// Explicitly set device

glutInit(&argc, argv);

glewInit();

int device;

cudaGLGetDevice(&device)

cudaGLSetGLDevice(device);

glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE);

glutInitWindowSize(window_width, window_height);

glutCreateWindow(“Cuda GL Interop (VBO)”);

glutDisplayFunc(display); // Create buffer object and register it with CUDA

createVBO(&pbo, &cuda_pbo_resource); // Loop

glutMainLoop();

deleteVBO();

cudaThreadExit();}

Im having some error saying

CUDA error: in file ‘my file path …’ in line 131: device kernel image is invalid.

Did somebody have similar problem before? Can someone help me? Thank you

Line 131 is CUT_CHECK_ERROR(cudaGraphicsGLRegisterBuffer(cuda_pixel_resource, *pixel_buffer, cudaGraphicsMapFlagsWriteDiscard));

Oh by the way my code does not have any rendering stuffs as in simpleGL. Do I need it? Can somebody help me out with how to start rendering? I have no clue of what is going on with that part. Thanks

And when I check cudaGraphicsMapResource in code bellow it the command window throws

.\Resampling_GL.cpp<143> : cudaSafeCall<> Runtime API error: invalid resource handle. Does this ring a bell? Thanks

Following is my code:

// includes, system

#include <stdlib.h>

#include <stdio.h>

#include <string.h>

// includes, GL

#include <GL/glew.h>

#include <GL/glu.h>

//#include <GL/freeglut.h>

#include <GL/glut.h>

// includes CUDA <--> C++ interlops 

#include <cuda_runtime.h>

#include <cutil_inline.h>

#include <cutil_gl_inline.h>

#include <cutil_gl_error.h>

#include <cuda_gl_interop.h>

//define variables

#define XDIM 1000 //original value 1000

#define YDIM 1024 //original value 1024

#define FRAMES 20

#define START_WAVELENGTH 7.5226E+02

#define WAVELENGTH_SPACING 8.6969E-02	

#define SECOND_ORDER_CORRECTION -4.2264E-06

#define THIRD_ORDER_CORRECTION 8.9511E-10

#define FOURTH_ORDER_CORRECTION -1.7987E-13

#define LINE_LENGTH 1024	//Note same as YDIM, should be fixed

#define CAPTURE_LINE_OFFSET 800

#define RESAMPLE_POINTS 1024

// variables into cuda

unsigned char a[XDIM*XDIM*YDIM];

float resamp_1D[LINE_LENGTH*2], original_cpu[FRAMES*XDIM*YDIM], *dev_original;

float k_resampledspacing;

cuComplex d_in[YDIM*XDIM];

float dc_subtracted[YDIM*XDIM];

int frame=0;

float sum=0;

const unsigned int window_width = 1000;

const unsigned int window_height = 1024;

float4 *d_vbo_buffer;

// pbo variables

GLuint pbo;

struct cudaGraphicsResource *cuda_pbo_resource;

char inputfile[] = "joecornearadialvolume.unp";

extern "C"

void launch_kernel(float* sum, float* original_data, int* frame_num, cuComplex* d, float* k_resamp, float* dc_subtracted, float* resample, float4 *ptr);

// Read Data from file

void readData() {..}

	

void convertor(){}

void calc_resample_coefficients() {}

//simply use cudaGraphicsMapFlagsWriteDiscard as cudaGraphicsResource

void createVBO(GLuint* pixel_buffer, struct cudaGraphicsResource **cuda_pixel_resource)

{

	if(pixel_buffer){

	// create buffer object

	glGenBuffers(1, pixel_buffer);

	glBindBuffer(GL_ARRAY_BUFFER, *pixel_buffer);

	//register buffer on cuda

	unsigned int size = XDIM * YDIM * 4 * sizeof(float); 

	glBufferData(GL_ARRAY_BUFFER, size, 0, GL_DYNAMIC_DRAW); 

	glBindBuffer(GL_ARRAY_BUFFER, 0); 

	cudaGraphicsGLRegisterBuffer(cuda_pixel_resource, *pixel_buffer, cudaGraphicsMapFlagsWriteDiscard);

	CUT_CHECK_ERROR_GL();

	}

	else{

	cutilSafeCall( cudaMalloc( (void **)&d_vbo_buffer, XDIM*YDIM*4*sizeof(float) ) );

	}

}

void display() { 

	// Map buffer object for writing from CUDA 

	float4* pix_buff; 

	cutilSafeCall(cudaGraphicsMapResources(1, &cuda_pbo_resource, 0)); //where invalid resource handle appears

	size_t num_bytes; 

	cutilSafeCall(cudaGraphicsResourceGetMappedPointer((void**)&pix_buff, &num_bytes, cuda_pbo_resource));

	// Execute kernel 

	// will execute by calling kernel.cu file

	if(pbo)

	launch_kernel(&sum, original_cpu, &frame, d_in, &k_resampledspacing, dc_subtracted, resamp_1D, pix_buff);

	else launch_kernel(&sum, original_cpu, &frame, d_in, &k_resampledspacing, dc_subtracted, resamp_1D, d_vbo_buffer);

	// Unmap buffer object 

	cutilSafeCall(cudaGraphicsUnmapResources(1, &cuda_pbo_resource, 0));

	// copy to Open_gl texture

	// Render from buffer object 

	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 

	glBindBuffer(GL_ARRAY_BUFFER, pbo); 

	glVertexPointer(4, GL_FLOAT, 0, 0); 

	glEnableClientState(GL_VERTEX_ARRAY); 

	glDrawArrays(GL_POINTS, 0, XDIM * YDIM); 

	glDisableClientState(GL_VERTEX_ARRAY); 

	

	// Swap buffers 

	glutSwapBuffers(); 

	glutPostRedisplay();

	

}

void deleteVBO() { 

	cudaGraphicsUnregisterResource(cuda_pbo_resource); 

	glDeleteBuffers(1, &pbo);

}

int main(int argc, char *argv[]) { 

   //set GL context first.

   glutInit(&argc, argv);

   glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE);

   glutInitWindowSize(window_width, window_height);

   glutCreateWindow("Cuda GL Interop (VBO)");

   glutDisplayFunc(display);

glewInit();

int device;

   cudaGetDevice(&device);

   cudaGLSetGLDevice(device);

   // Pre-Calculation

readData();

   convertor(); //convert values into single float

   calc_resample_coefficients();

//Cuda Memory Allocation

// Explicitly set device

// Create buffer object and register it with CUDA

   createVBO(&pbo, &cuda_pbo_resource);

// Loop

glutMainLoop();

deleteVBO();

cudaThreadExit();

}

Can somebody please give me suggestion? I cannot find any thing wrong. If possible can someone please look at my code? Ill send my code.

Part where Im getting that error is

void runCuda(struct cudaGraphicsResource **pbo_resource) {

// Map buffer object for writing from CUDA 
float4* pix_buff;
cutilSafeCall(cudaGraphicsMapResources(1, pbo_resource, 0)); <- Here
size_t num_bytes; 
cutilSafeCall(cudaGraphicsResourceGetMappedPointer((void **)&pix_buff, &num_bytes, *pbo_resource));
launch_kernel(&sum, original_cpu, &frame, d_in, &k_resampledspacing, dc_subtracted, resamp_1D, pix_buff);

// Unmap buffer object 
cutilSafeCall(cudaGraphicsUnmapResources(1, pbo_resource, 0));

}

By the way how can simpleGL sdk work without ignoring libcmt.lib ???