Skip to content

Commit

Permalink
refactor: formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
artemiipatov committed Dec 15, 2023
1 parent 39e36b0 commit b8696b7
Showing 1 changed file with 30 additions and 20 deletions.
50 changes: 30 additions & 20 deletions src/GraphBLAS-sharp.Backend/Operations/Kronecker.fs
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,8 @@ module internal Kronecker =

let mutable startIndex = 0

let value = clContext.CreateClCell Unchecked.defaultof<'a>
let value =
clContext.CreateClCell Unchecked.defaultof<'a>

for row in 0 .. rowCount - 1 do
let leftEdge, rightEdge = rowBoundaries.[row]
Expand All @@ -346,31 +347,31 @@ module internal Kronecker =

startIndex

let private countZeroElements
(clContext: ClContext)
workGroupSize
=
let private countZeroElements (clContext: ClContext) workGroupSize =

let countZeroElementsInRow =
<@ fun (ndRange: Range1D) (firstIndex: int) (lastIndex: int) (columnCount: int) (columns: ClArray<int>) (result: ClArray<int>) ->

let gid = ndRange.GlobalID0
let gid = ndRange.GlobalID0

let nnzInRow = lastIndex - firstIndex + 1
let nnzInRow = lastIndex - firstIndex + 1

if gid <= nnzInRow then
if gid <= nnzInRow then

if nnzInRow = 0 then
result.[0] <- columnCount
if nnzInRow = 0 then
result.[0] <- columnCount

elif gid = nnzInRow then
elif gid = nnzInRow then
result.[nnzInRow] <- columnCount - columns.[lastIndex] - 1

elif gid = 0 then
result.[0] <- columns.[firstIndex]
elif gid = 0 then
result.[0] <- columns.[firstIndex]

else
result.[gid] <- columns.[firstIndex + gid] - columns.[firstIndex + gid - 1] - 1 @>
else
result.[gid] <-
columns.[firstIndex + gid]
- columns.[firstIndex + gid - 1]
- 1 @>

let kernel = clContext.Compile countZeroElementsInRow

Expand All @@ -391,9 +392,15 @@ module internal Kronecker =
let ndRange =
Range1D.CreateValid(length, workGroupSize)

let result = clContext.CreateClArrayWithSpecificAllocationMode(DeviceOnly, length)
let result =
clContext.CreateClArrayWithSpecificAllocationMode(DeviceOnly, length)

queue.Post(
Msg.MsgSetArguments
(fun () ->
kernel.KernelFunc ndRange firstIndex lastIndex matrix.ColumnCount matrix.Columns result)
)

queue.Post(Msg.MsgSetArguments(fun () -> kernel.KernelFunc ndRange firstIndex lastIndex matrix.ColumnCount matrix.Columns result))
queue.Post(Msg.CreateRunMsg<_, _>(kernel))

zeroCounts.[row] <- result
Expand All @@ -408,9 +415,11 @@ module internal Kronecker =

let pairwise = ClArray.pairwise clContext workGroupSize

let mapInPlace = ClArray.mapInPlace <@ fun (a, b) -> (a, b - 1) @> clContext workGroupSize
let mapInPlace =
ClArray.mapInPlace <@ fun (a, b) -> (a, b - 1) @> clContext workGroupSize

let countZeroElements = countZeroElements clContext workGroupSize
let countZeroElements =
countZeroElements clContext workGroupSize

let insertNonZero = insertNonZero clContext workGroupSize op

Expand Down Expand Up @@ -446,7 +455,8 @@ module internal Kronecker =

let rowBoundaries = pairsOfRowPointers.ToHostAndFree queue

let zeroCounts = countZeroElements queue matrixLeft rowBoundaries
let zeroCounts =
countZeroElements queue matrixLeft rowBoundaries

let startIndex =
insertNonZero queue rowBoundaries matrixRight matrixLeft.Values leftColumns resultMatrix
Expand Down

0 comments on commit b8696b7

Please sign in to comment.