Let's fetch this week's upstream changes.
$ cd ~/cs40/examples $ git fetch upstream $ git merge -X ours upstream/master
After this step, you will need to manually edit the top level CMakeLists.txt
to add the new subdirectory.
#add these lines near the bottom if(CMAKE_CUDA_COMPILER) add_subdirectory(w07-cuda-pt1) endif()You will also need to add a line to grab some CUDA helper files. Add the line
include(${CMAKE_SOURCE_DIR}/cmake_modules/detectCUDA.cmake)after the line in
CMakeLists.txt
that reads
include(${CMAKE_SOURCE_DIR}/cmake_modules/helpers.cmake)
We are not done yet with CUDA customization. CUDA requires that we use a special compiler. For some reason, it is not being picked up correctly by CMake or the default paths.
You will need to edit your ~/.bashrc
file to add some custom paths. Append the following lines to the end of this file.
export PATH=$PATH:/usr/local/cuda/bin export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/cuda/lib64
After making the changes, for today only, run the following command to update the paths.
source ~/.bashrc
Your ~/.bashrc
is read every time you log into the system, so next time you login, you will not need to update this file or run the source
command. We are almost done with setup.
The last step is to go into your examples/build
directory and tell cmake
the location of CUDA and the default CUDA compiler. This should also be a one time step, unless you rebuild your build directory from scratch again.
cd ~/cs40/examples/build cmake -DCMAKE_CUDA_HOST_COMPILER=/usr/bin/g++-6 \ -DCMAKE_CUDA_COMPILER=/usr/local/cuda/bin/nvcc ../
If everything went well, you should be able to run make -j8
to compile the week 07 examples.
make -j8 cd w07-cuda-pt1 ./simple_kernel_params 2 + 7 = 9
glDrawArrays
.
cudaMalloc
and cudaMemcpy
hello_world.cu
: the nvcc compiler.
simple_kernel.cu
: the __global__
keyword and <<<>>>
syntax.
simple_kernel_params.cu
: cudaMalloc, cudaMemcpy, cudaFree
simple_device_call.cu
: the __device__
keyword
add_loop_cpu.cpp
: sequential array addition
add_loop_gpu.cu
: parallel array addition (small)
add_loop_long.cu
: parallel array addition (large)
enum_gpu
: general GPU properties.
Let's fetch this more upstream changes.
$ cd ~/cs40/examples $ git fetch upstream $ git merge -X ours upstream/master
After this step, you will need to manually edit the top level CMakeLists.txt
to add the new subdirectory.
if(CMAKE_CUDA_COMPILER) add_subdirectory(w07-cuda-pt1) #add this line inside the if/endif block add_subdirectory(w07-cuda-pt2) endif()The setup from Monday should still work, so just a simple
make
will build the new code samples.
cd ~/cs40/examples/build make -j8 cd w07-cuda-pt2 ./juliaCPU ./juliaGPU