forked from SparseLinearAlgebra/GraphBLAS-sharp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUtils.fs
36 lines (27 loc) · 1.15 KB
/
Utils.fs
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
namespace GraphBLAS.FSharp.Backend.Common
module internal Utils =
let floorToPower2 =
fun x -> x ||| (x >>> 1)
>> fun x -> x ||| (x >>> 2)
>> fun x -> x ||| (x >>> 4)
>> fun x -> x ||| (x >>> 8)
>> fun x -> x ||| (x >>> 16)
>> fun x -> x - (x >>> 1)
let ceilToPower2 =
fun x -> x - 1
>> fun x -> x ||| (x >>> 1)
>> fun x -> x ||| (x >>> 2)
>> fun x -> x ||| (x >>> 4)
>> fun x -> x ||| (x >>> 8)
>> fun x -> x ||| (x >>> 16)
>> fun x -> x + 1
let divUp x y = x / y + (if x % y = 0 then 0 else 1)
let divUpClamp x y left right = min (max (divUp x y) left) right
let floorToMultiple multiple x = x / multiple * multiple
let ceilToMultiple multiple x = ((x - 1) / multiple + 1) * multiple
let getClArrayOfValueTypeSize<'a when 'a: struct> localMemorySize = localMemorySize / sizeof<'a>
//Option type in C is represented as structure with additional integer field
let getClArrayOfOptionTypeSize<'a> localMemorySize =
localMemorySize
/ (sizeof<int> + sizeof<'a>
|> ceilToMultiple (max sizeof<'a> sizeof<int>))