diff --git a/FEDORA_18_HOWTO b/FEDORA_18_HOWTO new file mode 100644 index 0000000..3990b94 --- /dev/null +++ b/FEDORA_18_HOWTO @@ -0,0 +1,10 @@ +Here's what I had to do to get this homework assignment to build on Fedora 18: + +All the steps, based on http://www.r-tutor.com/gpu-computing/cuda-installation/cuda5.5-fc18: + +1. Uninstall the Nvidia drivers that I had installed from the RPMFusion repository. +2. Install the Nvidia drivers from the CUDA repository. The installer will fail to build the Nvidia Kernel modules because Fedora 18 currently runs kernel 3.10. Therefore, I had to apply this patch: http://pastebin.com/N0a5KMZa then manually execute the rest of the install scripts inside the RPM package. +3. Install CUDA per the tutorial in the link. +4. I couldn't get GLFW to work, so I used the Windows version as a starting point instead of the Mac Version :-P +5. I customized the Mac version's makefile to get it to compile. +6. I couldn't get Git to authenticate over HTTPS for some bizarre reason. I did it through SSH, by generating keys first: https://help.github.com/articles/generating-ssh-keys diff --git a/PROJ0_LINUX/CUDA_test_screenshot.png b/PROJ0_LINUX/CUDA_test_screenshot.png new file mode 100644 index 0000000..da0b658 Binary files /dev/null and b/PROJ0_LINUX/CUDA_test_screenshot.png differ diff --git a/PROJ0_LINUX/bin/CUDATEST b/PROJ0_LINUX/bin/CUDATEST new file mode 100755 index 0000000..9b61795 Binary files /dev/null and b/PROJ0_LINUX/bin/CUDATEST differ diff --git a/PROJ0_LINUX/bin/makefile b/PROJ0_LINUX/bin/makefile new file mode 100644 index 0000000..e6e4aea --- /dev/null +++ b/PROJ0_LINUX/bin/makefile @@ -0,0 +1,2 @@ +CC = /usr/bin/gcc -m64 +NVCC = $(CUDA_HOME)/bin/nvcc -m64 diff --git a/PROJ0_LINUX/makefile b/PROJ0_LINUX/makefile new file mode 100644 index 0000000..6101ed7 --- /dev/null +++ b/PROJ0_LINUX/makefile @@ -0,0 +1,30 @@ +NVCC = $(CUDA_HOME)/bin/nvcc -m64 +CC = /usr/bin/gcc -m64 + +#GLFW_INCLUDE_PATH = -Iglfw/include/ +#GLFW_LIB_PATH = -Lglfw/lib/ +#GLFW_INCLUDE_PATH = -Iglfw +#GLFW_LIB_PATH = -Lglfw +GLFW = $(GLFW_INCLUDE_PATH) $(GLFW_LIB_PATH) + +CUDA_SAMPLES = -I$(CUDA_HOME)/samples/common/inc +CUDA_INCLUDE = -I/usr/local/cuda/include +CUDASDK_C_LIB_PATH = -L/Developer/GPU\ Computing/C/lib +CUDASDK_C_INCLUDE_PATH = -I/Developer/GPU\ Computing/C/common/inc +CUDA = $(CUDA_INCLUDE) $(CUDASDK_C_LIB_PATH) $(CUDASDK_C_INCLUDE_PATH) $(CUDA_SAMPLES) + +#XLINKER = -Xlinker -framework,OpenGL,-framework,GLUT +LIBRARIES = -lglut -lGL -lGLU -lGLEW + +LFLAGS = $(GLFW) $(CUDA) $(LIBRARIES) -lglfw + +all: CUDATEST + +CUDATEST: src/main.cpp + $(NVCC) $(GLEW_PATH) $(LFLAGS) src/main.cpp src/kernel.cu src/glslUtility.cpp -o bin/CUDATEST + +clean: + rm bin/CUDATEST + rm *.o + +.PHONY : bin/CUDATEST diff --git a/PROJ0_LINUX/run.sh b/PROJ0_LINUX/run.sh new file mode 100644 index 0000000..b501c9e --- /dev/null +++ b/PROJ0_LINUX/run.sh @@ -0,0 +1,3 @@ +#!/bin/bash +export DYLD_LIBRARY_PATH='/usr/local/cuda/lib:glfw/lib'; +./bin/CUDATEST; diff --git a/PROJ0_LINUX/shaders/passthroughFS.glsl b/PROJ0_LINUX/shaders/passthroughFS.glsl new file mode 100644 index 0000000..fd4e15b --- /dev/null +++ b/PROJ0_LINUX/shaders/passthroughFS.glsl @@ -0,0 +1,8 @@ +varying vec2 v_Texcoords; + +uniform sampler2D u_image; + +void main(void) +{ + gl_FragColor = texture2D(u_image, v_Texcoords); +} diff --git a/PROJ0_LINUX/shaders/passthroughVS.glsl b/PROJ0_LINUX/shaders/passthroughVS.glsl new file mode 100644 index 0000000..a3dbe92 --- /dev/null +++ b/PROJ0_LINUX/shaders/passthroughVS.glsl @@ -0,0 +1,9 @@ +attribute vec4 Position; +attribute vec2 Texcoords; +varying vec2 v_Texcoords; + +void main(void) +{ + v_Texcoords = Texcoords; + gl_Position = Position; +} \ No newline at end of file diff --git a/PROJ0_LINUX/src/glslUtility.cpp b/PROJ0_LINUX/src/glslUtility.cpp new file mode 100644 index 0000000..bb07511 --- /dev/null +++ b/PROJ0_LINUX/src/glslUtility.cpp @@ -0,0 +1,154 @@ +// GLSL Utility: A utility class for loading GLSL shaders, for Patrick Cozzi's CIS565: GPU Computing at the University of Pennsylvania +// Written by Varun Sampath and Patrick Cozzi, Copyright (c) 2012 University of Pennsylvania + +#include "glslUtility.h" + +#include +#include +#include +#include + +using std::ios; + +namespace glslUtility { + + typedef struct { + GLuint vertex; + GLuint fragment; + } shaders_t; + + char* loadFile(const char *fname, GLint &fSize) + { + // file read based on example in cplusplus.com tutorial + std::ifstream file (fname, ios::in|ios::binary|ios::ate); + if (file.is_open()) + { + unsigned int size = (unsigned int)file.tellg(); + fSize = size; + char *memblock = new char [size]; + file.seekg (0, ios::beg); + file.read (memblock, size); + file.close(); + //std::cout << "file " << fname << " loaded" << std::endl; + return memblock; + } + + std::cout << "Unable to open file " << fname << std::endl; + exit(1); + } + + // printShaderInfoLog + // From OpenGL Shading Language 3rd Edition, p215-216 + // Display (hopefully) useful error messages if shader fails to compile + void printShaderInfoLog(GLint shader) + { + int infoLogLen = 0; + int charsWritten = 0; + GLchar *infoLog; + + glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &infoLogLen); + + if (infoLogLen > 1) + { + infoLog = new GLchar[infoLogLen]; + // error check for fail to allocate memory omitted + glGetShaderInfoLog(shader,infoLogLen, &charsWritten, infoLog); + //std::cout << "InfoLog:" << std::endl << infoLog << std::endl; + delete [] infoLog; + } + } + + void printLinkInfoLog(GLint prog) + { + int infoLogLen = 0; + int charsWritten = 0; + GLchar *infoLog; + + glGetProgramiv(prog, GL_INFO_LOG_LENGTH, &infoLogLen); + + if (infoLogLen > 1) + { + infoLog = new GLchar[infoLogLen]; + // error check for fail to allocate memory omitted + glGetProgramInfoLog(prog,infoLogLen, &charsWritten, infoLog); + //std::cout << "InfoLog:" << std::endl << infoLog << std::endl; + delete [] infoLog; + } + } + + shaders_t loadShaders(const char * vert_path, const char * frag_path) { + GLuint f, v; + + char *vs,*fs; + + v = glCreateShader(GL_VERTEX_SHADER); + f = glCreateShader(GL_FRAGMENT_SHADER); + + // load shaders & get length of each + GLint vlen; + GLint flen; + vs = loadFile(vert_path,vlen); + fs = loadFile(frag_path,flen); + + const char * vv = vs; + const char * ff = fs; + + glShaderSource(v, 1, &vv,&vlen); + glShaderSource(f, 1, &ff,&flen); + + GLint compiled; + + glCompileShader(v); + glGetShaderiv(v, GL_COMPILE_STATUS, &compiled); + if (!compiled) + { + std::cout << "Vertex shader not compiled." << std::endl; + } + printShaderInfoLog(v); + + glCompileShader(f); + glGetShaderiv(f, GL_COMPILE_STATUS, &compiled); + if (!compiled) + { + std::cout << "Fragment shader not compiled." << std::endl; + } + printShaderInfoLog(f); + + shaders_t out; out.vertex = v; out.fragment = f; + + delete [] vs; // dont forget to free allocated memory, or else really bad things start happening + delete [] fs; // we allocated this in the loadFile function... + + return out; + } + + void attachAndLinkProgram( GLuint program, shaders_t shaders) { + glAttachShader(program, shaders.vertex); + glAttachShader(program, shaders.fragment); + + glLinkProgram(program); + GLint linked; + glGetProgramiv(program,GL_LINK_STATUS, &linked); + if (!linked) + { + std::cout << "Program did not link." << std::endl; + } + printLinkInfoLog(program); + } + + GLuint createProgram(const char *vertexShaderPath, const char *fragmentShaderPath, const char *attributeLocations[], GLuint numberOfLocations) + { + glslUtility::shaders_t shaders = glslUtility::loadShaders(vertexShaderPath, fragmentShaderPath); + + GLuint program = glCreateProgram(); + + for (GLuint i = 0; i < numberOfLocations; ++i) + { + glBindAttribLocation(program, i, attributeLocations[i]); + } + + glslUtility::attachAndLinkProgram(program, shaders); + + return program; + } +} diff --git a/PROJ0_LINUX/src/glslUtility.h b/PROJ0_LINUX/src/glslUtility.h new file mode 100644 index 0000000..00ab7e8 --- /dev/null +++ b/PROJ0_LINUX/src/glslUtility.h @@ -0,0 +1,16 @@ +// GLSL Utility: A utility class for loading GLSL shaders, for Patrick Cozzi's CIS565: GPU Computing at the University of Pennsylvania +// Written by Varun Sampath and Patrick Cozzi, Copyright (c) 2012 University of Pennsylvania + +#ifndef GLSLUTILITY_H_ +#define GLSLUTILITY_H_ + +#include + +namespace glslUtility +{ + +GLuint createProgram(const char *vertexShaderPath, const char *fragmentShaderPath, const char *attributeLocations[], GLuint numberOfLocations); + +} + +#endif \ No newline at end of file diff --git a/PROJ0_LINUX/src/kernel.cu b/PROJ0_LINUX/src/kernel.cu new file mode 100644 index 0000000..6a5b551 --- /dev/null +++ b/PROJ0_LINUX/src/kernel.cu @@ -0,0 +1,75 @@ +// CIS565 CUDA Checker: A simple CUDA hello-world style program for Patrick Cozzi's CIS565: GPU Computing at the University of Pennsylvania +// Written by Yining Karl Li, Copyright (c) 2012 University of Pennsylvania +// This file includes code from: +// Rob Farber for CUDA-GL interop, from CUDA Supercomputing For The Masses: http://www.drdobbs.com/architecture-and-design/cuda-supercomputing-for-the-masses-part/222600097 + +#include +#include +#include +//#include +#include "kernel.h" +#include + +void checkCUDAError(const char *msg) { + cudaError_t err = cudaGetLastError(); + if( cudaSuccess != err) { + fprintf(stderr, "Cuda error: %s: %s.\n", msg, cudaGetErrorString( err) ); + exit(EXIT_FAILURE); + } +} + +//Kernel that writes the image to the OpenGL PBO directly. +__global__ void createVersionVisualization(uchar4* PBOpos, int width, int height, int major, int minor){ + + int x = (blockIdx.x * blockDim.x) + threadIdx.x; + int y = (blockIdx.y * blockDim.y) + threadIdx.y; + int index = x + (y * width); + + if(x<=width && y<=height){ + // Each thread writes one pixel location in the texture (textel) + PBOpos[index].w = 0; + PBOpos[index].x = 0; + PBOpos[index].y = 0; + PBOpos[index].z = 0; + + if(y>>(PBOpos, width, height, major, minor); + // make certain the kernel has completed + cudaThreadSynchronize(); + + checkCUDAError("Kernel failed!"); +} diff --git a/PROJ0_LINUX/src/kernel.h b/PROJ0_LINUX/src/kernel.h new file mode 100644 index 0000000..0e305ed --- /dev/null +++ b/PROJ0_LINUX/src/kernel.h @@ -0,0 +1,20 @@ +// CIS565 CUDA Checker: A simple CUDA hello-world style program for Patrick Cozzi's CIS565: GPU Computing at the University of Pennsylvania +// Written by Yining Karl Li, Copyright (c) 2012 University of Pennsylvania +// This file includes code from: +// Rob Farber for CUDA-GL interop, from CUDA Supercomputing For The Masses: http://www.drdobbs.com/architecture-and-design/cuda-supercomputing-for-the-masses-part/222600097 + +#ifndef KERNEL_H +#define KERNEL_H + +#include +#include + +#if CUDA_VERSION >= 5000 + #include +#else + #include +#endif + +void cudaKernel(uchar4* pos, int width, int height, int major, int minor); + +#endif //KERNEL_H diff --git a/PROJ0_LINUX/src/main.cpp b/PROJ0_LINUX/src/main.cpp new file mode 100644 index 0000000..b9d5031 --- /dev/null +++ b/PROJ0_LINUX/src/main.cpp @@ -0,0 +1,238 @@ +// CIS565 CUDA Checker: A simple CUDA hello-world style program for Patrick Cozzi's CIS565: GPU Computing at the University of Pennsylvania +// Written by Yining Karl Li, Copyright (c) 2013 University of Pennsylvania +// This file includes code from: +// Rob Farber for CUDA-GL interop, from CUDA Supercomputing For The Masses: http://www.drdobbs.com/architecture-and-design/cuda-supercomputing-for-the-masses-part/222600097 +// Varun Sampath and Patrick Cozzi for GLSL Loading, from CIS565 Spring 2012 HW5 at the University of Pennsylvania: http://cis565-spring-2012.github.com/ + +#include "main.h" + +//------------------------------- +//-------------MAIN-------------- +//------------------------------- + +int main(int argc, char* argv[]){ + //Change this line to use your name! + yourName = "Nathan Marshak"; + + init(argc, argv); + initVAO(); + initTextures(); + initCuda(); + + GLuint passthroughProgram; + passthroughProgram = initShader("shaders/passthroughVS.glsl", "shaders/passthroughFS.glsl"); + + glUseProgram(passthroughProgram); + glActiveTexture(GL_TEXTURE0); + + glutDisplayFunc(display); + glutKeyboardFunc(keyboard); + + glutMainLoop(); + + return 0; +} + +//------------------------------- +//---------RUNTIME STUFF--------- +//------------------------------- + +void runCuda(){ + + // Map OpenGL buffer object for writing from CUDA on a single GPU + // No data is moved (Win & Linux). When mapped to CUDA, OpenGL should not use this buffer + + uchar4 *dptr=NULL; + cudaGLMapBufferObject((void**)&dptr, pbo); + + // Execute the kernel + cudaKernel(dptr, width, height, major, minor); + + // Unmap buffer object + cudaGLUnmapBufferObject(pbo); + +} + +void display(){ + runCuda(); + + glBindBuffer( GL_PIXEL_UNPACK_BUFFER, pbo); + glBindTexture(GL_TEXTURE_2D, image); + glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, width, height, + GL_RGBA, GL_UNSIGNED_BYTE, NULL); + + glClear(GL_COLOR_BUFFER_BIT); + + // VAO, shader program, and texture already bound + glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, 0); + + glutPostRedisplay(); + glutSwapBuffers(); +} + +void keyboard(unsigned char key, int x, int y) +{ + std::cout << key << std::endl; + switch (key) + { + case(27): + exit(1); + break; + } +} + +//------------------------------- +//----------SETUP STUFF---------- +//------------------------------- + +void init(int argc, char* argv[]){ + glutInit(&argc, argv); + glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA); + glutInitWindowSize(width, height); + + // Set window title to "Student Name: GPU Name" + string deviceName; + cudaDeviceProp deviceProp; + int gpudevice = 0; + int device_count = 0; + cudaGetDeviceCount( &device_count); + if (gpudevice > device_count) + { + printf("Error: GPU device number is greater than the number of devices! Perhaps a CUDA-capable GPU is not installed?\n"); + exit(1); + } + cudaGetDeviceProperties(&deviceProp, gpudevice); + deviceName = deviceProp.name; + deviceName = yourName + ": " + deviceProp.name; + major = deviceProp.major; + minor = deviceProp.minor; + glutCreateWindow(deviceName.c_str()); + + // Init GLEW + glewInit(); + GLenum err = glewInit(); + if (GLEW_OK != err) + { + /* Problem: glewInit failed, something is seriously wrong. */ + std::cout << "glewInit failed, aborting." << std::endl; + exit (1); + } +} + +void initPBO(GLuint* pbo){ + if (pbo) { + // set up vertex data parameter + int num_texels = width*height; + int num_values = num_texels * 4; + int size_tex_data = sizeof(GLubyte) * num_values; + + // Generate a buffer ID called a PBO (Pixel Buffer Object) + glGenBuffers(1,pbo); + // Make this the current UNPACK buffer (OpenGL is state-based) + glBindBuffer(GL_PIXEL_UNPACK_BUFFER, *pbo); + // Allocate data for the buffer. 4-channel 8-bit image + glBufferData(GL_PIXEL_UNPACK_BUFFER, size_tex_data, NULL, GL_DYNAMIC_COPY); + cudaGLRegisterBufferObject( *pbo ); + } +} + +void initCuda(){ + // Use device with highest Gflops/s +#if CUDA_VERSION >= 5000 + cudaGLSetGLDevice( gpuGetMaxGflopsDeviceId() ); +#else + cudaGLSetGLDevice( cutGetMaxGflopsDeviceId() ); +#endif + + initPBO(&pbo); + + // Clean up on program exit + atexit(cleanupCuda); + + runCuda(); +} + +void initTextures(){ + glGenTextures(1,&image); + glBindTexture(GL_TEXTURE_2D, image); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA8, width, height, 0, GL_BGRA, + GL_UNSIGNED_BYTE, NULL); +} + +void initVAO(void){ + GLfloat vertices[] = + { + -1.0f, -1.0f, + 1.0f, -1.0f, + 1.0f, 1.0f, + -1.0f, 1.0f, + }; + + GLfloat texcoords[] = + { + 1.0f, 1.0f, + 0.0f, 1.0f, + 0.0f, 0.0f, + 1.0f, 0.0f + }; + + GLushort indices[] = { 0, 1, 3, 3, 1, 2 }; + + GLuint vertexBufferObjID[3]; + glGenBuffers(3, vertexBufferObjID); + + glBindBuffer(GL_ARRAY_BUFFER, vertexBufferObjID[0]); + glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW); + glVertexAttribPointer((GLuint)positionLocation, 2, GL_FLOAT, GL_FALSE, 0, 0); + glEnableVertexAttribArray(positionLocation); + + glBindBuffer(GL_ARRAY_BUFFER, vertexBufferObjID[1]); + glBufferData(GL_ARRAY_BUFFER, sizeof(texcoords), texcoords, GL_STATIC_DRAW); + glVertexAttribPointer((GLuint)texcoordsLocation, 2, GL_FLOAT, GL_FALSE, 0, 0); + glEnableVertexAttribArray(texcoordsLocation); + + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vertexBufferObjID[2]); + glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_STATIC_DRAW); +} + +GLuint initShader(const char *vertexShaderPath, const char *fragmentShaderPath){ + GLuint program = glslUtility::createProgram(vertexShaderPath, fragmentShaderPath, attributeLocations, 2); + GLint location; + glUseProgram(program); + + if ((location = glGetUniformLocation(program, "u_image")) != -1) + { + glUniform1i(location, 0); + } + + return program; +} + +//------------------------------- +//---------CLEANUP STUFF--------- +//------------------------------- + +void cleanupCuda(){ + if(pbo) deletePBO(&pbo); + if(image) deleteTexture(&image); +} + +void deletePBO(GLuint* pbo){ + if (pbo) { + // unregister this buffer object with CUDA + cudaGLUnregisterBufferObject(*pbo); + + glBindBuffer(GL_ARRAY_BUFFER, *pbo); + glDeleteBuffers(1, pbo); + + *pbo = (GLuint)NULL; + } +} + +void deleteTexture(GLuint* tex){ + glDeleteTextures(1, tex); + *tex = (GLuint)NULL; +} + diff --git a/PROJ0_LINUX/src/main.h b/PROJ0_LINUX/src/main.h new file mode 100644 index 0000000..4cb7d59 --- /dev/null +++ b/PROJ0_LINUX/src/main.h @@ -0,0 +1,82 @@ +// CIS565 CUDA Checker: A simple CUDA hello-world style program for Patrick Cozzi's CIS565: GPU Computing at the University of Pennsylvania +// Written by Yining Karl Li, Copyright (c) 2012 University of Pennsylvania +// This file includes code from: +// Rob Farber for CUDA-GL interop, from CUDA Supercomputing For The Masses: http://www.drdobbs.com/architecture-and-design/cuda-supercomputing-for-the-masses-part/222600097 +// Varun Sampath and Patrick Cozzi for GLSL Loading, from CIS565 Spring 2012 HW5 at the University of Pennsylvania: http://cis565-spring-2012.github.com/ + +#ifndef MAIN_H +#define MAIN_H + +#include +#include +#include +#include + +#if CUDART_VERSION >= 5000 + #include + #include +#else + #include + #include +#endif + +#include +#include +#include +#include "kernel.h" +#include "glslUtility.h" + +using namespace std; + +//------------------------------- +//------------GL STUFF----------- +//------------------------------- + +GLuint positionLocation = 0; +GLuint texcoordsLocation = 1; +const char *attributeLocations[] = { "Position", "Tex" }; +GLuint pbo = (GLuint)NULL; +GLuint image; + +//------------------------------- +//----------CUDA STUFF----------- +//------------------------------- + +int major; int minor; +int width=800; int height=800; +string yourName; + +//------------------------------- +//-------------MAIN-------------- +//------------------------------- + +int main(int argc, char* argv[]); + +//------------------------------- +//---------RUNTIME STUFF--------- +//------------------------------- + +void runCuda(); +void display(); +void keyboard(unsigned char key, int x, int y); + +//------------------------------- +//----------SETUP STUFF---------- +//------------------------------- + +void init(int argc, char* argv[]); +void initPBO(GLuint* pbo); +void initCuda(); +void initTextures(); +void initVAO(); +GLuint initShader(const char *vertexShaderPath, const char *fragmentShaderPath); + +//------------------------------- +//---------CLEANUP STUFF--------- +//------------------------------- + +void cleanupCuda(); +void deletePBO(GLuint* pbo); +void deleteTexture(GLuint* tex); + +#endif \ No newline at end of file diff --git a/PROJ0_LINUX/src/shaders/passthroughFS.glsl b/PROJ0_LINUX/src/shaders/passthroughFS.glsl new file mode 100644 index 0000000..fd4e15b --- /dev/null +++ b/PROJ0_LINUX/src/shaders/passthroughFS.glsl @@ -0,0 +1,8 @@ +varying vec2 v_Texcoords; + +uniform sampler2D u_image; + +void main(void) +{ + gl_FragColor = texture2D(u_image, v_Texcoords); +} diff --git a/PROJ0_LINUX/src/shaders/passthroughVS.glsl b/PROJ0_LINUX/src/shaders/passthroughVS.glsl new file mode 100644 index 0000000..a3dbe92 --- /dev/null +++ b/PROJ0_LINUX/src/shaders/passthroughVS.glsl @@ -0,0 +1,9 @@ +attribute vec4 Position; +attribute vec2 Texcoords; +varying vec2 v_Texcoords; + +void main(void) +{ + v_Texcoords = Texcoords; + gl_Position = Position; +} \ No newline at end of file diff --git a/README.md b/README.md index 5ac0a6d..6c33ced 100644 --- a/README.md +++ b/README.md @@ -1,97 +1,3 @@ -CIS565: Homework 0: Setting up CUDA and running CUDATEST -Fall 2013 - -Due Monday, 09/09/2013 -------------------------------------------------------------------------------- - -------------------------------------------------------------------------------- -NOTE: -------------------------------------------------------------------------------- -This homework requires an NVIDIA graphics card with CUDA capability! Any card after the Geforce 8xxx series will work. If you do not have an NVIDIA graphics card in the machine you are working on, fell free to use any machine in the SIG Lab or in Moore100 labs. All machines in the SIG Lab and Moore100 are equipped with CUDA capable NVIDIA graphics cards. If this too proves to be a problem, please contact Patrick or Liam as soon as possible. - -------------------------------------------------------------------------------- -INTRODUCTION: -------------------------------------------------------------------------------- -This homework is meant to get you started with CUDA through some simple tasks. In this homework, you will install the necessary CUDA 5.5 tools and drivers needed for the class, check out a test CUDA program from Github, build, and run the test program, and check the results back into Github. None of these steps are difficult, but there is a lot to do, so let's get started! - -A quick note: all of the projects for this semester will use CUDA 4.0 as their baseline, since that is the version of CUDA installed in the Moore100 labs. Versions of CUDA later than 4.0 will work too, but for Windows you may have to tweak the Visual Studio project file settings slightly. - -------------------------------------------------------------------------------- -PART 1- INSTALL CUDA: -------------------------------------------------------------------------------- -WINDOWS: - -* 1. Make sure you are running Windows XP/Vista/7 and that your graphics drivers are up to date. You will need support for OpenGL 3.2 or better in this class. -* 2. Make sure you have installed Visual Studio 2010 (available for free to Penn Engineering students from MSDN Academic Alliance). Visual Studio 2012 should also be compatible with a little elbow grease and supports some of the newer features of C++11. -* 3. Install the CUDA 4.0 (or greater) For Windows Toolkit, Development Drivers, and SDK from http://developer.nvidia.com/cuda/cuda-downloads or https://developer.nvidia.com/cuda-toolkit-archive. Make sure you download and install the appropriate versions of each package for your machine. (As of version 5.5 all three components are bundeled together in one package). -* 4. You're good to go! All Windows base code for CIS565 will make use of Visual Studio 2010 and will be distributed as Visual Studio 2010 projects. - -OSX: **NOTE: Karl was wonderful enough to provide OSX base code, however I've never developed on a Mac before** - -* 1. Make sure you are running OSX 10.7 or 10.8. We will need OpenGL 3.2 support in this class, so 10.7 or 10.8 are mandatory if you plan on using OSX as your development platform. -* 2. Make sure you have installed XCode 4.2 (available for free from the App Store). -* 3. Make sure you have installed the OSX Unix Command Line Development Tools (XCode->Preferences->Downloads->Command Line Tools->Install). -* 4. Install the CUDA 4.0 (or greater) For Mac Toolkit, Development Drivers, and SDK from http://developer.nvidia.com/cuda/cuda-downloads or https://developer.nvidia.com/cuda-toolkit-archive. (As of version 5.5 all three components are bundeled together in one package). -* 5. You're good to go! All OSX base code for CIS565 will make use of the Unix make toolchain, hence the need for OSX Unix Command Line Development Tools. - -------------------------------------------------------------------------------- -PART 2- FORK/CLONE PROJECT 0: -------------------------------------------------------------------------------- - -* 1. Using GitHub fork this repository into your own account. -* 2. Clone from GitHub onto your machine. - -------------------------------------------------------------------------------- -PART 3- BUILD/RUN CUDATEST: -------------------------------------------------------------------------------- -CUDATEST is a simple program that demonstrates CUDA and OpenGL functionality and interoperability on systems that CUDA has been properly installed on. If the machine you are working on has CUDA properly set up and has OpenGL 3.2 support, then when you run CUDATEST, you should see a window displaying either two horizonal colored bars OR one solid color. What gets displayed depends on your graphics card, so your results will most likely vary from some or many of your classmates. The window title should be a combination of your name and the model of your graphics card. - -Please note: The Windows version of Homework 0 uses GLEW/freeglut, whereas the OSX version of Homework 0 uses GLFW. The two versions of CUDATEST are functionally the same and share the same CUDA code, but the GL harnesses for each are slightly different. - -WINDOWS: - -Contents: - -The Windows version of CUDATEST is in the HW0_WIN/ folder. The contents of the folder are the following: - -* Build/ contains CUDA 4.0 build rules. Normally the CUDA build rules do not need to be included, but the Moore100 machines have broken CUDA 4.0 rules. The ones included with the project files are fixed to work properly in Moore100. -* CUDATEST/ contains the actual source code for CUDATEST -* shared/ contains the libraries and includes for freeglut and glew - -To Build: - -Open CUDATEST.sln in Visual Studio 2010. The project should build straight from Visual Studio 2010 without modification. - -To Run: - -CUDATEST should run straight from Visual Studio 2010 without modification after building if CUDA has been installed properly on your machine. - -OSX: - -Contents: - -The OSX version of CUDATEST is in the HW0_MAC/ folder. The contents of the folder are the following: -* bin/ is where the binary will be built to and run from. -* glfw/ contains the glfw OpenGL library's header and library files. -* shaders/ contains two simple GLSL shaders required for the OpenGL component of CUDATEST to run -* src/ contains the actual source code for CUDATEST - -To Build: - -The makefile for CUDATEST has already been created and set up for you. If you installed the CUDA SDK to its default location, you should be able to simply run the command "make" inside of the OSX/ folder in order to build CUDATEST. If you installed the CUDA SDK to a custom location, you will have to modify the makefile accordingly. - -To Run: - -Once you have successfully build CUDATEST, you can run CUDATEST by running the script run.sh in the OSX/ folder. run.sh will set up the necessary environment variables required to run CUDATEST, and then will run CUDATEST. Run.sh can be run with the command "./run.sh". You may need to run "chmod +x run.sh" beforehand, depending on how your system is set up. - -------------------------------------------------------------------------------- -PART 4- MODIFY CUDATEST, RUN, SCREENSHOT, AND SUBMIT -------------------------------------------------------------------------------- - -* 1. Line 15 of main.cpp contains a variable string set by default to "Your Name Here". Replace "Your Name Here" with your name, rebuild, and run CUDATEST. Take a screenshot of CUDATEST working on your machine. -* 2. ADD your screenshot to your Git repository and check in your modified main.cpp and added screenshot. -* 2.5 If you are using Windows, make sure your modified CUDATEST can run in Moore100 or the SIG Lab. -* 3. Open a Pull Request so we can see that you have finished. -* 4. Send an email to Liam With your name, github account name, and the grade you believe you deserve. -* 5. You're done with Homework 0! - +A small CUDA test project for the GPU Programming class (CIS565) at UPenn. I've +forked the official class repo and have added my own version of the test for +Fedora 18.