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 2020/07/22 23:27:16 UTC

[GitHub] [incubator-tvm] trevor-m commented on a change in pull request #6108: Fix CUDA Compute Function For `get_valid_counts` and `nms`

trevor-m commented on a change in pull request #6108:
URL: https://github.com/apache/incubator-tvm/pull/6108#discussion_r459138745



##########
File path: tests/python/relay/test_op_level5.py
##########
@@ -270,9 +270,9 @@ def verify_get_valid_counts(dshape, score_threshold, id_index, score_index):
             intrp = relay.create_executor("debug", ctx=ctx, target=target)
             out = intrp.evaluate(func)(np_data)
             tvm.testing.assert_allclose(out[0].asnumpy(), np_out1, rtol=1e-3, atol=1e-04)
-            # get_valid_count for cuda, opencl doesn't do data rearrangement
-            if target in ['cuda', 'opencl']:
-                return
+            # get_valid_count for opencl doesn't do data rearrangement
+            if target in ['opencl']:

Review comment:
       OpenCL shares the cuda implementation, so you can enable this test too.

##########
File path: topi/python/topi/cuda/nms.py
##########
@@ -93,44 +93,41 @@ def get_valid_counts_ir(data, valid_count, out, out_indices,
     valid_count = ib.buffer_ptr(valid_count)
     out = ib.buffer_ptr(out)
     out_indices = ib.buffer_ptr(out_indices)
-    atomic_add_return = ib.allocate(
-        valid_count.dtype, (1,), name='atomic_add_return', scope='local')
     one_count = tvm.tir.const(1, dtype=valid_count.dtype)
     one = tvm.tir.const(1, dtype=out.dtype)
     score_threshold = tvm.ir.make_node(
         "FloatImm", dtype="float32", value=score_threshold)
     id_index = tvm.ir.make_node("IntImm", dtype="int32", value=id_index)
     score_index = tvm.ir.make_node("IntImm", dtype="int32", value=score_index)
 
-    max_threads = int(tvm.target.Target.current(
-        allow_none=False).max_num_threads)
-    nthread_tx = max_threads
-    nthread_bx = batch_size * num_anchors // max_threads + 1
+    nthread_tx = batch_size
+    nthread_bx = 1
     tx = te.thread_axis("threadIdx.x")
     bx = te.thread_axis("blockIdx.x")
     ib.scope_attr(tx, "thread_extent", nthread_tx)
     ib.scope_attr(bx, "thread_extent", nthread_bx)
-    tid = bx * max_threads + tx
-    idxd = tvm.tir.indexdiv
-
-    # initialize valid_count
-    with ib.if_scope(tid < batch_size):
-        valid_count[tid] = 0
-    with ib.if_scope(tid < batch_size * num_anchors):
-        i = idxd(tid, num_anchors)
+    tid = tx
+
+    # each thread process one batch
+    valid_count[tid] = 0
+    data_base_ind = tid * num_anchors * elem_length
+    ind_base_ind = tid * num_anchors
+    with ib.for_range(0, num_anchors) as anchor_ind:
+        with ib.for_range(0, elem_length) as k:
+            out[data_base_ind + anchor_ind * elem_length + k] = -one
+        out_indices[ind_base_ind + anchor_ind] = -one_count
+
+    with ib.for_range(0, num_anchors) as anchor_ind:
         with ib.if_scope(
-                tvm.tir.all(data[tid * elem_length + score_index] > score_threshold,
-                            tvm.tir.any(id_index < 0, data[tid * elem_length + id_index] >= 0))):
-            atomic_add_return[0] = atomic_add(tvm.tir.call_intrin("handle", "tir.address_of",

Review comment:
       Since we are no longer using atomic_add, should we remove those intrinsic definitions?




----------------------------------------------------------------
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