-
Notifications
You must be signed in to change notification settings - Fork 5
/
pi.yaml
49 lines (48 loc) · 1.16 KB
/
pi.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
meta:
comment: π by monte carlo
description: runmetal run pi.yaml
vars:
sampleM: 128
program:
- source: |-
#include <metal_stdlib>
using namespace metal;
kernel void monte_carlo(const device float2 *inPoints [[buffer(0)]],
device bool *outBools [[buffer(1)]],
uint id [[thread_position_in_grid]]) {
const float2 location = inPoints[id];
const float x = location.x;
const float y = location.y;
outBools[id] = (sqrt((x * x) + (y * y)) < 1.0) ? true : false;
}
entrypoint:
- name: monte_carlo
buffer:
- name: input
type: buffer
mode: random
dtype: float32
size: "{{sampleM*2}}m"
- name: output
size: "{{sampleM}}m"
dtype: bool8
progn:
- type: compute
name: check
entrypoint: monte_carlo
buffers:
- input
- output
options:
iterations: "{{sampleM}}m"
- type: blit
name: memcpy
buffers:
- output
post-process:
- name: result
source: |-
log.info("pi = %f, n = %d", numpy.sum(output == True)/(len(output))*4, len(output))
buffers:
- name: output
dtype: bool8