mattboran / CudaRT

Photorealistic CPU or GPU (NVidia only) rendering engine written in C++/CUDA.
3 stars 0 forks source link

Sampler Struct #21

Closed mattboran closed 5 years ago

mattboran commented 5 years ago

For consistency between CPU and GPU versions, consider using the following


struct Sampler {
    __host__ __device__ virtual float getNextFloat() { return rand() / (RAND_MAX + 1.f); }
};

struct ParallelSampler : Sampler { 
    curandState* p_curandState;
    __host__ __device__ virtual float getNextFloat() { return curand_uniform(p_curandState); }
};```
mattboran commented 5 years ago

Can't do this. Try a templatized version?

mattboran commented 5 years ago

Solution was posted to reddit: https://www.reddit.com/r/CUDA/comments/adnzcb/using_c_templates_or_some_other_mechanism_to/

And stackoverflow: https://stackoverflow.com/questions/54115284/how-to-use-macros-or-c-templates-to-allow-reusable-code-in-both-host-and-devic