From c5fc2a09182970ebbbca2ce8d060cd5b141df773 Mon Sep 17 00:00:00 2001 From: Kurt Robert Rudolph Date: Wed, 20 Apr 2011 22:43:03 -0500 Subject: [PATCH] changed device info to store on GPU memory --- common/rudyGL.h | 34 ++++++++++++++++++++++++++++++++++ src/rudyCUDA_deviceInfo.cu | 13 +++++++------ 2 files changed, 41 insertions(+), 6 deletions(-) create mode 100644 common/rudyGL.h diff --git a/common/rudyGL.h b/common/rudyGL.h new file mode 100644 index 0000000..5e5d03d --- /dev/null +++ b/common/rudyGL.h @@ -0,0 +1,34 @@ + +#ifndef __RUDY_GL_H__ +#define __RUDY_GL_H__ + +#ifdef _WIN64 +#define GLUT_NO_LIB_PRAGMA +#pragma comment (lib, "opengl32.lib") /* link with Microsoft OpenGL lib */ +#pragma comment (lib, "glut64.lib") /* link with Win64 GLUT lib */ +#endif //_WIN64 + + +#ifdef _WIN32 +/* On Windows, include the local copy of glut.h and glext.h */ +#include "GL/glut.h" +#include "GL/glext.h" + +#define GET_PROC_ADDRESS( str ) wglGetProcAddress( str ) + +#else + +/* On Linux, include the system's copy of glut.h, glext.h, and glx.h */ +#if defined(__APPLE__) || defined(MACOSX) +#include +#else +#include +#include +#include +#endif +#define GET_PROC_ADDRESS( str ) glXGetProcAddress( (const GLubyte *)str ) + +#endif //_WIN32 + + +#endif //__RUDY_GL_H__ diff --git a/src/rudyCUDA_deviceInfo.cu b/src/rudyCUDA_deviceInfo.cu index 54870ee..00c6a58 100644 --- a/src/rudyCUDA_deviceInfo.cu +++ b/src/rudyCUDA_deviceInfo.cu @@ -8,11 +8,12 @@ rudyCUDA_deviceInfo * rudyCUDA_deviceInfo_gather( void) { int i; - rudyCUDA_deviceInfo * devices = (rudyCUDA_deviceInfo*) malloc( sizeof( rudyCUDA_deviceInfo)); + rudyCUDA_deviceInfo * devices; + HANDLE_ERROR( cudaMalloc( (rudyCUDA_deviceInfo**) &devices, sizeof( rudyCUDA_deviceInfo))); HANDLE_ERROR( cudaGetDeviceCount( &( devices->deviceCount))); - devices->devicePropertiesArray = (cudaDeviceProp**) malloc( sizeof( cudaDeviceProp*) * devices->deviceCount); + HANDLE_ERROR( cudaMalloc( (cudaDeviceProp**) &devices->devicePropertiesArray, sizeof( cudaDeviceProp*) * devices->deviceCount)); for( i= 0; i< devices->deviceCount; i++) { - devices->devicePropertiesArray[i] = (cudaDeviceProp*) malloc( sizeof( cudaDeviceProp)); + HANDLE_ERROR( cudaMalloc( (cudaDeviceProp***) &devices->devicePropertiesArray[i], sizeof( cudaDeviceProp))); HANDLE_ERROR( cudaGetDeviceProperties( devices->devicePropertiesArray[i], i)); } return devices; @@ -21,12 +22,12 @@ rudyCUDA_deviceInfo * rudyCUDA_deviceInfo_gather( void) { void rudyCUDA_deviceInfo_free( rudyCUDA_deviceInfo * devices) { int i; for( i= 0; i< devices->deviceCount; i++) { - free( devices->devicePropertiesArray[i]); + cudaFree( devices->devicePropertiesArray[i]); devices->devicePropertiesArray[i] = NULL; } - free( devices->devicePropertiesArray); + cudaFree( devices->devicePropertiesArray); devices->devicePropertiesArray = NULL; - free( devices); + cudaFree( devices); devices = NULL; }