Skip to content
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

Experimental upgrade for v2.2.0 #278

Draft
wants to merge 42 commits into
base: 33-v2.1.0.1
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
c95dbec
Merge pull request #767 from kmaehashi/fix-dependency-docs
niboshi Nov 21, 2017
c758157
Merge pull request #769 from kmaehashi/fix-typo-cache
niboshi Nov 21, 2017
4f9c59e
Merge pull request #512 from okuta/improve-cudnn
niboshi Nov 10, 2017
464b178
Merge pull request #770 from niboshi/bp-767-fix-dependency-docs
kmaehashi Nov 21, 2017
b302247
Merge pull request #771 from niboshi/bp-769-fix-typo-cache
kmaehashi Nov 21, 2017
58dca59
Merge pull request #774 from kmaehashi/test-argminmax-tie
niboshi Nov 24, 2017
a310ab9
Merge pull request #776 from niboshi/bp-774-test-argminmax-tie
kmaehashi Nov 24, 2017
873479b
Merge pull request #777 from kmaehashi/fix-dump-filename
niboshi Nov 24, 2017
61be331
Merge pull request #778 from niboshi/bp-777-fix-dump-filename
kmaehashi Nov 24, 2017
601b1dd
Merge pull request #787 from hvy/fix-doc-missing-arg
unnonouno Nov 27, 2017
95cd84f
Merge pull request #790 from unnonouno/v2-fix-doc-missing-arg
hvy Nov 27, 2017
29f55e4
Merge pull request #749 from okuta/fix-stack
unnonouno Nov 29, 2017
45a00d4
Merge pull request #798 from unnonouno/v2-fix-stack
hvy Nov 29, 2017
ac93d73
Merge pull request #797 from kmaehashi/fix-gitignore
okuta Nov 30, 2017
bf60572
Merge pull request #800 from okuta/bp-797-fix-gitignore
kmaehashi Nov 30, 2017
494c59b
Merge pull request #803 from kmaehashi/fix-stack-test
niboshi Nov 30, 2017
624f6a8
Merge pull request #808 from kmaehashi/embed-signature
niboshi Dec 1, 2017
8538889
Merge pull request #786 from kmaehashi/fix-elementwise-docs
niboshi Dec 1, 2017
6be88dc
Merge pull request #810 from niboshi/bp-786-fix-elementwise-docs
kmaehashi Dec 1, 2017
6c9e947
Merge pull request #806 from niboshi/bp-803-fix-stack-test
kmaehashi Dec 1, 2017
adf72f7
Merge pull request #788 from hvy/allow-derived-errors
niboshi Dec 1, 2017
ae333f5
Merge pull request #809 from niboshi/bp-808-embed-signature
kmaehashi Dec 1, 2017
5bc3cda
Merge pull request #720 from okuta/add-default-casting
niboshi Dec 1, 2017
148701b
Merge pull request #804 from kmaehashi/fix-helper-comment
niboshi Dec 1, 2017
d45bae2
Merge pull request #811 from niboshi/bp-788-allow-derived-errors
hvy Dec 2, 2017
8eefaee
Merge pull request #812 from niboshi/bp-720-add-default-casting
okuta Dec 3, 2017
77ba344
Merge pull request #737 from niboshi/fix-matmul-value-error
okuta Dec 3, 2017
1b75b10
Merge pull request #748 from niboshi/bp-512-improve-cudnn
okuta Dec 3, 2017
a780b9e
Merge pull request #814 from niboshi/bp-804-fix-helper-comment
kmaehashi Dec 4, 2017
5879e40
Merge pull request #816 from okuta/bp-737-fix-matmul-value-error
niboshi Dec 4, 2017
a83c500
Merge pull request #817 from okuta/fix-matmul-test
niboshi Dec 4, 2017
be56876
Merge pull request #818 from niboshi/bp-817-fix-matmul-test
okuta Dec 4, 2017
b0f9e66
Merge pull request #805 from toslunar/cast-env-seed
niboshi Dec 4, 2017
75b3175
Merge pull request #822 from niboshi/bp-805-cast-env-seed
kmaehashi Dec 6, 2017
f87a4dd
Merge pull request #574 from unnonouno/remove-randint-dtype
niboshi Oct 14, 2017
50d6f3c
Merge pull request #830 from unnonouno/v2-remove-randint-dtype
niboshi Dec 7, 2017
aa39eb6
Merge pull request #741 from niboshi/fix-random-choice-repro
unnonouno Nov 24, 2017
7cca7e6
Remove unused import
unnonouno Dec 7, 2017
a276e56
Merge pull request #775 from unnonouno/v2-fix-random-choice-repro
niboshi Dec 7, 2017
d543ced
Update to v2.2.0
beam2d Dec 12, 2017
4423b77
Merge pull request #839 from beam2d/update-v2.2.0
kmaehashi Dec 12, 2017
2739453
Merge branch 'master' into clpy
LWisteria Mar 3, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ htmlcov/
.idea/
!ultima/ultima.cpp
ultima/ultima
.cache/
2 changes: 1 addition & 1 deletion clpy/_version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '2.1.0.1'
__version__ = '2.2.0'
2 changes: 1 addition & 1 deletion clpy/backend/cuda/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ def dump(self, f):
linum_fmt = '{{:0{}d}} '.format(digits)
f.write('NVRTC compilation error: {}\n'.format(self))
f.write('-----\n')
f.write('Name: {}\n'.format(' '.join(self.name)))
f.write('Name: {}\n'.format(self.name))
f.write('Options: {}\n'.format(' '.join(self.options)))
f.write('CUDA source:\n')
for i, line in enumerate(lines):
Expand Down
4 changes: 3 additions & 1 deletion clpy/backend/cuda/device.pxd
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
cpdef int get_device_id() except *
cpdef get_cublas_handle()
cpdef size_t get_cublas_handle() except *
cpdef size_t get_cusolver_handle() except *
cpdef size_t get_cusparse_handle() except *

