@@ -272,6 +272,31 @@ def test_sparse_dense_csr():
272
272
tvm .testing .assert_allclose (Y_tvm .asnumpy (), Y_np , atol = 1e-4 , rtol = 1e-4 )
273
273
274
274
275
+ def test_sparse_dense_csr_reverse ():
276
+ M , N , K , density = 1 , 17 , 47 , 0.2
277
+ X_np = np .random .randn (M , K ).astype ("float32" )
278
+ W_sp_np = sp .random (N , K , density = density , format = "csr" , dtype = "float32" )
279
+ W_np = W_sp_np .todense ()
280
+ Y_np = W_np .dot (X_np .T )
281
+
282
+ W_data = te .placeholder (shape = W_sp_np .data .shape , dtype = str (W_sp_np .data .dtype ))
283
+ W_indices = te .placeholder (shape = W_sp_np .indices .shape , dtype = str (W_sp_np .indices .dtype ))
284
+ W_indptr = te .placeholder (shape = W_sp_np .indptr .shape , dtype = str (W_sp_np .indptr .dtype ))
285
+ X = te .placeholder (shape = X_np .shape , dtype = str (X_np .dtype ))
286
+ Y = topi .nn .sparse_dense (X , W_data , W_indices , W_indptr , sparse_lhs = True )
287
+ s = te .create_schedule (Y .op )
288
+ func = tvm .build (s , [X , W_data , W_indices , W_indptr , Y ])
289
+ Y_tvm = tvm .nd .array (np .zeros (Y_np .shape , dtype = Y_np .dtype ))
290
+ func (
291
+ tvm .nd .array (X_np ),
292
+ tvm .nd .array (W_sp_np .data ),
293
+ tvm .nd .array (W_sp_np .indices ),
294
+ tvm .nd .array (W_sp_np .indptr ),
295
+ Y_tvm ,
296
+ )
297
+ tvm .testing .assert_allclose (Y_tvm .asnumpy (), Y_np , atol = 1e-4 , rtol = 1e-4 )
298
+
299
+
275
300
def test_sparse_transpose_csr ():
276
301
N , density = 1023 , 0.3
277
302
@@ -368,6 +393,31 @@ def test_sparse_dense_bsr_relu(ctx, target):
368
393
verify_sparse_dense_bsr (M , N , K , BS_R , BS_C , density , False , ctx , target )
369
394
370
395
396
+ def test_sparse_dense_bsr_reverse ():
397
+ M , N , K , BS_R , BS_C , density = 1 , 64 , 128 , 8 , 16 , 0.9
398
+ X_np = np .random .randn (M , K ).astype ("float32" )
399
+ W_sp_np = random_bsr_matrix (N , K , BS_R , BS_C , density = density , dtype = "float32" )
400
+ W_np = W_sp_np .todense ()
401
+ Y_np = W_np .dot (X_np .T )
402
+
403
+ W_data = te .placeholder (shape = W_sp_np .data .shape , dtype = str (W_sp_np .data .dtype ))
404
+ W_indices = te .placeholder (shape = W_sp_np .indices .shape , dtype = str (W_sp_np .indices .dtype ))
405
+ W_indptr = te .placeholder (shape = W_sp_np .indptr .shape , dtype = str (W_sp_np .indptr .dtype ))
406
+ X = te .placeholder (shape = X_np .shape , dtype = str (X_np .dtype ))
407
+ Y = topi .nn .sparse_dense (X , W_data , W_indices , W_indptr , sparse_lhs = True )
408
+ s = te .create_schedule (Y .op )
409
+ func = tvm .build (s , [X , W_data , W_indices , W_indptr , Y ])
410
+ Y_tvm = tvm .nd .array (np .zeros (Y_np .shape , dtype = Y_np .dtype ))
411
+ func (
412
+ tvm .nd .array (X_np ),
413
+ tvm .nd .array (W_sp_np .data ),
414
+ tvm .nd .array (W_sp_np .indices ),
415
+ tvm .nd .array (W_sp_np .indptr ),
416
+ Y_tvm ,
417
+ )
418
+ tvm .testing .assert_allclose (Y_tvm .asnumpy (), Y_np , atol = 1e-4 , rtol = 1e-4 )
419
+
420
+
371
421
@tvm .testing .uses_gpu
372
422
def test_sparse_dense_bsr_randomized ():
373
423
for _ in range (20 ):
@@ -480,3 +530,5 @@ def test_sparse_dense_padded_alter_op():
480
530
test_sparse_transpose_csr ()
481
531
test_sparse_dense_padded_cuda ()
482
532
test_sparse_dense_padded_alter_op ()
533
+ test_sparse_dense_csr_reverse ()
534
+ test_sparse_dense_bsr_reverse ()
0 commit comments