Skip to content

Commit

Permalink
Bug fixes
Browse files Browse the repository at this point in the history
- fix issue #2 - for this branch only.
- fix issue #8 - forgot to free d_rand_state2
  • Loading branch information
rogerallen committed Oct 12, 2020
1 parent fbdfafb commit e75548b
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions main.cu
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,11 @@ __global__ void render_init(int max_x, int max_y, curandState *rand_state) {
int j = threadIdx.y + blockIdx.y * blockDim.y;
if((i >= max_x) || (j >= max_y)) return;
int pixel_index = j*max_x + i;
//Each thread gets same seed, a different sequence number, no offset
curand_init(1984, pixel_index, 0, &rand_state[pixel_index]);
// Original: Each thread gets same seed, a different sequence number, no offset
// curand_init(1984, pixel_index, 0, &rand_state[pixel_index]);
// BUGFIX, see Issue#2: Each thread gets different seed, same sequence for
// performance improvement of about 2x!
curand_init(1984+pixel_index, 0, 0, &rand_state[pixel_index]);
}

__global__ void render(vec3 *fb, int max_x, int max_y, int ns, camera **cam, hitable **world, curandState *rand_state) {
Expand Down Expand Up @@ -217,6 +220,7 @@ int main() {
checkCudaErrors(cudaFree(d_world));
checkCudaErrors(cudaFree(d_list));
checkCudaErrors(cudaFree(d_rand_state));
checkCudaErrors(cudaFree(d_rand_state2));
checkCudaErrors(cudaFree(fb));

cudaDeviceReset();
Expand Down

0 comments on commit e75548b

Please sign in to comment.