Skip to content
Snippets Groups Projects
Commit 89662377 authored by Yichao Yu's avatar Yichao Yu
Browse files

use similar structure with master

parent 44b178a2
No related branches found
No related tags found
No related merge requests found
......@@ -514,17 +514,6 @@ def _add_functionality():
self._arg_type_chars = arg_type_chars
_size_t_char = ({
8: 'Q',
4: 'L',
2: 'H',
1: 'B',
})[_cl._ffi.sizeof('size_t')]
_type_char_map = {
'n': _size_t_char.lower(),
'N': _size_t_char
}
del _size_t_char
def kernel_set_args(self, *args):
assert len(args) == self.num_args, (
"length of argument list (%d) and "
......@@ -539,20 +528,14 @@ def _add_functionality():
for i, arg in enumerate(args):
self.set_arg(i, arg)
else:
#from pyopencl._pvt_struct import pack
from struct import pack
from pyopencl._pvt_struct import pack
for i, (arg, arg_type_char) in enumerate(
zip(args, arg_type_chars)):
if not arg_type_char or arg_type_char == "V":
_arg = arg
elif arg_type_char == "F":
_arg = pack('f', arg.real) + pack('f', arg.imag)
elif arg_type_char == "D":
_arg = pack('d', arg.real) + pack('d', arg.imag)
if arg_type_char and arg_type_char != "V":
self.set_arg(i, pack(arg_type_char, arg))
else:
_arg = pack(_type_char_map.get(arg_type_char,
arg_type_char), arg)
self.set_arg(i, _arg)
self.set_arg(i, arg)
except LogicError, e:
if i is not None:
advice = ""
......
from __future__ import division
__copyright__ = """
Copyright (C) 2013 Marko Bencun
Copyright (C) 2014 Andreas Kloeckner
Copyright (C) 2014 Yichao Yu
"""
__license__ = """
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
"""
#import pyopencl._cl as _cl
import pyopencl.cffi_cl as _cl
from struct import pack as _pack
_size_t_char = ({
8: 'Q',
4: 'L',
2: 'H',
1: 'B',
})[_cl._ffi.sizeof('size_t')]
_type_char_map = {
'n': _size_t_char.lower(),
'N': _size_t_char
}
del _size_t_char
def pack(type_char, obj):
if type_char == 'F':
return _pack('f', obj.real) + _pack('f', obj.imag)
elif type_char == "D":
return _pack('d', obj.real) + _pack('d', obj.imag)
else:
return _pack(_type_char_map.get(type_char, type_char), obj)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment