Skip to content

Commit

Permalink
intp->uintp and flake8 cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
inducer committed Sep 17, 2014
1 parent 854ba9c commit 70c3584
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 24 deletions.
6 changes: 3 additions & 3 deletions pycuda/driver.py
Expand Up @@ -147,7 +147,7 @@ def _build_arg_buf(args):
format += "%ds" % arg.itemsize
else:
try:
gpudata = np.intp(arg.gpudata)
gpudata = np.uintp(arg.gpudata)
except AttributeError:
raise TypeError("invalid type on parameter #%d (0-based)" % i)
else:
Expand Down Expand Up @@ -252,7 +252,7 @@ def function_prepare_pre_v4(func, arg_types, block=None,
elif isinstance(arg_type, str):
func.arg_format += arg_type
else:
func.arg_format += np.dtype(np.intp).char
func.arg_format += np.dtype(np.uintp).char

from pycuda._pvt_struct import calcsize
func._param_set_size(calcsize(func.arg_format))
Expand Down Expand Up @@ -432,7 +432,7 @@ def function_prepare(func, arg_types, texrefs=[]):
elif isinstance(arg_type, str):
func.arg_format += arg_type
else:
func.arg_format += np.dtype(np.intp).char
func.arg_format += np.dtype(np.uintp).char

return func

Expand Down
24 changes: 13 additions & 11 deletions pycuda/elementwise.py
Expand Up @@ -127,9 +127,9 @@ def get_elwise_kernel_and_types(arguments, operation,

if use_range:
arguments.extend([
ScalarArg(np.intp, "start"),
ScalarArg(np.intp, "stop"),
ScalarArg(np.intp, "step"),
ScalarArg(np.uintp, "start"),
ScalarArg(np.uintp, "stop"),
ScalarArg(np.uintp, "step"),
])
else:
arguments.append(ScalarArg(np.uintp, "n"))
Expand Down Expand Up @@ -242,7 +242,7 @@ def get_take_kernel(dtype, idx_dtype, vec_count=1):

args = [VectorArg(idx_dtype, "idx")] + [
VectorArg(dtype, "dest"+str(i))for i in range(vec_count)] + [
ScalarArg(np.intp, "n")
ScalarArg(np.uintp, "n")
]
preamble = "#include <pycuda-helpers.hpp>\n\n" + "\n".join(
"texture <%s, 1, cudaReadModeElementType> tex_src%d;" % (ctx["tex_tp"], i)
Expand Down Expand Up @@ -273,11 +273,11 @@ def get_take_put_kernel(dtype, idx_dtype, with_offsets, vec_count=1):
VectorArg(idx_dtype, "gmem_src_idx"),
] + [
VectorArg(dtype, "dest%d" % i)
for i in range(vec_count)
for i in range(vec_count)
] + [
ScalarArg(idx_dtype, "offset%d" % i)
for i in range(vec_count) if with_offsets
] + [ScalarArg(np.intp, "n")]
for i in range(vec_count) if with_offsets
] + [ScalarArg(np.uintp, "n")]

preamble = "#include <pycuda-helpers.hpp>\n\n" + "\n".join(
"texture <%s, 1, cudaReadModeElementType> tex_src%d;" % (ctx["tex_tp"], i)
Expand Down Expand Up @@ -320,11 +320,11 @@ def get_put_kernel(dtype, idx_dtype, vec_count=1):
VectorArg(idx_dtype, "gmem_dest_idx"),
] + [
VectorArg(dtype, "dest%d" % i)
for i in range(vec_count)
for i in range(vec_count)
] + [
VectorArg(dtype, "src%d" % i)
for i in range(vec_count)
] + [ScalarArg(np.intp, "n")]
for i in range(vec_count)
] + [ScalarArg(np.uintp, "n")]

body = (
"%(idx_tp)s dest_idx = gmem_dest_idx[i];\n" % ctx
Expand Down Expand Up @@ -451,6 +451,7 @@ def get_binary_func_kernel(func, dtype_x, dtype_y, dtype_z):
"z[i] = %s(x[i], y[i])" % func,
func+"_kernel")


@context_dependent_memoize
def get_binary_func_scalar_kernel(func, dtype_x, dtype_y, dtype_z):
return get_elwise_kernel(
Expand All @@ -462,8 +463,9 @@ def get_binary_func_scalar_kernel(func, dtype_x, dtype_y, dtype_z):
"z[i] = %s(x[i], y)" % func,
func+"_kernel")


def get_binary_minmax_kernel(func, dtype_x, dtype_y, dtype_z, use_scalar):
if not np.float64 in [dtype_x, dtype_y]:
if np.float64 not in [dtype_x, dtype_y]:
func = func + "f"

from pytools import any
Expand Down
22 changes: 12 additions & 10 deletions test/test_driver.py
Expand Up @@ -76,7 +76,7 @@ def test_simple_kernel_2(self):
# now try with offsets
dest = np.zeros_like(a)
multiply_them(
drv.Out(dest), np.intp(a_gpu)+a.itemsize, b_gpu,
drv.Out(dest), np.uintp(a_gpu)+a.itemsize, b_gpu,
block=(399, 1, 1))

assert la.norm((dest[:-1]-a[1:]*b[:-1])) == 0
Expand All @@ -95,7 +95,7 @@ def test_vector_types(self):
a = gpuarray.vec.make_float3(1, 2, 3)
dest = np.empty((400), gpuarray.vec.float3)

set_them(drv.Out(dest), a, block=(400,1,1))
set_them(drv.Out(dest), a, block=(400, 1, 1))
assert (dest == a).all()

@mark_cuda_test
Expand Down Expand Up @@ -217,14 +217,15 @@ def test_multiple_2d_textures(self):
mtx_tex = mod.get_texref("mtx_tex")
mtx2_tex = mod.get_texref("mtx2_tex")

shape = (3,4)
shape = (3, 4)
a = np.random.randn(*shape).astype(np.float32)
b = np.random.randn(*shape).astype(np.float32)
drv.matrix_to_texref(a, mtx_tex, order="F")
drv.matrix_to_texref(b, mtx2_tex, order="F")

dest = np.zeros(shape, dtype=np.float32)
copy_texture(drv.Out(dest),
copy_texture(
drv.Out(dest),
block=shape+(1,),
texrefs=[mtx_tex, mtx2_tex]
)
Expand Down Expand Up @@ -267,8 +268,8 @@ def test_multichannel_2d_texture(self):
texrefs=[mtx_tex]
)
reshaped_a = a.transpose(1, 2, 0)
#print reshaped_a
#print dest
# print reshaped_a
# print dest
assert la.norm(dest-reshaped_a) == 0

@mark_cuda_test
Expand Down Expand Up @@ -299,12 +300,13 @@ def test_multichannel_linear_texture(self):
mtx_tex.set_format(drv.array_format.FLOAT, 4)

dest = np.zeros(shape+(channels,), dtype=np.float32)
copy_texture(drv.Out(dest),
copy_texture(
drv.Out(dest),
block=shape+(1,),
texrefs=[mtx_tex]
)
#print a
#print dest
# print a
# print dest
assert la.norm(dest-a) == 0

@mark_cuda_test
Expand All @@ -326,7 +328,7 @@ def test_large_smem(self):
import pycuda.gpuarray as gpuarray
arg = gpuarray.zeros((n,), dtype=np.float32)

kernel(arg, block=(1,1,1,), )
kernel(arg, block=(1, 1, 1,), )

@mark_cuda_test
def test_bitlog(self):
Expand Down

0 comments on commit 70c3584

Please sign in to comment.