Skip to content

Commit 41c095b

Browse files
committed
Method for array creation with flags
1 parent 7a400a7 commit 41c095b

2 files changed

Lines changed: 30 additions & 16 deletions

File tree

src/GraphBLAS-sharp.Backend/Common/ClArray.fs

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,27 @@
11
namespace GraphBLAS.FSharp.Backend
22

3-
open Brahma.FSharp.OpenCL
4-
open GraphBLAS.FSharp.Backend.Common
3+
open GraphBLAS.FSharp.Backend
54
open Brahma.FSharp
65
open Microsoft.FSharp.Quotations
76

87
module ClArray =
8+
type ClContext with
9+
member this.CreateClArrayWithGPUOnlyFlags(size: int) =
10+
this.CreateClArray(
11+
size,
12+
deviceAccessMode = DeviceAccessMode.ReadWrite,
13+
hostAccessMode = HostAccessMode.NotAccessible,
14+
allocationMode = AllocationMode.Default
15+
)
16+
17+
member this.CreateClArrayWithGPUOnlyFlags(array: 'a []) =
18+
this.CreateClArray(
19+
array,
20+
deviceAccessMode = DeviceAccessMode.ReadWrite,
21+
hostAccessMode = HostAccessMode.NotAccessible,
22+
allocationMode = AllocationMode.CopyHostPtr
23+
)
24+
925
let init (initializer: Expr<int -> 'a>) (clContext: ClContext) workGroupSize =
1026

1127
let init =
@@ -20,7 +36,8 @@ module ClArray =
2036

2137
fun (processor: MailboxProcessor<_>) (length: int) ->
2238
// TODO: Выставить нужные флаги
23-
let outputArray = clContext.CreateClArray(length)
39+
let outputArray =
40+
clContext.CreateClArrayWithGPUOnlyFlags(length)
2441

2542
let kernel = program.GetKernel()
2643

@@ -47,7 +64,8 @@ module ClArray =
4764
fun (processor: MailboxProcessor<_>) (length: int) (value: 'a) ->
4865
let value = clContext.CreateClCell(value)
4966

50-
let outputArray = clContext.CreateClArray(length)
67+
let outputArray =
68+
clContext.CreateClArrayWithGPUOnlyFlags(length)
5169

5270
let kernel = program.GetKernel()
5371

@@ -83,7 +101,7 @@ module ClArray =
83101
Range1D.CreateValid(inputArray.Length, workGroupSize)
84102

85103
let outputArray =
86-
clContext.CreateClArray(inputArray.Length, allocationMode = AllocationMode.Default)
104+
clContext.CreateClArrayWithGPUOnlyFlags inputArray.Length
87105

88106
let kernel = program.GetKernel()
89107

@@ -111,7 +129,7 @@ module ClArray =
111129
let outputArrayLength = inputArray.Length * count
112130

113131
let outputArray =
114-
clContext.CreateClArray(outputArrayLength, allocationMode = AllocationMode.Default)
132+
clContext.CreateClArrayWithGPUOnlyFlags outputArrayLength
115133

116134
let ndRange =
117135
Range1D.CreateValid(outputArray.Length, workGroupSize)
@@ -228,12 +246,7 @@ module ClArray =
228246
Range1D.CreateValid(inputLength, workGroupSize)
229247

230248
let bitmap =
231-
clContext.CreateClArray(
232-
inputLength,
233-
hostAccessMode = HostAccessMode.NotAccessible,
234-
deviceAccessMode = DeviceAccessMode.ReadWrite,
235-
allocationMode = AllocationMode.Default
236-
)
249+
clContext.CreateClArrayWithGPUOnlyFlags inputLength
237250

238251
let kernel = kernel.GetKernel()
239252

@@ -261,7 +274,7 @@ module ClArray =
261274
Range1D.CreateValid(inputArray.Length, workGroupSize)
262275

263276
let outputArray =
264-
clContext.CreateClArray(outputArraySize, allocationMode = AllocationMode.Default)
277+
clContext.CreateClArrayWithGPUOnlyFlags outputArraySize
265278

266279
let kernel = kernel.GetKernel()
267280

src/GraphBLAS-sharp.Backend/Vector/Vector.fs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ open Microsoft.FSharp.Quotations
77
open GraphBLAS.FSharp.Backend.Common
88
open GraphBLAS.FSharp.Backend.DenseVector
99
open GraphBLAS.FSharp.Backend.SparseVector
10+
open GraphBLAS.FSharp.Backend.ClArray
1011

1112
module Vector =
1213
let zeroCreate (clContext: ClContext) (workGroupSize: int) =
@@ -18,8 +19,8 @@ module Vector =
1819
| Sparse ->
1920
let vector =
2021
{ Context = clContext
21-
Indices = clContext.CreateClArray [| 0 |]
22-
Values = clContext.CreateClArray [| Unchecked.defaultof<'a> |]
22+
Indices = clContext.CreateClArrayWithGPUOnlyFlags [| 0 |]
23+
Values = clContext.CreateClArrayWithGPUOnlyFlags [| Unchecked.defaultof<'a> |]
2324
Size = size }
2425

2526
ClVectorSparse vector
@@ -45,7 +46,7 @@ module Vector =
4546
for i in 0 .. indices.Length - 1 do
4647
res.[indices.[i]] <- Some(values.[i])
4748

48-
ClVectorDense <| clContext.CreateClArray res
49+
ClVectorDense <| clContext.CreateClArrayWithGPUOnlyFlags res
4950

5051
let copy (clContext: ClContext) (workGroupSize: int) =
5152
let copy = ClArray.copy clContext workGroupSize

0 commit comments

Comments
 (0)