Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
d55d34f
add: Gather
IgorErin Mar 12, 2023
a136bd3
add: Expand module
IgorErin Mar 13, 2023
f77b4d2
add: requiredRawsLengths test
IgorErin Mar 13, 2023
d22621e
wip: module Expand test
IgorErin Mar 13, 2023
9d25601
refactor: globalMap
IgorErin Mar 13, 2023
5479816
add: Expand stage
IgorErin Mar 13, 2023
be13d6e
add: Expand test
IgorErin Mar 16, 2023
890bdd1
merge: dev
IgorErin Mar 26, 2023
6da457b
add: reduceByKey2D
IgorErin Mar 27, 2023
66c2711
refactor: wip
IgorErin Apr 1, 2023
91a72e2
add: Gather tests
IgorErin Apr 3, 2023
b679650
wip: segments computing tests
IgorErin Apr 4, 2023
7e09219
wip: expand tests passed
IgorErin Apr 4, 2023
84fb950
wip: getUniqueBitmap{first/last} occurrence
IgorErin Apr 5, 2023
8ec7fd7
add: Scatter.firstOccurrence
IgorErin Apr 5, 2023
63037b6
spgemm: left filtering
IgorErin Apr 6, 2023
03e7e95
add: init gather
IgorErin Apr 6, 2023
6f02570
add: init scatter
IgorErin Apr 6, 2023
29c564c
add: scatter init value
IgorErin Apr 6, 2023
972b392
refactor: init in spgemm
IgorErin Apr 6, 2023
73d755f
refactor: deforestation in ClArray.choose
IgorErin Apr 6, 2023
f34e590
add: ClArray.choose2
IgorErin Apr 6, 2023
751ee68
add: filter after multiplication
IgorErin Apr 6, 2023
69be680
add: reduce by key option
IgorErin Apr 6, 2023
3f7c0bf
add: spgemm
IgorErin Apr 7, 2023
96c0c08
refactor: spgemm
IgorErin Apr 7, 2023
95fea31
refactor: duplication, allTests in Reduce
IgorErin Apr 7, 2023
c5fa0d0
refactor: ClArray.Free and *.FreeAndWait
IgorErin Apr 7, 2023
6ff1971
refactor: remove use in test
IgorErin Apr 7, 2023
048477d
refactor: formatting
IgorErin Apr 7, 2023
3703609
merge: dev
IgorErin Apr 7, 2023
4d26023
refactor: formatting
IgorErin Apr 7, 2023
cf7cc1d
refactor: expand endSize
IgorErin Apr 8, 2023
fdb9041
refactor: Scatter.test memory release
IgorErin Apr 8, 2023
a6ebc30
refactor: tests, names
IgorErin Apr 8, 2023
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
refactor: tests, names
  • Loading branch information
IgorErin committed Apr 8, 2023
commit a6ebc30e76573995f02cf905f1c54f21c5179a60
50 changes: 25 additions & 25 deletions src/GraphBLAS-sharp.Backend/Matrix/CSRMatrix/SpGEMM/Expand.fs
Original file line number Diff line number Diff line change
Expand Up @@ -139,75 +139,75 @@ module Expand =
let expandRowPointers =
Common.expandRowPointers clContext workGroupSize

let AGather = Gather.run clContext workGroupSize
let leftMatrixGather = Gather.run clContext workGroupSize

let BGather = Gather.run clContext workGroupSize
let rightMatrixGather = Gather.run clContext workGroupSize

fun (processor: MailboxProcessor<_>) lengths (segmentsPointers: Indices) (leftMatrix: ClMatrix.CSR<'a>) (rightMatrix: ClMatrix.CSR<'b>) ->

// Compute A positions
let APositions = zeroCreate processor DeviceOnly lengths
// Compute left matrix positions
let leftMatrixPositions = zeroCreate processor DeviceOnly lengths

idScatter processor segmentsPointers APositions
idScatter processor segmentsPointers leftMatrixPositions

(maxPrefixSum processor APositions 0)
(maxPrefixSum processor leftMatrixPositions 0)
.Free processor

// Compute B positions
let BPositions = create processor DeviceOnly lengths 1
// Compute right matrix positions
let rightMatrixPositions = create processor DeviceOnly lengths 1

let requiredBPointers =
let requiredRightMatrixPointers =
zeroCreate processor DeviceOnly leftMatrix.Columns.Length

gather processor leftMatrix.Columns rightMatrix.RowPointers requiredBPointers
gather processor leftMatrix.Columns rightMatrix.RowPointers requiredRightMatrixPointers

scatter processor segmentsPointers requiredBPointers BPositions
scatter processor segmentsPointers requiredRightMatrixPointers rightMatrixPositions

requiredBPointers.Free processor
requiredRightMatrixPointers.Free processor

// another way to get offsets ???
let offsets =
removeDuplicates processor segmentsPointers

segmentPrefixSum processor offsets.Length BPositions APositions offsets
segmentPrefixSum processor offsets.Length rightMatrixPositions leftMatrixPositions offsets

offsets.Free processor

// compute columns
let columns =
clContext.CreateClArrayWithSpecificAllocationMode(DeviceOnly, lengths)

gather processor BPositions rightMatrix.Columns columns
gather processor rightMatrixPositions rightMatrix.Columns columns

// compute rows
let ARows =
let leftMatrixRows =
expandRowPointers processor DeviceOnly leftMatrix.RowPointers leftMatrix.NNZ leftMatrix.RowCount

let rows =
clContext.CreateClArrayWithSpecificAllocationMode(DeviceOnly, lengths)

