Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ version = "0.5.0"

[deps]
ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4"
FiniteDifferences = "26cc04aa-876d-5657-8c51-4c34ba976000"
Libdl = "8f399da3-3557-5675-b5ff-fb832c97cbdb"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
MacroTools = "1914dd2f-81c6-5fcd-8719-6d5c9610ff09"
Expand All @@ -18,9 +17,8 @@ SuiteSparse = "4607b0f0-06f3-5cda-b6b1-a6196a1729e9"

[compat]
ChainRulesCore = "1"
FiniteDifferences = "0.12"
MacroTools = "0.5"
Preferences = "1"
SSGraphBLAS_jll = "6.0"
SSGraphBLAS_jll = "6.2.1"
SpecialFunctions = "2"
julia = "1.6"
18 changes: 9 additions & 9 deletions src/SuiteSparseGraphBLAS.jl
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ using SpecialFunctions: lgamma, gamma, erf, erfc
using Base.Broadcast
include("abstracts.jl")
include("libutils.jl")
include("lib/LibGraphBLAS.jl")
using .libgb
include("operators/libgbops.jl")

# Globals
include("lib/LibGraphBLAS_gen.jl")
using .LibGraphBLAS

include("operators/libgbops.jl")

include("types.jl")
include("gbtypes.jl")
include("types.jl")



include("constants.jl")
Expand Down Expand Up @@ -88,7 +88,7 @@ include("asjulia.jl")
include("spmgb/sparsemat.jl")

export SparseArrayCompat
export libgb
export LibGraphBLAS
export UnaryOps, BinaryOps, Monoids, Semirings #Submodules
export UnaryOp, BinaryOp, Monoid, Semiring #UDFs
export Descriptor #Types
Expand Down Expand Up @@ -124,19 +124,19 @@ function __init__()
#The artifact does dlopen for us.
libgraphblas_handle[] = SSGraphBLAS_jll.libgraphblas_handle
end
_load_globaltypes()
# We initialize GraphBLAS by giving it Julia's GC wrapped memory management functions.
# In the future this should hopefully allow us to do no-copy passing of arrays between Julia and SS:GrB.
# In the meantime it helps Julia respond to memory pressure from SS:GrB and finalize things in a timely fashion.
libgb.GxB_init(libgb.GrB_NONBLOCKING, cglobal(:jl_malloc), cglobal(:jl_calloc), cglobal(:jl_realloc), cglobal(:jl_free))
@wraperror LibGraphBLAS.GxB_init(LibGraphBLAS.GrB_NONBLOCKING, cglobal(:jl_malloc), cglobal(:jl_calloc), cglobal(:jl_realloc), cglobal(:jl_free))
gbset(:nthreads, Sys.CPU_THREADS ÷ 2)
# Eagerly load selectops constants.
_loadselectops()
ALL.p = load_global("GrB_ALL", LibGraphBLAS.GrB_Index)
# Set printing done by SuiteSparse:GraphBLAS to base-1 rather than base-0.
gbset(BASE1, 1)
atexit() do
# Finalize the lib, for now only frees a small internal memory pool.
libgb.GrB_finalize()
@wraperror LibGraphBLAS.GrB_finalize()
@static if artifact_or_path != "default"
dlclose(libgraphblas_handle[])
end
Expand Down
22 changes: 10 additions & 12 deletions src/asjulia.jl
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,11 @@ function asCSCVectors(f::Function, A::GBMatrix{T}; freeunpacked=false) where {T}
result = try
f(colptr, rowidx, values, A)
finally
println("I'm finally")
if freeunpacked
ccall(:jl_free, Cvoid, (Ptr{libgb.GrB_Index},), pointer(colptr))
ccall(:jl_free, Cvoid, (Ptr{libgb.GrB_Index},), pointer(rowidx))
ccall(:jl_free, Cvoid, (Ptr{LibGraphBLAS.GrB_Index},), pointer(colptr))
ccall(:jl_free, Cvoid, (Ptr{LibGraphBLAS.GrB_Index},), pointer(rowidx))
ccall(:jl_free, Cvoid, (Ptr{T},), pointer(values))
else
println("I repacked!")
_packcscmatrix!(A, colptr, rowidx, values)
end
end
Expand All @@ -52,8 +50,8 @@ function asCSRVectors(f::Function, A::GBMatrix{T}; freeunpacked=false) where {T}
f(rowptr, colidx, values, A)
finally
if freeunpacked
ccall(:jl_free, Cvoid, (Ptr{libgb.GrB_Index},), pointer(rowptr))
ccall(:jl_free, Cvoid, (Ptr{libgb.GrB_Index},), pointer(colidx))
ccall(:jl_free, Cvoid, (Ptr{LibGraphBLAS.GrB_Index},), pointer(rowptr))
ccall(:jl_free, Cvoid, (Ptr{LibGraphBLAS.GrB_Index},), pointer(colidx))
ccall(:jl_free, Cvoid, (Ptr{T},), pointer(values))
else
_packcsrmatrix!(A, rowptr, colidx, values)
Expand All @@ -64,13 +62,13 @@ end

