diff options
| author | Stan Seibert <stan@mtrr.org> | 2011-10-21 16:53:05 -0400 |
|---|---|---|
| committer | tlatorre <tlatorre@uchicago.edu> | 2021-05-09 08:42:38 -0700 |
| commit | ce45e90e90f801bf7b523c97399b1986c8bfa97e (patch) | |
| tree | c6119e370e990d3a43cbd768f8d84d91c1a248e2 /chroma/cuda | |
| parent | 03d3afd7aab2df0f2ffb5a81bf862c7fd17b3b11 (diff) | |
| download | chroma-ce45e90e90f801bf7b523c97399b1986c8bfa97e.tar.gz chroma-ce45e90e90f801bf7b523c97399b1986c8bfa97e.tar.bz2 chroma-ce45e90e90f801bf7b523c97399b1986c8bfa97e.zip | |
Add a select function to GPUPhotons to extract a reduced list of photons that all have a particular interaction process code set. Handy for selection just the detected photons from a large list of photons.
Diffstat (limited to 'chroma/cuda')
| -rw-r--r-- | chroma/cuda/propagate.cu | 62 |
1 files changed, 61 insertions, 1 deletions
diff --git a/chroma/cuda/propagate.cu b/chroma/cuda/propagate.cu index fdcf532..87ba9f5 100644 --- a/chroma/cuda/propagate.cu +++ b/chroma/cuda/propagate.cu @@ -45,7 +45,67 @@ photon_duplicate(int first_photon, int nthreads, histories[target_photon_id] = p.history; } } - + +__global__ void +count_photons(int first_photon, int nthreads, unsigned int target_flag, + unsigned int *index_counter, + unsigned int *histories) +{ + int id = blockIdx.x*blockDim.x + threadIdx.x; + __shared__ unsigned int counter; + + if (threadIdx.x == 0) + counter = 0; + __syncthreads(); + + if (id < nthreads) { + int photon_id = first_photon + id; + + if (histories[photon_id] & target_flag) { + atomicAdd(&counter, 1); + } + + } + + __syncthreads(); + + if (threadIdx.x == 0) + atomicAdd(index_counter, counter); +} + +__global__ void +copy_photons(int first_photon, int nthreads, unsigned int target_flag, + unsigned int *index_counter, + float3 *positions, float3 *directions, + float *wavelengths, float3 *polarizations, + float *times, unsigned int *histories, + int *last_hit_triangles, + float3 *new_positions, float3 *new_directions, + float *new_wavelengths, float3 *new_polarizations, + float *new_times, unsigned int *new_histories, + int *new_last_hit_triangles) +{ + int id = blockIdx.x*blockDim.x + threadIdx.x; + + if (id >= nthreads) + return; + + int photon_id = first_photon + id; + + if (histories[photon_id] & target_flag) { + int offset = atomicAdd(index_counter, 1); + + new_positions[offset] = positions[photon_id]; + new_directions[offset] = directions[photon_id]; + new_polarizations[offset] = polarizations[photon_id]; + new_wavelengths[offset] = wavelengths[photon_id]; + new_times[offset] = times[photon_id]; + new_histories[offset] = histories[photon_id]; + new_last_hit_triangles[offset] = last_hit_triangles[photon_id]; + } +} + + __global__ void propagate(int first_photon, int nthreads, unsigned int *input_queue, unsigned int *output_queue, curandState *rng_states, |
