-
Notifications
You must be signed in to change notification settings - Fork 0
/
util.go
52 lines (41 loc) · 979 Bytes
/
util.go
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
package cuda
import "github.com/barnex/cuda5/cu"
// CUDA Launch parameters. TODO: optimize?
var (
BlockSize = 512
TileX, TileY = 32, 32
MaxGridSize = 65535
)
// cuda launch configuration
type config struct {
Grid, Block cu.Dim3
}
// Make a 1D kernel launch configuration suited for N threads.
func make1DConf(N int) *config {
bl := cu.Dim3{X: BlockSize, Y: 1, Z: 1}
N2 := divUp(N, BlockSize) // N2 blocks left
NX := divUp(N2, MaxGridSize)
NY := divUp(N2, NX)
gr := cu.Dim3{X: NX, Y: NY, Z: 1}
return &config{gr, bl}
}
// Make a 3D kernel launch configuration suited for N threads.
func make3DConf(N [3]int) *config {
bl := cu.Dim3{X: TileX, Y: TileY, Z: 1}
NZ := N[0]
NY := divUp(N[1], TileY)
NX := divUp(N[2], TileX)
gr := cu.Dim3{X: NX, Y: NY, Z: NZ}
return &config{gr, bl}
}
// integer minimum
func iMin(a, b int) int {
if a < b {
return a
}
return b
}
// Integer division rounded up.
func divUp(x, y int) int {
return ((x - 1) / y) + 1
}