cdef class Device:
cdef:
Expand Down
21 changes: 12 additions & 9 deletions clpy/backend/cuda/device.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -24,24 +24,27 @@ cdef dict _cusolver_handles = {}
cdef dict _cusparse_handles = {}


cpdef get_cublas_handle():
cpdef size_t get_cublas_handle() except *:
dev_id = get_device_id()
if dev_id in _cublas_handles:
return _cublas_handles[dev_id]
ret = _cublas_handles.get(dev_id, None)
if ret is not None:
return ret
return Device().cublas_handle


cpdef get_cusolver_handle():
cpdef size_t get_cusolver_handle() except *:
dev_id = get_device_id()
if dev_id in _cusolver_handles:
return _cusolver_handles[dev_id]
ret = _cusolver_handles.get(dev_id, None)
if ret is not None:
return ret
return Device().cusolver_handle


cpdef get_cusparse_handle():
cpdef size_t get_cusparse_handle() except *:
dev_id = get_device_id()
if dev_id in _cusparse_handles:
return _cusparse_handles[dev_id]
ret = _cusparse_handles.get(dev_id, None)
if ret is not None:
return ret
return Device().cusparse_handle


Expand Down
3 changes: 3 additions & 0 deletions clpy/core/core.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ cdef class Indexer:
readonly Py_ssize_t size
readonly tuple shape


cpdef ndarray ascontiguousarray(ndarray a, dtype=*)

cdef class CArray:
cdef:
readonly tuple stride
Expand Down
37 changes: 19 additions & 18 deletions clpy/core/core.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -1888,29 +1888,18 @@ include "reduction.pxi"

cdef _id = 'out0 = in0'

_elementwise_copy = create_ufunc(
elementwise_copy = create_ufunc(
'clpy_copy',
('?->?', 'b->b', 'B->B', 'h->h', 'H->H', 'i->i', 'I->I', 'l->l', 'L->L',
'q->q', 'Q->Q', ('e->e', _id), 'f->f', 'd->d', 'F->F', 'D->D'),
'out0 = (out0_type)(in0)')
'out0 = out0_type(in0)', default_casting='unsafe')
# complex numbers requires out0 = complex<T>(in0)


def elementwise_copy(*args, **kwargs):
kwargs['casting'] = 'unsafe'
return _elementwise_copy(*args, **kwargs)


_elementwise_copy_where = create_ufunc(
elementwise_copy_where = create_ufunc(
'clpy_copy_where',
('??->?', 'b?->b', 'B?->B', 'h?->h', 'H?->H', 'i?->i', 'I?->I', 'l?->l',
'L?->L', 'q?->q', 'Q?->Q', 'f?->f', 'd?->d', 'F?->F', 'D?->D'),
'if (in1) out0 = in0')


def elementwise_copy_where(*args, **kwargs):
kwargs['casting'] = 'unsafe'
return _elementwise_copy_where(*args, **kwargs)
'L?->L', 'q?->q', 'Q?->Q', 'e?->e', 'f?->f', 'd?->d', 'F?->F', 'D?->D'),
'if (in1) out0 = in0', default_casting='unsafe')


