-
Notifications
You must be signed in to change notification settings - Fork 5
/
rand.yaml
55 lines (53 loc) · 1.34 KB
/
rand.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
meta:
comment: random number generator (LCG)
description: runmetal run rand.yaml
vars:
seedsize: 128
mult: 1024
program:
- source: |-
#include <metal_stdlib>
using namespace metal;
struct DataOut{
uint32_t data[{{mult}}];
};
kernel void rand32(device uint32_t *seed [[buffer(0)]],
device DataOut *outData [[buffer(1)]],
uint id [[thread_position_in_grid]]) {
for(int i=0; i<{{mult}}; i++){
uint32_t s = seed[id];
s = (s * 0x41c64e6d + 0x3039);
seed[id] = outData[id].data[i] = s;
}
}
buffer:
- name: input
type: buffer
mode: irandom
dtype: uint32
size: "{{seedsize}}"
- name: output
size: "{{seedsize*mult}}"
dtype: uint32
progn:
- type: compute
name: check
entrypoint: rand32
buffers:
- input
- output
options:
iterations: "{{seedsize}}"
- type: blit
name: memcpy
buffers:
- output
post-process:
- name: result
source: |-
log.info("result: %s", output)
log.info("max/min/avg/stdev=%d/%d/%f/%f, len=%d", numpy.max(output), numpy.min(output), numpy.average(output), numpy.std(output), len(output))
log.info("uniq: %d/%d", len(numpy.unique(output)), len(output))
buffers:
- name: output
dtype: uint32