本文整理汇总了Python中pycuda._pvt_struct.pack函数的典型用法代码示例。如果您正苦于以下问题:Python pack函数的具体用法?Python pack怎么用?Python pack使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了pack函数的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: function_prepared_async_call_pre_v4
def function_prepared_async_call_pre_v4(func, grid, block, stream, *args, **kwargs):
if isinstance(block, tuple):
func._set_block_shape(*block)
else:
from warnings import warn
warn("Not passing the block size to prepared_async_call is deprecated as of "
"version 2011.1.", DeprecationWarning, stacklevel=2)
args = (stream,) + args
stream = block
shared_size = kwargs.pop("shared_size", None)
if shared_size is not None:
func._set_shared_size(shared_size)
if kwargs:
raise TypeError("unknown keyword arguments: "
+ ", ".join(kwargs.iterkeys()))
from pycuda._pvt_struct import pack
func._param_setv(0, pack(func.arg_format, *args))
for texref in func.texrefs:
func.param_set_texref(texref)
if stream is None:
func._launch_grid(*grid)
else:
grid_x, grid_y = grid
func._launch_grid_async(grid_x, grid_y, stream)
示例2: _build_arg_buf
def _build_arg_buf(args):
handlers = []
arg_data = []
format = ""
for i, arg in enumerate(args):
if isinstance(arg, np.number):
arg_data.append(arg)
format += arg.dtype.char
elif isinstance(arg, (DeviceAllocation, PooledDeviceAllocation)):
arg_data.append(int(arg))
format += "P"
elif isinstance(arg, ArgumentHandler):
handlers.append(arg)
arg_data.append(int(arg.get_device_alloc()))
format += "P"
elif isinstance(arg, np.ndarray):
arg_data.append(arg)
format += "%ds" % arg.nbytes
else:
try:
gpudata = np.intp(arg.gpudata)
except AttributeError:
raise TypeError("invalid type on parameter #%d (0-based)" % i)
else:
# for gpuarrays
arg_data.append(int(gpudata))
format += "P"
from pycuda._pvt_struct import pack
return handlers, pack(format, *arg_data)
示例3: function_prepared_timed_call_pre_v4
def function_prepared_timed_call_pre_v4(func, grid, block, *args, **kwargs):
if isinstance(block, tuple):
func._set_block_shape(*block)
else:
from warnings import warn
warn("Not passing the block size to prepared_timed_call is deprecated as of "
"version 2011.1.", DeprecationWarning, stacklevel=2)
args = (block,) + args
shared_size = kwargs.pop("shared_size", None)
if shared_size is not None:
func._set_shared_size(shared_size)
if kwargs:
raise TypeError("unknown keyword arguments: "
+ ", ".join(kwargs.iterkeys()))
from pycuda._pvt_struct import pack
func._param_setv(0, pack(func.arg_format, *args))
for texref in func.texrefs:
func.param_set_texref(texref)
start = Event()
end = Event()
start.record()
func._launch_grid(*grid)
end.record()
def get_call_time():
end.synchronize()
return end.time_since(start)*1e-3
return get_call_time
示例4: function_prepared_async_call
def function_prepared_async_call(func, grid, block, stream, *args, **kwargs):
if isinstance(block, tuple):
func._set_block_shape(*block)
else:
from warnings import warn
warn(
"Not passing the block size to prepared_async_call is deprecated as of " "version 2011.1.",
DeprecationWarning,
stacklevel=2,
)
args = (stream,) + args
stream = block
shared_size = kwargs.pop("shared_size", 0)
if kwargs:
raise TypeError("unknown keyword arguments: " + ", ".join(kwargs.iterkeys()))
from pycuda._pvt_struct import pack
arg_buf = pack(func.arg_format, *args)
for texref in func.texrefs:
func.param_set_texref(texref)
func._launch_kernel(grid, block, arg_buf, shared_size, stream)
示例5: function_prepared_timed_call
def function_prepared_timed_call(func, grid, block, *args, **kwargs):
if isinstance(block, tuple):
func._set_block_shape(*block)
else:
from warnings import warn
warn("Not passing the block size to prepared_timed_call is deprecated as of "
"version 2011.1.", DeprecationWarning, stacklevel=2)
args = (block,) + args
from pycuda._pvt_struct import pack
func._param_setv(0, pack(func.arg_format, *args))
for texref in func.texrefs:
func.param_set_texref(texref)
start = Event()
end = Event()
start.record()
func._launch_grid(*grid)
end.record()
def get_call_time():
end.synchronize()
return end.time_since(start)*1e-3
return get_call_time
示例6: function_prepared_async_call
def function_prepared_async_call(func, grid, block, stream, *args, **kwargs):
if isinstance(block, tuple):
func._set_block_shape(*block)
else:
from warnings import warn
warn(
"Not passing the block size to prepared_async_call is deprecated as of " "version 2011.1.",
DeprecationWarning,
stacklevel=2,
)
args = (stream,) + args
stream = block
from pycuda._pvt_struct import pack
func._param_setv(0, pack(func.arg_format, *args))
for texref in func.texrefs:
func.param_set_texref(texref)
if stream is None:
func._launch_grid(*grid)
else:
grid_x, grid_y = grid
func._launch_grid_async(grid_x, grid_y, stream)
示例7: function_prepared_call
def function_prepared_call(func, grid, *args):
from pycuda._pvt_struct import pack
func.param_setv(0, pack(func.arg_format, *args))
for texref in func.texrefs:
func.param_set_texref(texref)
func.launch_grid(*grid)
示例8: function_prepared_async_call
def function_prepared_async_call(func, grid, stream, *args):
from pycuda._pvt_struct import pack
func.param_setv(0, pack(func.arg_format, *args))
for texref in func.texrefs:
func.param_set_texref(texref)
if stream is None:
func.launch_grid(*grid)
else:
grid_x, grid_y = grid
func.launch_grid_async(grid_x, grid_y, stream)
示例9: function_prepared_timed_call
def function_prepared_timed_call(func, grid, *args):
from pycuda._pvt_struct import pack
func.param_setv(0, pack(func.arg_format, *args))
for texref in func.texrefs:
func.param_set_texref(texref)
start = Event()
end = Event()
start.record()
func.launch_grid(*grid)
end.record()
def get_call_time():
end.synchronize()
return end.time_since(start)*1e-3
return get_call_time
示例10: function_param_set
def function_param_set(func, *args):
try:
import numpy
except ImportError:
numpy = None
handlers = []
arg_data = []
format = ""
for i, arg in enumerate(args):
if numpy is not None and isinstance(arg, numpy.number):
arg_data.append(arg)
format += arg.dtype.char
elif isinstance(arg, (DeviceAllocation, PooledDeviceAllocation)):
arg_data.append(int(arg))
format += "P"
elif isinstance(arg, ArgumentHandler):
handlers.append(arg)
arg_data.append(int(arg.get_device_alloc()))
format += "P"
elif isinstance(arg, buffer):
arg_data.append(arg)
format += "s"
else:
try:
gpudata = arg.gpudata
except AttributeError:
raise TypeError("invalid type on parameter #%d (0-based)" % i)
else:
# for gpuarrays
arg_data.append(int(gpudata))
format += "P"
from pycuda._pvt_struct import pack
buf = pack(format, *arg_data)
func.param_setv(0, buf)
func.param_set_size(len(buf))
return handlers
示例11: function_prepared_timed_call
def function_prepared_timed_call(func, grid, block, *args, **kwargs):
shared_size = kwargs.pop("shared_size", 0)
if kwargs:
raise TypeError("unknown keyword arguments: "
+ ", ".join(kwargs.iterkeys()))
from pycuda._pvt_struct import pack
arg_buf = pack(func.arg_format, *args)
for texref in func.texrefs:
func.param_set_texref(texref)
start = Event()
end = Event()
start.record()
func._launch_kernel(grid, block, arg_buf, shared_size, None)
end.record()
def get_call_time():
end.synchronize()
return end.time_since(start)*1e-3
return get_call_time