-
Notifications
You must be signed in to change notification settings - Fork 247
Change API introduced in "cuda-python" #849
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -30,8 +30,7 @@ | |
| import cuda.bindings.runtime as cudart | ||
|
|
||
|
|
||
| def call_cuda_function(function, *argv): | ||
| res = function(*argv) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do you need to change this place? Seems like the difference is where the CUDA function actually gets called (inside v.s. outside
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I only save my local changes, it's not real change. |
||
| def call_cuda_function(res): | ||
| err = res[0] | ||
| if isinstance(err, cudart.cudaError_t): | ||
| if err != cudart.cudaError_t.cudaSuccess: | ||
|
|
@@ -92,9 +91,10 @@ def __del__(self): | |
| return | ||
| prev_device = None | ||
| try: | ||
| prev_device = call_cuda_function(cudart.cudaGetDevice) | ||
| call_cuda_function(cudart.cudaSetDevice, self._device_id) | ||
| call_cuda_function(cudart.cudaFree, self._base_addr) | ||
| cuda_driver.cuInit(self._device_id) | ||
| prev_device = call_cuda_function(cudart.cudaGetDevice()) | ||
| call_cuda_function(cudart.cudaSetDevice(self._device_id)) | ||
| call_cuda_function(cudart.cudaFree(self._base_addr)) | ||
| finally: | ||
| if prev_device is not None: | ||
| maybe_set_device(prev_device) | ||
|
|
@@ -104,9 +104,10 @@ class CudaStream: | |
| def __init__(self, device_id): | ||
| prev_device = None | ||
| try: | ||
| prev_device = call_cuda_function(cudart.cudaGetDevice) | ||
| call_cuda_function(cudart.cudaSetDevice, device_id) | ||
| self._stream = call_cuda_function(cudart.cudaStreamCreate) | ||
| cuda_driver.cuInit(device_id) | ||
| prev_device = call_cuda_function(cudart.cudaGetDevice()) | ||
| call_cuda_function(cudart.cudaSetDevice(device_id)) | ||
| self._stream = call_cuda_function(cudart.cudaStreamCreate()) | ||
| finally: | ||
| if prev_device is not None: | ||
| maybe_set_device(prev_device) | ||
|
|
@@ -117,12 +118,13 @@ def __del__(self): | |
| if not hasattr(self, "_stream") or self._stream is None: | ||
| return | ||
| # [FIXME] __del__ is not the best place for releasing resources | ||
| call_cuda_function(cudart.cudaStreamDestroy, self._stream) | ||
| call_cuda_function(cudart.cudaStreamDestroy(self._stream)) | ||
| self._stream = None | ||
|
|
||
|
|
||
| def maybe_set_device(device_id): | ||
| device = call_cuda_function(cuda_driver.cuDeviceGet, device_id) | ||
| _, active = call_cuda_function(cuda_driver.cuDevicePrimaryCtxGetState, device) | ||
| cuda_driver.cuInit(device_id) | ||
| call_cuda_function(cuda_driver.cuDeviceGet(device_id)) | ||
| _, active = call_cuda_function(cuda_driver.cuDevicePrimaryCtxGetState(device_id)) | ||
| if active: | ||
| call_cuda_function(cudart.cudaSetDevice, device_id) | ||
| call_cuda_function(cudart.cudaSetDevice(device_id)) | ||
Uh oh!
There was an error while loading. Please reload this page.