mbrookhart opened a new pull request #7229:
URL: https://github.com/apache/tvm/pull/7229


   Thanks @trevor-m and @anijain2305 for finding this issue. Sometimes a model 
may propose 0 boxes, and the code had a place that ended up assigning 
uninitialized memory to valid_counts, which could cause memory access issues in 
NMS.
   
   The diff is kind of ugly, but this PR simply wraps the exclusive scan in 
this:
   
   ```
       with ib.if_scope(num_anchors > 0):
           # Old code
       with ib.else_scope():
           with ib.new_scope():
               bx = te.thread_axis("blockIdx.x")
               ib.scope_attr(bx, "thread_extent", batch_size)
               with ib.if_scope(bx < batch_size):
                   valid_count[bx] = 0
   ```
   Which runs the algorithm if there are boxes to check, and otherwise assigns 
valid_count to 0.
   
   Unfortunately, since the issue is randomly uninitialized memory getting 
assigned to valid_count, I haven't been able to write a unit test that 
consistently fails with the old code, so this just includes the change.


----------------------------------------------------------------
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:
[email protected]


Reply via email to