gather processor APositions ARows rows
gather processor leftMatrixPositions leftMatrixRows rows

ARows.Free processor
leftMatrixRows.Free processor

// compute leftMatrix values
let AValues =
// compute left matrix values
let leftMatrixValues =
clContext.CreateClArrayWithSpecificAllocationMode(DeviceOnly, lengths)

AGather processor APositions leftMatrix.Values AValues
leftMatrixGather processor leftMatrixPositions leftMatrix.Values leftMatrixValues

APositions.Free processor
leftMatrixPositions.Free processor

// compute right matrix values
let BValues =
let rightMatrixValues =
clContext.CreateClArrayWithSpecificAllocationMode(DeviceOnly, lengths)

BGather processor BPositions rightMatrix.Values BValues
rightMatrixGather processor rightMatrixPositions rightMatrix.Values rightMatrixValues

BPositions.Free processor
rightMatrixPositions.Free processor

// left, right matrix values, columns and rows indices
AValues, BValues, columns, rows
leftMatrixValues, rightMatrixValues, columns, rows

let sortByColumnsAndRows (clContext: ClContext) workGroupSize =

Expand Down
10 changes: 5 additions & 5 deletions tests/GraphBLAS-sharp.Tests/Common/Reduce/ReduceByKey.fs
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,17 @@ let processor = Context.defaultContext.Queue

let config = Utils.defaultConfig

let private getOffsets array =
let getOffsets array =
Array.map fst array
|> HostPrimitives.getUniqueBitmapFirstOccurrence
|> HostPrimitives.getBitPositions

let private getOffsets2D array =
let getOffsets2D array =
Array.map (fun (fst, snd, _) -> fst, snd) array
|> HostPrimitives.getUniqueBitmapFirstOccurrence
|> HostPrimitives.getBitPositions

let private checkResult isEqual actualKeys actualValues keys values reduceOp =
let checkResult isEqual actualKeys actualValues keys values reduceOp =

let expectedKeys, expectedValues =
HostPrimitives.reduceByKey keys values reduceOp
Expand All @@ -36,7 +36,7 @@ let private checkResult isEqual actualKeys actualValues keys values reduceOp =
"Values must the same"
|> Utils.compareArrays isEqual actualValues expectedValues

let private makeTest isEqual reduce reduceOp (arrayAndKeys: (int * 'a) []) =
let makeTest isEqual reduce reduceOp (arrayAndKeys: (int * 'a) []) =
let keys, values =
Array.sortBy fst arrayAndKeys |> Array.unzip

Expand All @@ -60,7 +60,7 @@ let private makeTest isEqual reduce reduceOp (arrayAndKeys: (int * 'a) []) =

checkResult isEqual actualKeys actualValues keys values reduceOp

let private createTestSequential<'a> (isEqual: 'a -> 'a -> bool) reduceOp reduceOpQ =
let createTestSequential<'a> (isEqual: 'a -> 'a -> bool) reduceOp reduceOpQ =

let reduce =
Reduce.ByKey.sequential context Utils.defaultWorkGroupSize reduceOpQ
Expand Down
2 changes: 1 addition & 1 deletion tests/GraphBLAS-sharp.Tests/Common/Scan/PrefixSum.fs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ let makeTest plus zero isEqual scan (array: 'a []) =
let (total: ClCell<_>) = scan q clArray zero

let actual = clArray.ToHostAndFree q
let actualSum = total.ToHostAndFree(q)
let actualSum = total.ToHostAndFree q
actual, actualSum

logger.debug (
Expand Down
4 changes: 1 addition & 3 deletions tests/GraphBLAS-sharp.Tests/Helpers.fs
Original file line number Diff line number Diff line change
Expand Up @@ -254,9 +254,7 @@ module HostPrimitives =
// add and filter
|> Array.map Some
|> Array.fold add None
|> function
| Some value -> value
| None -> zero
|> Option.defaultValue zero

let scanByKey scan keysAndValues =
Array.groupBy fst keysAndValues
Expand Down
14 changes: 7 additions & 7 deletions tests/GraphBLAS-sharp.Tests/Matrix/SpGeMM/Expand.fs
Original file line number Diff line number Diff line change
Expand Up @@ -67,23 +67,23 @@ let makeTest isZero testFun (leftArray: 'a [,], rightArray: 'a [,]) =
"Result pointers must be the same"
|> Expect.sequenceEqual actualPointers expectedPointers

let createTest<'a when 'a: struct> (isZero: 'a -> bool) testFun =
let createTest<'a when 'a: struct> (isZero: 'a -> bool) =

let testFun =
testFun context Utils.defaultWorkGroupSize
Expand.getSegmentPointers context Utils.defaultWorkGroupSize

makeTest isZero testFun
|> testPropertyWithConfig config $"test on {typeof<'a>}"

let getSegmentsTests =
[ createTest ((=) 0) Expand.getSegmentPointers
[ createTest ((=) 0)

if Utils.isFloat64Available context.ClDevice then
createTest ((=) 0.0) Expand.getSegmentPointers
createTest ((=) 0.0)

createTest ((=) 0f) Expand.getSegmentPointers
createTest ((=) false) Expand.getSegmentPointers
createTest ((=) 0uy) Expand.getSegmentPointers ]
createTest ((=) 0f)
createTest ((=) false)
createTest ((=) 0uy) ]
|> testList "get segment pointers"

let expand length segmentPointers (leftMatrix: Matrix.CSR<'a>) (rightMatrix: Matrix.CSR<'b>) =
Expand Down