From 48550062440c5b7f1479ecbe17fd4b024a90fca2 Mon Sep 17 00:00:00 2001 From: Stan Seibert Date: Sat, 3 Sep 2011 09:19:55 -0400 Subject: GPU-based sampling from an arbitrary distribition. The sample_cdf() device function will draw random numbers from an arbitrary disribution given a cumulative distribution function in the form of a list of x,y points, beginning with y=0 and ending with y=1. For an example of how to convert a ROOT histogram to this form, see the unit test in test_sample_cdf.py --- tests/test_sample_cdf.cu | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 tests/test_sample_cdf.cu (limited to 'tests/test_sample_cdf.cu') diff --git a/tests/test_sample_cdf.cu b/tests/test_sample_cdf.cu new file mode 100644 index 0000000..1401772 --- /dev/null +++ b/tests/test_sample_cdf.cu @@ -0,0 +1,16 @@ +// -*-c++-*- +#include "random.h" + +extern "C" { + +__global__ void test_sample_cdf(int offset, int ncdf, + float *cdf_x, float *cdf_y, float *out) +{ + int id = blockDim.x * blockIdx.x + threadIdx.x; + curandState s; + curand_init(0, id, offset, &s); + + out[id] = sample_cdf(&s, ncdf, cdf_x, cdf_y); +} + +} -- cgit