You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tvm.apache.org by GitBox <gi...@apache.org> on 2019/11/19 18:53:35 UTC

[GitHub] [incubator-tvm] tmoreau89 commented on a change in pull request #4369: [Runtime] Add cusparse for sparse dense

tmoreau89 commented on a change in pull request #4369: [Runtime] Add cusparse for sparse dense
URL: https://github.com/apache/incubator-tvm/pull/4369#discussion_r348106742
 
 

 ##########
 File path: topi/tests/python/test_topi_sparse.py
 ##########
 @@ -218,22 +220,42 @@ def test_dense():
 
 
 def test_sparse_dense_csr():
-    M, N, K, density = 1, 17, 47, 0.2
-    X_np = np.random.randn(M, K).astype("float32")
+    M, N, K, density = 1, 100, 128, 0.1
+    X_np = np.random.uniform(size=(M, K)).astype("float32")
     W_sp_np = sp.random(N, K, density=density, format='csr', dtype="float32")
-    W_np = W_sp_np.todense()
+    W_np = W_sp_np.todense().astype("float32")
     Y_np = X_np.dot(W_np.T)
 
-    W_data = tvm.placeholder(shape=W_sp_np.data.shape, dtype=str(W_sp_np.data.dtype))
-    W_indices = tvm.placeholder(shape=W_sp_np.indices.shape, dtype=str(W_sp_np.indices.dtype))
-    W_indptr = tvm.placeholder(shape=W_sp_np.indptr.shape, dtype=str(W_sp_np.indptr.dtype))
     X = tvm.placeholder(shape=X_np.shape, dtype=str(X_np.dtype))
-    Y = topi.nn.sparse_dense(X, W_data, W_indices, W_indptr)
-    s = tvm.create_schedule(Y.op)
-    func = tvm.build(s, [X, W_data, W_indices, W_indptr, Y])
-    Y_tvm = tvm.ndarray.array(np.zeros(Y_np.shape, dtype=Y_np.dtype))
-    func(tvm.ndarray.array(X_np), tvm.ndarray.array(W_sp_np.data), tvm.ndarray.array(W_sp_np.indices), tvm.ndarray.array(W_sp_np.indptr), Y_tvm)
-    tvm.testing.assert_allclose(Y_tvm.asnumpy(), Y_np, atol=1e-4, rtol=1e-4)
+    W_data = tvm.placeholder(shape=W_sp_np.data.shape, 
+                             dtype=str(W_sp_np.data.dtype))
+    W_indices = tvm.placeholder(shape=W_sp_np.indices.shape, 
+                                dtype=str(W_sp_np.indices.dtype))
+    W_indptr = tvm.placeholder(shape=W_sp_np.indptr.shape, 
+                               dtype=str(W_sp_np.indptr.dtype))
+    def check_device(device):
+        ctx = tvm.context(device, 0)
+        if not ctx.exist:
+            print("Skip because %s is not enabled" % device)
+            return
+        print("Running on target: %s" % device)
+
+        with tvm.target.create(device):
+            Y = topi.nn.sparse_dense(X, W_data, W_indices, W_indptr)
+            s = topi.generic.schedule_sparse_dense([Y])
+
+        func = tvm.build(s, [X, W_data, W_indices, W_indptr, Y], 
+                         device)
+        Y_tvm = tvm.ndarray.array(np.zeros(Y_np.shape, dtype=Y_np.dtype), ctx)
+        func(tvm.ndarray.array(X_np, ctx), 
+             tvm.ndarray.array(W_sp_np.data, ctx), 
+             tvm.ndarray.array(W_sp_np.indices, ctx), 
+             tvm.ndarray.array(W_sp_np.indptr, ctx), 
+             Y_tvm)
+        tvm.testing.assert_allclose(Y_tvm.asnumpy(), Y_np, atol=1e-4, rtol=1e-4)
+
+    for device in ["llvm", "cuda", "cuda -libs=cusparse"]:
+        check_device(device)
 
 Review comment:
   I was referring to turning on the `USE_CUSPARSE` flag when building the CI docker image: https://github.com/apache/incubator-tvm/blob/master/docker/install/install_tvm_gpu.sh#L31
   

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services