Skip to content

Commit b48050e

Browse files
Added test for similar for COO and BSR with custom types/dims
1 parent 4b626bf commit b48050e

3 files changed

Lines changed: 42 additions & 5 deletions

File tree

lib/cusparse/src/array.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -295,20 +295,20 @@ Base.similar(Mat::CuSparseMatrixCOO, dims::Tuple{Int, Int}) = similar(Mat, dims.
295295

296296
Base.similar(Mat::CuSparseArrayCSR) = CuSparseArrayCSR(copy(Mat.rowPtr), copy(Mat.colVal), similar(nonzeros(Mat)), size(Mat))
297297

298-
299-
function Base.similar(mat::CuSparseMatrixCOO, ::Type{T}, dims::Dims{2}) where {T}
298+
function Base.similar(mat::CuSparseMatrixCOO{Tv, Ti}, ::Type{T}, N::Int, M::Int) where {Tv, Ti, T}
300299
new_rowInd = similar(mat.rowInd)
301300
new_colInd = similar(mat.colInd)
302301
new_nzVal = similar(mat.nzVal, T)
303-
return CuSparseMatrixCOO{T, Ti}(new_rowInd, new_colInd, new_nzVal, dims)
302+
303+
return CuSparseMatrixCOO{T, Ti}(new_rowInd, new_colInd, new_nzVal, (N, M))
304304
end
305305

306-
function Base.similar(mat::CuSparseMatrixBSR{Tv, Ti}, ::Type{T}, dims::Dims{2}) where {Tv, Ti, T}
306+
function Base.similar(mat::CuSparseMatrixBSR{Tv, Ti}, ::Type{T}, N::Int, M::Int) where {Tv, Ti, T}
307307
new_rowPtr = similar(mat.rowPtr)
308308
new_colVal = similar(mat.colVal)
309309
new_nzVal = similar(mat.nzVal, T)
310310

311-
return CuSparseMatrixBSR{T, Ti}(new_rowPtr, new_colVal, new_nzVal, dims, mat.blockDim, mat.dir, mat.nnzb)
311+
return CuSparseMatrixBSR{T, Ti}(new_rowPtr, new_colVal, new_nzVal, (N, M), mat.blockDim, mat.dir, mat.nnzb)
312312
end
313313

314314
## array interface

lib/cusparse/test/construction.jl

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,4 +88,28 @@ if capability(device()) >= v"5.3"
8888
end
8989
end
9090
end
91+
92+
@testset "similar for COO and BSR with custom types/dims" begin
93+
row = CuVector{Cint}([1, 2, 3])
94+
col = CuVector{Cint}([1, 2, 3])
95+
val = CuVector{Float32}([1.0, 2.0, 3.0])
96+
coo_mat = CuSparseMatrixCOO(row, col, val, (3, 3))
97+
98+
coo_sim = similar(coo_mat, Float64, (3, 3))
99+
@test eltype(coo_sim) == Float64
100+
@test size(coo_sim) == (3, 3)
101+
@test typeof(coo_sim) <: CuSparseMatrixCOO
102+
103+
rowPtr = CuVector{Cint}([1, 2, 3])
104+
colVal = CuVector{Cint}([1, 2])
105+
valBSR = CuVector{Float32}([1.0, 2.0, 3.0, 4.0])
106+
bsr_mat = CuSparseMatrixBSR(rowPtr, colVal, valBSR, 2, 'R', 1, (4, 4))
107+
108+
bsr_sim = similar(bsr_mat, Float64, (4, 4))
109+
@test eltype(bsr_sim) == Float64
110+
@test size(bsr_sim) == (4, 4)
111+
@test typeof(bsr_sim) <: CuSparseMatrixBSR
112+
@test bsr_sim.blockDim == bsr_mat.blockDim
113+
end
114+
91115
end

test/core/device/intrinsics.jl

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,3 +338,16 @@ end
338338

339339
############################################################################################
340340

341+
@testset "intrinsic range metadata" begin
342+
# Create tiny kernels to isolate the x-dimension
343+
kernel_block() = CUDA.blockDim().x
344+
kernel_grid() = CUDA.gridDim().x
345+
346+
ir_block = sprint(io -> CUDA.code_llvm(io, kernel_block, Tuple{}; dump_module=true, raw=true))
347+
@test occursin("!range", ir_block)
348+
349+
ir_grid = sprint(io -> CUDA.code_llvm(io, kernel_grid, Tuple{}; dump_module=true, raw=true))
350+
@test !occursin("!range", ir_grid)
351+
end
352+
353+
############################################################################################

0 commit comments

Comments
 (0)