OpenQMC API
Loading...
Searching...
No Matches
sampler.h
Go to the documentation of this file.
1// SPDX-License-Identifier: Apache-2.0
2// Copyright Contributors to the OpenQMC Project.
3
6
7#pragma once
8
9#include "float.h" // NOLINT: false positive
10#include "gpu.h"
11#include "range.h"
12
13#include <cassert>
14#include <cstddef>
15#include <cstdint>
16
68
69namespace oqmc
70{
71
109template <typename Impl>
111{
112 // Dimensions per pattern.
113 static constexpr auto maxDrawValue = 4;
114
115 // Prevent value-construction.
117
118 // Implemention type.
119 Impl impl;
120
121 public:
129 static constexpr std::size_t cacheSize = Impl::cacheSize;
130
153 static void initialiseCache(void* cache);
154
160 /*AUTO_DEFINED*/ SamplerInterface() = default;
161
179 OQMC_HOST_DEVICE SamplerInterface(int x, int y, int frame, int index,
180 const void* cache);
181
202
229 int index) const;
230
256 int index) const;
257
282 OQMC_HOST_DEVICE SamplerInterface newDomainChain(int key, int index) const;
283
298 template <int Size>
299 OQMC_HOST_DEVICE void drawSample(std::uint32_t sample[Size]) const;
300
310 template <int Size>
311 OQMC_HOST_DEVICE void drawSample(std::uint32_t range,
312 std::uint32_t sample[Size]) const;
313
322 template <int Size>
323 OQMC_HOST_DEVICE void drawSample(float sample[Size]) const;
324
339 template <int Size>
340 OQMC_HOST_DEVICE void drawRnd(std::uint32_t rnd[Size]) const;
341
351 template <int Size>
352 OQMC_HOST_DEVICE void drawRnd(std::uint32_t range,
353 std::uint32_t rnd[Size]) const;
354
363 template <int Size>
364 OQMC_HOST_DEVICE void drawRnd(float rnd[Size]) const;
365};
366
367template <typename Impl>
369{
370 Impl::initialiseCache(cache);
371}
372
373template <typename Impl>
375{
376}
377
378template <typename Impl>
380 const void* cache)
381 : impl(x, y, frame, index, cache)
382{
383 assert(index >= 0);
384}
385
386template <typename Impl>
388{
389 return {impl.newDomain(key)};
390}
391
392template <typename Impl>
394 int index) const
395{
396 assert(size > 0);
397 assert(index >= 0);
398
399 return {impl.newDomainSplit(key, size, index)};
400}
401
402template <typename Impl>
404 int index) const
405{
406 assert(index >= 0);
407
408 return {impl.newDomainDistrib(key, index)};
409}
410
411template <typename Impl>
413 int index) const
414{
415 assert(index >= 0);
416
417 return {impl.newDomain(key).newDomain(index)};
418}
419
420template <typename Impl>
421template <int Size>
423{
424 static_assert(Size >= 0, "Draw size greater or equal to zero.");
425 static_assert(Size <= maxDrawValue, "Draw size less or equal to max.");
426
427 impl.template drawSample<Size>(sample);
428}
429
430template <typename Impl>
431template <int Size>
433 std::uint32_t sample[Size]) const
434{
435 assert(range > 0);
436
437 std::uint32_t integerSample[Size];
439
440 for(int i = 0; i < Size; ++i)
441 {
443 }
444}
445
446template <typename Impl>
447template <int Size>
449{
450 std::uint32_t integerSample[Size];
452
453 for(int i = 0; i < Size; ++i)
454 {
456 }
457}
458
459template <typename Impl>
460template <int Size>
461void SamplerInterface<Impl>::drawRnd(std::uint32_t rnd[Size]) const
462{
463 static_assert(Size >= 0, "Draw size greater or equal to zero.");
464 static_assert(Size <= maxDrawValue, "Draw size less or equal to max.");
465
466 impl.template drawRnd<Size>(rnd);
467}
468
469template <typename Impl>
470template <int Size>
472 std::uint32_t rnd[Size]) const
473{
474 assert(range > 0);
475
476 std::uint32_t integerRnd[Size];
478
479 for(int i = 0; i < Size; ++i)
480 {
482 }
483}
484
485template <typename Impl>
486template <int Size>
488{
489 std::uint32_t integerRnd[Size];
491
492 for(int i = 0; i < Size; ++i)
493 {
495 }
496}
497
498} // namespace oqmc
#define OQMC_HOST_DEVICE
Definition gpu.h:13
SamplerInterface newDomainSplit(int key, int size, int index) const
Derive a split sampler object with a local and a global distribution.
Definition sampler.h:393
static constexpr std::size_t cacheSize
Required allocation size of the cache.
Definition sampler.h:129
static void initialiseCache(void *cache)
Initialise the cache allocation.
Definition sampler.h:368
SamplerInterface newDomain(int key) const
Derive a sampler object as a new domain.
Definition sampler.h:387
SamplerInterface newDomainDistrib(int key, int index) const
Derive a split sampler object with a local distribution.
Definition sampler.h:403
void drawRnd(std::uint32_t rnd[Size]) const
Draw integer pseudo random values from domain.
Definition sampler.h:461
void drawSample(std::uint32_t sample[Size]) const
Draw integer sample values from domain.
Definition sampler.h:422
SamplerInterface()=default
Construct an invalid sampler object.
SamplerInterface newDomainChain(int key, int index) const
Derive a split sampler object with a global distribution.
Definition sampler.h:412
Public sampler API.
Definition sampler.h:111
EncodeKey decodeBits16(std::uint16_t value)
Decode a value back into a key.
Definition encode.h:81
constexpr std::uint32_t uintToRange(std::uint32_t value, std::uint32_t range)
Compute an unsigned integer within 0-bounded half-open range.
Definition range.h:40
float uintToFloat(std::uint32_t value)
Convert an integer into a [0, 1) float.
Definition float.h:47
Definition bntables.h:21