|
|
8/20/2009 UPDATE: I still have problems for step i), executable file produced, and can be run normally. Only problem now is debug step. I need some advices!
a) Start Eclipse and set the workspace to the SDK install folder/projects b) Create a new C or C++ Makefile Project New>File>C++ Project; then choose ("Makefile project" in the "Project types" selection window) In the "Toolchain" selection window select "Linux GCC",set a name and click Finish. Let's say the project name is CUDA_test c) Add a new Source File with the extension eg. "CUDA_test.cu" and click Finish File>New>Source File
d) Add a new File called "Makefile" (File>New>File) and click ok
e) Edit the Makefile Copy these lines to the makefile:
################################################# # Build script for project ################################################# EXECUTABLE := CUDA_test
# cu files CUFILES := CUDA_test.cu # c/c++ CCFILES := CUDA_INSTALL_PATH := /usr/local/cuda
PROJECT_PATH := . NV_ROOT_PATH := /home/username/NVIDIA_GPU_Computing_SDK/C ifeq ($(emu), 1)
LIB := -lcufftemu else LIB := -lcufft endif # Basic directory setup for SDK
# (override directories only if they are not already defined) #SRCDIR ?= $(PROJECT_PATH)/Source #ROOTDIR ?= $(PROJECT_PATH) #ROOTBINDIR ?= $(PROJECT_PATH)/bin #BINDIR ?= $(ROOTBINDIR)/linux #ROOTOBJDIR ?= $(ROOTBINDIR)/obj #LIBDIR := $(NV_ROOT_PATH)/lib #COMMONDIR := $(NV_ROOT_PATH)/common include ../../common/common.mk
#######################################################
f) now edit the CUDA_test.cu file ##############################################################################
/* * Copyright 1993-2008 NVIDIA Corporation. All rights reserved. * * NOTICE TO USER: * * This source code is subject to NVIDIA ownership rights under U.S. and * international Copyright laws. Users and possessors of this source code * are hereby granted a nonexclusive, royalty-free license to use this code * in individual and commercial software. * * NVIDIA MAKES NO REPRESENTATION ABOUT THE SUITABILITY OF THIS SOURCE * CODE FOR ANY PURPOSE. IT IS PROVIDED "AS IS" WITHOUT EXPRESS OR * IMPLIED WARRANTY OF ANY KIND. NVIDIA DISCLAIMS ALL WARRANTIES WITH * REGARD TO THIS SOURCE CODE, INCLUDING ALL IMPLIED WARRANTIES OF * MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE. * IN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL, * OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE * OR PERFORMANCE OF THIS SOURCE CODE. * * U.S. Government End Users. This source code is a "commercial item" as * that term is defined at 48 C.F.R. 2.101 (OCT 1995), consisting of * "commercial computer software" and "commercial computer software * documentation" as such terms are used in 48 C.F.R. 12.212 (SEPT 1995) * and is provided to the U.S. Government only as a commercial end item. * Consistent with 48 C.F.R.12.212 and 48 C.F.R. 227.7202-1 through * 227.7202-4 (JUNE 1995), all U.S. Government End Users acquire the * source code with only those rights set forth herein. * * Any use of this source code in individual and commercial software must * include, in the user documentation and internal comments to the code, * the above Disclaimer and U.S. Government End Users Notice. */
// includes, system #include <stdio.h> #include <assert.h>
// Simple utility function to check for CUDA runtime errors void checkCUDAError(const char* msg);
// Part 1 of 1: implement the kernel __global__ void reverseArrayBlock(int* d_B, int* d_A ) { int tx = threadIdx.x; d_B[blockDim.x-tx-1] = d_A[tx]; }
//////////////////////////////////////////////////////////////////////////////// // Program main //////////////////////////////////////////////////////////////////////////////// int main( int argc, char** argv) { // pointer for host memory and size int *h_a; int dimA = 256;
// pointer for device memory int *d_b, *d_a;
// define grid and block size int numBlocks = 1; int numThreadsPerBlock = dimA;
// allocate host and device memory size_t memSize = numBlocks * numThreadsPerBlock * sizeof(int); h_a = (int *) malloc(memSize); cudaMalloc( (void **) &d_a, memSize ); cudaMalloc( (void **) &d_b, memSize );
// Initialize input array on host for (int i = 0; i < dimA; ++i) { h_a[i] = i; }
// Copy host array to device array cudaMemcpy( d_a, h_a, memSize, cudaMemcpyHostToDevice );
// launch kernel dim3 dimGrid(numBlocks); dim3 dimBlock(numThreadsPerBlock); reverseArrayBlock<<< dimGrid, dimBlock >>>( d_b, d_a );
// block until the device has completed cudaThreadSynchronize();
// check if kernel execution generated an error // Check for any CUDA errors checkCUDAError("kernel invocation");
// device to host copy cudaMemcpy( h_a, d_b, memSize, cudaMemcpyDeviceToHost );
// Check for any CUDA errors checkCUDAError("memcpy");
// verify the data returned to the host is correct for (int i = 0; i < dimA; i++) { assert(h_a[i] == dimA - 1 - i ); }
// free device memory cudaFree(d_a); cudaFree(d_b);
// free host memory free(h_a);
// If the program makes it this far, then the results are correct and // there are no run-time errors. Good work! printf("Correct!\n");
return 0; }
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); } }
####################################################### g) now you have to change the Project properties. Right click the project and select properties. g.1) Select C/C++ Build options. Deselect the option "Use default build command". Then, on the Build command input field enter:
For release mode let the field with "make" unchanged. For debug mode enter "make dbg=1" (Use customarily this option) For debug emulation mode enter "make dbg=1 emu=1" (this enables the user to acces GPU functions when debugging Notice that that the used compiler for GPU functions is not nvcc but gcc) For emulation mode enter "make emu=1".
g.2) Still in the C/C++ Build options, Switch to tab "Behaviour" Empty the textboxes next to Build (Incremental build) and Clean [delete "all" and "clean"] (located at the bottom of :Workbench Build Type" area) Select the line "Discovery options" under the menu C/C++ Build set the Discovery profile to "GCC per project scanner info profile" g.3) At C/C++ General Select the line "Paths and symbols" under the menu and switch to the tab "Library Paths". Click on Add and enter "$LD_LIBRARY_PATH". Select the box "Add to all configurations" At last click ok to close this tab, and again to close the "Paths and symbols window" g.4) Ctrl + b to Build Project h) Now create a debug profile for this project (assuming the executable could be produced). h.1) Right click the Project option and select "Debug As..">"Open Debug Dialog...". Double left-click on C/C++ Local Application to add a new debug configuration h.2) Select the new configuration and then in the line "C/C++ Application:" click "Browse..." and select the executable from your filesystem. [it should be here "/home/username/NVIDIA_GPU_Computing_SDK/C/bin/linux/release/"] h.3) Now switch to the tab common and select in the box "Display in favorites menu" the checkbox for Debug. Press Apply and close the window. i) Press F11 to start the program or select the start configuration from the "bug" button in the shortcut menu. Then you have the following options: RUN dialog give the different opportunities F8 from break point to break point (or end) F6 execute stepwise F5 step into function
Thanks bin04017 @ gmail.com for his/her instructions from nvidia forum.
8/18/2009 My steps are:
1. install the 2.6.28.11 server; 2. without install gnome, "sudo apt-get install build-essential linux-headers-`uname -r`" 3. wget the cuda 2.3 driver for ubuntu 9.04 4. at this moment, since no gnome installed, no X-server is on, "sudo sh NVIDIA_LONG_NAME_64_BIT_DRIVER.run" 5. It asked me if I would like to install 32 bit compatible OPEN GL library, i said yes 6. Installed Nvidia driver sucessfully 7. install gnome 8. reboot 9. in gnome, run "sudo nvidia-xconfig"
After done with above, go to System -> Preferences -> Display,
it would say something about some feature is not there, it asks whether
you want to use alternative driver from your graphics card. Choose "YES", then you can see the Nvidia X driver Utilities Panel
ONE MORE THING: after changing all the display settings, you would like to save that xorg.config, but the system would tell you it could not remove/create xorg.config.backup. What I did was, clicked on the preview settings, and copied the whole thing, manually changed xorg.config by editor.
And now you can reboot, and you will see the display setting is still there!
Add /usr/local/cuda/bin to $PATH, /usr/local/cuda/lib64 to $LD_LIBRARY_PATH, ~/NVIDIA_GPU_Computing_SDK/C to $NVSDKCUDA_ROOT.You should put them into ~/.bashrc to make it permernant!
Added some lib such as libglut3, libxi and libmu to make the "make" under SDK run) Then CUDA SDK samples all worked on my system! It's time to get some my own test code running!
|