wkcn commented on issue #12823: Is it necessary to wait CUDA stream when 
calling `WaitToRead` or `WaitToWrite`?
URL: 
https://github.com/apache/incubator-mxnet/issues/12823#issuecomment-431878342
 
 
   Sorry, there is a bug in my project.
   I use Python Code to call `cudaSetDevice` and kernel function, like that:
   ```python
   class CFuncDef:
       [...]
       def __call__(self, arg_datas, arg_types, dev_id):
           if dev_id is None:
               ctx = 'cpu'
           else:
               set_device(dev_id)
               ctx = gpu_ctx_name
           # function loader
           func = self.loader(self, arg_types, ctx, **self.loader_kwargs)
           return func(*arg_datas)
   ```
   `func` is a ctypes reference of a CUDA kernel function.
   The function `CFuncDef.__call__` will be called in MXNet Custom Operator.
   However, the device ID may be changed between calling `set_device` and 
`func(*arg_datas)` because of asynchronous execution. It causes the problem 
`access illegal memory`.
   
   Calling `WaitToRead` or `WaitToWrite` is enough.
   
   Solved it.
   Thank you!

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


With regards,
Apache Git Services

Reply via email to