Use finally to restore pointer mode to be original one (2)
@@ -141,7 +141,9 @@ def _iamaxmin(x, out, name):
result_dtype = 'i'
result_ptr, result, orig_mode = _setup_result_ptr(
handle, out, result_dtype)
+ try:
func(handle, x.size, x.data.ptr, 1, result_ptr)
+ finally:
cublas.setPointerMode(handle, orig_mode)
if out is None:
@@ -172,7 +174,9 @@ def asum(x, out=None):
result_dtype = dtype.lower()
result_ptr, result, orig_mode = _setup_result_ptr(
handle, out, result_dtype)
+ try:
func(handle, x.size, x.data.ptr, 1, result_ptr)
+ finally:
cublas.setPointerMode(handle, orig_mode)
if out is None:
@@ -203,7 +207,9 @@ def axpy(a, x, y):
handle = device.get_cublas_handle()
a, a_ptr, orig_mode = _setup_scalar_ptr(handle, a, dtype)
+ try:
func(handle, x.size, a_ptr, x.data.ptr, 1, y.data.ptr, 1)
+ finally:
cublas.setPointerMode(handle, orig_mode)
@@ -224,7 +230,9 @@ def dot(x, y, out=None):
result_dtype = dtype
result_ptr, result, orig_mode = _setup_result_ptr(
handle, out, result_dtype)
+ try:
func(handle, x.size, x.data.ptr, 1, y.data.ptr, 1, result_ptr)
+ finally:
cublas.setPointerMode(handle, orig_mode)
if out is None:
@@ -251,7 +259,9 @@ def dotu(x, y, out=None):
result_dtype = dtype
result_ptr, result, orig_mode = _setup_result_ptr(
handle, out, result_dtype)
+ try:
func(handle, x.size, x.data.ptr, 1, y.data.ptr, 1, result_ptr)
+ finally:
cublas.setPointerMode(handle, orig_mode)
if out is None:
@@ -278,7 +288,9 @@ def dotc(x, y, out=None):
result_dtype = dtype
result_ptr, result, orig_mode = _setup_result_ptr(
handle, out, result_dtype)
+ try:
func(handle, x.size, x.data.ptr, 1, y.data.ptr, 1, result_ptr)
+ finally:
cublas.setPointerMode(handle, orig_mode)
if out is None:
@@ -309,7 +321,9 @@ def nrm2(x, out=None):
result_dtype = dtype.lower()
result_ptr, result, orig_mode = _setup_result_ptr(
handle, out, result_dtype)
+ try:
func(handle, x.size, x.data.ptr, 1, result_ptr)
+ finally:
cublas.setPointerMode(handle, orig_mode)
if out is None:
@@ -341,7 +355,9 @@ def scal(a, x):
handle = device.get_cublas_handle()
a, a_ptr, orig_mode = _setup_scalar_ptr(handle, a, dtype)
+ try:
func(handle, x.size, a_ptr, x.data.ptr, 1)
+ finally:
cublas.setPointerMode(handle, orig_mode)