function asSparseMatrixCSC(f::Function, A::GBMatrix{T}; freeunpacked=false) where {T}
colptr, rowidx, values = _unpackcscmatrix!(A)
array = SparseMatrixCSC{T, libgb.GrB_Index}(size(A, 1), size(A, 2), colptr, rowidx, values)
array = SparseMatrixCSC{T, LibGraphBLAS.GrB_Index}(size(A, 1), size(A, 2), colptr, rowidx, values)
result = try
f(array, A)
finally
if freeunpacked
ccall(:jl_free, Cvoid, (Ptr{libgb.GrB_Index},), pointer(colptr))
ccall(:jl_free, Cvoid, (Ptr{libgb.GrB_Index},), pointer(rowidx))
ccall(:jl_free, Cvoid, (Ptr{LibGraphBLAS.GrB_Index},), pointer(colptr))
ccall(:jl_free, Cvoid, (Ptr{LibGraphBLAS.GrB_Index},), pointer(rowidx))
ccall(:jl_free, Cvoid, (Ptr{T},), pointer(values))
else
_packcscmatrix!(A, colptr, rowidx, values)
Expand All @@ -81,13 +79,13 @@ end

function asSparseVector(f::Function, A::GBVector{T}; freeunpacked=false) where {T}
colptr, rowidx, values = _unpackcscmatrix!(A)
vector = SparseVector{T, libgb.GrB_Index}(size(A, 1), rowidx, values)
vector = SparseVector{T, LibGraphBLAS.GrB_Index}(size(A, 1), rowidx, values)
result = try
f(vector, A)
finally
if freeunpacked
ccall(:jl_free, Cvoid, (Ptr{libgb.GrB_Index},), pointer(colptr))
ccall(:jl_free, Cvoid, (Ptr{libgb.GrB_Index},), pointer(rowidx))
ccall(:jl_free, Cvoid, (Ptr{LibGraphBLAS.GrB_Index},), pointer(colptr))
ccall(:jl_free, Cvoid, (Ptr{LibGraphBLAS.GrB_Index},), pointer(rowidx))
ccall(:jl_free, Cvoid, (Ptr{T},), pointer(values))
else
_packcscmatrix!(A, colptr, rowidx, values)
Expand Down
20 changes: 0 additions & 20 deletions src/chainrules/chainruleutils.jl
Original file line number Diff line number Diff line change
@@ -1,27 +1,7 @@
using FiniteDifferences
import LinearAlgebra
import ChainRulesCore: frule, rrule
using ChainRulesCore
const RealOrComplex = Union{Real, Complex}

#Required for ChainRulesTestUtils
function FiniteDifferences.to_vec(M::GBMatrix)
x, back = FiniteDifferences.to_vec(Matrix(M))
function backtomat(xvec)
M2 = GBMatrix(back(xvec))
return mask(M2, M; structural=true)
end
return x, backtomat
end

function FiniteDifferences.to_vec(v::GBVector)
x, back = FiniteDifferences.to_vec(Vector(v))
function backtovec(xvec)
v2 = GBVector(back(xvec))
return mask(v2, v; structural=true)
end
return x, backtovec
end

# LinearAlgebra.norm doesn't like the nothings.
LinearAlgebra.norm(A::GBArray, p::Real=2) = norm(nonzeros(A), p)
14 changes: 8 additions & 6 deletions src/constants.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ const GBVecOrMat{T} = Union{GBVector{T}, GBMatrix{T}}
const GBMatOrTranspose{T} = Union{GBMatrix{T}, Transpose{T, GBMatrix{T}}}
const GBVecOrTranspose{T} = Union{GBVector{T}, Transpose{T, GBVector{T}}}
const GBArray{T} = Union{GBVecOrTranspose{T}, GBMatOrTranspose{T}}
const ptrtogbtype = Dict{Ptr, AbstractGBType}()
const ptrtogbtype = IdDict{Ptr, GBType}()

const GrBOp = Union{
libgb.GrB_Monoid,
libgb.GrB_UnaryOp,
libgb.GrB_Semiring,
libgb.GrB_BinaryOp,
libgb.GxB_SelectOp
LibGraphBLAS.GrB_Monoid,
LibGraphBLAS.GrB_UnaryOp,
LibGraphBLAS.GrB_Semiring,
LibGraphBLAS.GrB_BinaryOp,
LibGraphBLAS.GxB_SelectOp
}

const TypedOp = Union{
Expand All @@ -32,3 +32,5 @@ const OperatorUnion = Union{
AbstractOp,
GrBOp
}

const ALL = GBAllType(C_NULL)
Loading