cdef _divmod_int = string.Template('''
Expand Down Expand Up @@ -3465,6 +3454,11 @@ cpdef ndarray matmul(ndarray a, ndarray b, ndarray out=None):
cdef Py_ssize_t i, n, m, ka, kb
cdef Py_ssize_t batchCount

orig_a_shape = a.shape
orig_b_shape = b.shape
if len(orig_a_shape) == 0 or len(orig_b_shape) == 0:
raise ValueError('Scalar operands are not allowed, use \'*\' instead')

ret_dtype = numpy.result_type(a.dtype, b.dtype)
dtype = numpy.find_common_type((ret_dtype, 'f'), ())

Expand Down Expand Up @@ -3550,9 +3544,16 @@ cpdef ndarray matmul(ndarray a, ndarray b, ndarray out=None):
*la, ka, n = a.shape
*lb, m, kb = b.shape

assert ka == kb
if ka != kb:
raise ValueError(
'shapes ({}) and ({}) not aligned'.format(
','.join([str(_) for _ in orig_a_shape]),
','.join([str(_) for _ in orig_b_shape])))
for la_, lb_ in zip(la, lb):
assert la_ == lb_ or la_ == 1 or lb_ == 1
if not (la_ == lb_ or la_ == 1 or lb_ == 1):
raise ValueError(
'operands could not be broadcast together with '
'remapped shapes')

batchCount = 1 # batchCount = numpy.prod(la)
for i in la:
Expand Down
29 changes: 19 additions & 10 deletions clpy/core/elementwise.pxi
Original file line number Diff line number Diff line change
Expand Up @@ -567,9 +567,11 @@ cdef class ElementwiseKernel:

Args:
args: Arguments of the kernel.
size (int): Range size of the indices. If specified, the variable
``n`` is set to this value. Otherwise, the result of
broadcasting is used to determine the value of ``n``.
size (int): Range size of the indices. By default, the range size
is automatically determined from the result of broadcasting.
This parameter must be specified if and only if all ndarrays
are `raw` and the range size cannot be determined
automatically.

Returns:
Arrays are returned according to the ``out_params`` argument of the
Expand Down Expand Up @@ -761,7 +763,9 @@ class ufunc(object):
nargs (int): Number of all arguments.

"""
def __init__(self, name, nin, nout, ops, preamble='', doc=''):

def __init__(self, name, nin, nout, ops, preamble='', doc='',
default_casting=None):
# TODO(tomoya.sakai): raw array may be possible for ufunc
self.name = name
self.nin = nin
Expand All @@ -770,6 +774,10 @@ class ufunc(object):
self._ops = ops
self._preamble = preamble
self.__doc__ = doc
if default_casting is None:
self._default_casting = 'same_kind'
else:
self._default_casting = default_casting
_in_params = tuple(
ParameterInfo('T in%d' % i, True)
for i in range(nin))
Expand Down Expand Up @@ -799,9 +807,7 @@ class ufunc(object):
return types

def __call__(self, *args, **kwargs):
"""__call__(*args, **kwargs)

Applies the universal function to arguments elementwise.
"""Applies the universal function to arguments elementwise.

Args:
args: Input arguments. Each of them can be a :class:`clpy.ndarray`
Expand All @@ -821,7 +827,7 @@ class ufunc(object):
out = kwargs.pop('out', None)
dtype = kwargs.pop('dtype', None)
# Note default behavior of casting is 'same_kind' on numpy>=1.10
casting = kwargs.pop('casting', 'same_kind')
casting = kwargs.pop('casting', self._default_casting)
if dtype is not None:
dtype = numpy.dtype(dtype).type
if kwargs:
Expand Down Expand Up @@ -879,7 +885,8 @@ class ufunc(object):
return ret


cpdef create_ufunc(name, ops, routine=None, preamble='', doc=''):
cpdef create_ufunc(name, ops, routine=None, preamble='', doc='',
default_casting=None):
_ops = []
for t in ops:
if not isinstance(t, tuple):
Expand All @@ -897,4 +904,6 @@ cpdef create_ufunc(name, ops, routine=None, preamble='', doc=''):
out_types = tuple([numpy.dtype(t).type for t in out_types])
_ops.append((in_types, out_types, rt))

return ufunc(name, len(_ops[0][0]), len(_ops[0][1]), _ops, preamble, doc)
ret = ufunc(name, len(_ops[0][0]), len(_ops[0][1]), _ops, preamble, doc,
default_casting=default_casting)
return ret
2 changes: 1 addition & 1 deletion clpy/core/fusion.py
Original file line number Diff line number Diff line change
Expand Up @@ -734,7 +734,7 @@ def _create_ufunc(clpy_ufunc, numpy_ufunc):

clip = ufunc(core._clip, math.misc.clip, numpy.clip)

copy = ufunc(core._elementwise_copy,
copy = ufunc(core.elementwise_copy,
creation.from_data.copy, numpy.copy)

bitwise_and = _create_ufunc(core.bitwise_and, numpy.bitwise_and)
Expand Down
4 changes: 1 addition & 3 deletions clpy/core/reduction.pxi
Original file line number Diff line number Diff line change
Expand Up @@ -398,9 +398,7 @@ class ReductionKernel(object):
self.preamble = preamble

def __call__(self, *args, **kwargs):
"""__call__(*args, **kwargs)

Compiles and invokes the reduction kernel.
"""Compiles and invokes the reduction kernel.

The compilation runs only if the kernel is not cached. Note that the
kernels with different argument dtypes, ndims, or axis are not
Expand Down
Loading