GeNN  4.9.0
GPU enhanced Neuronal Networks (GeNN)
philox432.h
Go to the documentation of this file.
1 
2  /*
3  ***********************************************************************
4  Copyright (c) 2015 Advanced Micro Devices, Inc.
5  All rights reserved.
6 
7  Redistribution and use in source and binary forms, with or without
8  modification, are permitted provided that the following conditions
9  are met:
10 
11  1. Redistributions of source code must retain the above copyright
12  notice, this list of conditions and the following disclaimer.
13 
14  2. Redistributions in binary form must reproduce the above copyright
15  notice, this list of conditions and the following disclaimer in the
16  documentation and/or other materials provided with the distribution.
17 
18  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22  HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 
30  ***********************************************************************
31  */
32 
33 /* @file Philox432.h
34 * @brief Specific interface for the Philox432 generator
35 * @see clRNG_template.h
36 */
37 
38 #pragma once
39 #ifndef PHILOX432_H
40 #define PHILOX432_H
41 
42 #include <clRNG/clRNG.h>
43 #include <stdio.h>
44 
45 
46 /* @brief State type of a Philox432 stream
47 *
48 * The state is a seed consisting of a 128bits counter
49 *
50 * @see clrngStreamState
51 */
52 
53 typedef struct clrngPhilox432SB_ {
54  cl_uint msb, lsb; //most significant bits, and the least significant bits
56 
57 typedef struct clrngPhilox432Counter_ {
60 
61 
62 typedef struct {
63  cl_uint key[2]; // 64-bit key
64  clrngPhilox432Counter ctr; // 128 bits counter
65  cl_uint deck[4]; // this table hold the 4x32 generated uint from philox4x32(ctr,kry) function
66  cl_uint deckIndex; //the index of actual pregenerated integer to give to the user
68 
69 
71  union {
72  struct {
74  };
75  struct {
79  };
80  };
81 };
82 
87 
93 
94 
95 #ifdef __cplusplus
96 extern "C" {
97 #endif
98 
103 
108 
113 
118 
123 
127  CLRNGAPI clrngPhilox432Stream* clrngPhilox432AllocStreams(size_t count, size_t* bufSize, clrngStatus* err);
128 
133 
138 
143 
147  CLRNGAPI clrngStatus clrngPhilox432CopyOverStreams(size_t count, clrngPhilox432Stream* destStreams, const clrngPhilox432Stream* srcStreams);
148 
153 
154 #define clrngPhilox432RandomU01 _CLRNG_TAG_FPTYPE(clrngPhilox432RandomU01)
155 #define clrngPhilox432RandomInteger _CLRNG_TAG_FPTYPE(clrngPhilox432RandomInteger)
156 #define clrngPhilox432RandomU01Array _CLRNG_TAG_FPTYPE(clrngPhilox432RandomU01Array)
157 #define clrngPhilox432RandomIntegerArray _CLRNG_TAG_FPTYPE(clrngPhilox432RandomIntegerArray)
158 
165 
169  CLRNGAPI cl_int clrngPhilox432RandomInteger(clrngPhilox432Stream* stream, cl_int i, cl_int j);
170  CLRNGAPI cl_int clrngPhilox432RandomInteger_cl_float (clrngPhilox432Stream* stream, cl_int i, cl_int j);
171  CLRNGAPI cl_int clrngPhilox432RandomInteger_cl_double(clrngPhilox432Stream* stream, cl_int i, cl_int j);
172 
177  CLRNGAPI clrngStatus clrngPhilox432RandomU01Array_cl_float (clrngPhilox432Stream* stream, size_t count, cl_float * buffer);
178  CLRNGAPI clrngStatus clrngPhilox432RandomU01Array_cl_double(clrngPhilox432Stream* stream, size_t count, cl_double* buffer);
179 
183  CLRNGAPI clrngStatus clrngPhilox432RandomIntegerArray(clrngPhilox432Stream* stream, cl_int i, cl_int j, size_t count, cl_int* buffer);
184  CLRNGAPI clrngStatus clrngPhilox432RandomIntegerArray_cl_float (clrngPhilox432Stream* stream, cl_int i, cl_int j, size_t count, cl_int* buffer);
185  CLRNGAPI clrngStatus clrngPhilox432RandomIntegerArray_cl_double(clrngPhilox432Stream* stream, cl_int i, cl_int j, size_t count, cl_int* buffer);
186 
191 
196 
201 
205  CLRNGAPI clrngPhilox432Stream* clrngPhilox432MakeSubstreams(clrngPhilox432Stream* stream, size_t count, size_t* bufSize, clrngStatus* err);
206 
211 
215  CLRNGAPI clrngStatus clrngPhilox432AdvanceStreams(size_t count, clrngPhilox432Stream* streams, cl_int e, cl_int c);
216 
220 #ifdef CLRNG_SINGLE_PRECISION
221 #define clrngPhilox432DeviceRandomU01Array(...) clrngPhilox432DeviceRandomU01Array_(__VA_ARGS__, CL_TRUE)
222 #else
223 #define clrngPhilox432DeviceRandomU01Array(...) clrngPhilox432DeviceRandomU01Array_(__VA_ARGS__, CL_FALSE)
224 #endif
225 
229  CLRNGAPI clrngStatus clrngPhilox432DeviceRandomU01Array_(size_t streamCount, cl_mem streams,
230  size_t numberCount, cl_mem outBuffer, cl_uint numQueuesAndEvents,
231  cl_command_queue* commQueues, cl_uint numWaitEvents,
232  const cl_event* waitEvents, cl_event* outEvents, cl_bool singlePrecision);
233 
238 
239 
240 #if 0
241  CLRNGAPI clrngPhilox432Stream* clrngPhilox432GetStreamByIndex(clrngPhilox432Stream* stream, cl_uint index);
242 #endif
243 
244 
245 #ifdef __cplusplus
246 }
247 #endif
248 
249 
250 
251 #endif
#define clrngPhilox432RandomInteger
Definition: philox432.h:155
Library definitions common to all RNG&#39;s.
CLRNGAPI clrngPhilox432Stream * clrngPhilox432AllocStreams(size_t count, size_t *bufSize, clrngStatus *err)
Definition: philox432.c:168
clrngPhilox432Counter ctr
Definition: philox432.h:64
struct clrngPhilox432Counter_ clrngPhilox432Counter
CLRNGAPI clrngStatus clrngPhilox432DeviceRandomU01Array_(size_t streamCount, cl_mem streams, size_t numberCount, cl_mem outBuffer, cl_uint numQueuesAndEvents, cl_command_queue *commQueues, cl_uint numWaitEvents, const cl_event *waitEvents, cl_event *outEvents, cl_bool singlePrecision)
Definition: philox432.c:488
CLRNGAPI clrngStatus clrngPhilox432RewindSubstreams(size_t count, clrngPhilox432Stream *streams)
Definition: device/philox432.c.h:204
CLRNGAPI clrngStatus clrngPhilox432RandomIntegerArray_cl_double(clrngPhilox432Stream *stream, cl_int i, cl_int j, size_t count, cl_int *buffer)
clrngPhilox432StreamState initial
Definition: philox432.h:77
clrngPhilox432SB L
Definition: philox432.h:58
CLRNGAPI clrngStatus clrngPhilox432RandomIntegerArray_cl_float(clrngPhilox432Stream *stream, cl_int i, cl_int j, size_t count, cl_int *buffer)
CLRNGAPI clrngPhilox432Stream * clrngPhilox432CopyStreams(size_t count, const clrngPhilox432Stream *streams, clrngStatus *err)
Definition: philox432.c:252
enum clrngStatus_ clrngStatus
Error codes.
Definition: philox432.h:57
cl_uint lsb
Definition: philox432.h:54
CLRNGAPI clrngStatus clrngPhilox432WriteStreamInfo(const clrngPhilox432Stream *stream, FILE *file)
Definition: philox432.c:291
CLRNGAPI cl_float clrngPhilox432RandomU01_cl_float(clrngPhilox432Stream *stream)
CLRNGAPI clrngStatus clrngPhilox432RewindStreams(size_t count, clrngPhilox432Stream *streams)
Definition: device/philox432.c.h:181
CLRNGAPI clrngPhilox432Stream * clrngPhilox432CreateStreams(clrngPhilox432StreamCreator *creator, size_t count, size_t *bufSize, clrngStatus *err)
Definition: philox432.c:234
CLRNGAPI cl_int clrngPhilox432RandomInteger_cl_float(clrngPhilox432Stream *stream, cl_int i, cl_int j)
clrngPhilox432StreamState current
Definition: philox432.h:76
#define _CLRNG_FPTYPE
Definition: clRNG.h:314
CLRNGAPI clrngStatus clrngPhilox432DestroyStreams(clrngPhilox432Stream *streams)
Definition: philox432.c:193
cl_uint msb
Definition: philox432.h:54
CLRNGAPI clrngPhilox432StreamCreator * clrngPhilox432CopyStreamCreator(const clrngPhilox432StreamCreator *creator, clrngStatus *err)
Definition: philox432.c:82
clrngPhilox432StreamState substream
Definition: philox432.h:78
CLRNGAPI clrngStatus clrngPhilox432ChangeStreamsSpacing(clrngPhilox432StreamCreator *creator, cl_int e, cl_int c)
Definition: philox432.c:139
CLRNGAPI clrngStatus clrngPhilox432AdvanceStreams(size_t count, clrngPhilox432Stream *streams, cl_int e, cl_int c)
Definition: philox432.c:472
Definition: philox432.c:44
#define clrngPhilox432RandomU01
Definition: philox432.h:154
CLRNGAPI cl_int clrngPhilox432RandomInteger_cl_double(clrngPhilox432Stream *stream, cl_int i, cl_int j)
CLRNGAPI clrngStatus clrngPhilox432RandomU01Array_cl_float(clrngPhilox432Stream *stream, size_t count, cl_float *buffer)
#define clrngPhilox432RandomU01Array
Definition: philox432.h:156
CLRNGAPI clrngPhilox432Stream * clrngPhilox432MakeSubstreams(clrngPhilox432Stream *stream, size_t count, size_t *bufSize, clrngStatus *err)
Definition: philox432.c:273
CLRNGAPI clrngStatus clrngPhilox432CreateOverStreams(clrngPhilox432StreamCreator *creator, size_t count, clrngPhilox432Stream *streams)
Definition: philox432.c:219
CLRNGAPI clrngStatus clrngPhilox432RandomU01Array_cl_double(clrngPhilox432Stream *stream, size_t count, cl_double *buffer)
#define CLRNGAPI
Definition: clRNG.h:326
Definition: philox432.h:53
Definition: philox432.h:62
CLRNGAPI clrngStatus clrngPhilox432RewindStreamCreator(clrngPhilox432StreamCreator *creator)
Definition: philox432.c:113
CLRNGAPI clrngStatus clrngPhilox432MakeOverSubstreams(clrngPhilox432Stream *stream, size_t count, clrngPhilox432Stream *substreams)
Definition: device/philox432.c.h:242
cl_uint deckIndex
Definition: philox432.h:66
CLRNGAPI clrngStatus clrngPhilox432CopyOverStreams(size_t count, clrngPhilox432Stream *destStreams, const clrngPhilox432Stream *srcStreams)
Definition: device/philox432.c.h:72
#define clrngPhilox432RandomIntegerArray
Definition: philox432.h:157
CLRNGAPI cl_double clrngPhilox432RandomU01_cl_double(clrngPhilox432Stream *stream)
CLRNGAPI clrngStatus clrngPhilox432DestroyStreamCreator(clrngPhilox432StreamCreator *creator)
Definition: philox432.c:106
Definition: philox432.h:70
CLRNGAPI clrngStatus clrngPhilox432ForwardToNextSubstreams(size_t count, clrngPhilox432Stream *streams)
Definition: device/philox432.c.h:228
struct clrngPhilox432SB_ clrngPhilox432SB
CLRNGAPI clrngStatus clrngPhilox432SetBaseCreatorState(clrngPhilox432StreamCreator *creator, const clrngPhilox432StreamState *baseState)
Definition: philox432.c:121