Skip to content
Switch branches/tags
This branch is up to date with master.

Latest commit


Git stats


Failed to load latest commit information.
Latest commit message
Commit time

Ray Tracing in One Weekend in CUDA

This is yet another Ray Tracing in One Weekend clone, but this time using CUDA instead of C++. CUDA can be used to speed up the code. For example, on my machine, the C++ code renders the test image in 90 seconds. The CUDA accelerated code renders the image in about 7 seconds.

Initial coding started in May, 2018 and was posted to the NVIDIA Developer blog November 5, 2018:


Peter Shirley has written a few ebooks about Ray Tracing. You can find out more at Note that as of April, 2018 the books are pay what you wish and 50% of the proceeds go towards not-for-profit programming education organizations. They are also available for $3 each on Amazon as a Kindle download.

This repository contains code for converting the first ray tracer ebook "Ray Tracing in one Weekend" from C++ to CUDA. By changing to CUDA, depending on your CPU and GPU you can see speedups of 10x or more! UPDATE: see Issue #2 for a further 2x improvement!

Before coding the ray tracer in CUDA, I recommend that you code the ray tracer in C++, first. You should understand the concepts presented in a serial language well, then translate this knowledge to CUDA. In fact, since CUDA uses C++, much of your code can be reused.

The C++ code that this repository is based on is at As of January, 2020, the book and code are being updated and improved at This repository has not been changed to match these changes. The code matches the original book from 2016 which you can still download from Further, I am basing this on the repo at which has each chapter as a separate git branch. This is very handy for checking out the code at each chapter.

Chapter List

Here are links to the git branch for each Chapter. If you look at the you'll see some hints about what needed to be done. See the Makefile for the standard targets. Note that you'll want to adjust the GENCODE_FLAGS in the CUDA Makefiles for your specific graphics card architecture.

The master branch has the code as Peter Shirley presented it in C++. I added a Makefile so you can make out.jpg and compare the runtime to CUDA. To build variants that use CUDA, check out one of these branches. E.g. git checkout ch01_output_cuda


Basic process (after Chapter 3) was:

# checkout original code & create a cuda branch
git checkout origin/chyy_yyy
git checkout chyy_yyy
git branch -m chyy_yyy_cuda
git mv
# grab previous chapters code as a starting point
cp chapterxx/* .
# edit & fix code
# checkin code
# save current code for next chapter
mkdir chapteryy
cp * chapteryy


The code for the ebook Ray Tracing in One Weekend by Peter Shirley translated to CUDA by Roger Allen. This work is in the public domain.



No releases published


No packages published