Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
719ac73
Working prototype with creation and readout
isVoid Mar 29, 2022
6d7ac9b
Second attmpet on working example
isVoid Apr 12, 2022
e01c497
Style fixes
isVoid Apr 12, 2022
dc6223a
Remove binop logics and minor cleanups
isVoid Apr 12, 2022
c6f5f4e
Initial to fancy creation
isVoid Apr 12, 2022
8430abc
cleanups
isVoid Apr 12, 2022
8864af8
Add documentation for vector types
isVoid Apr 14, 2022
61a97a3
Various docstring updates.
isVoid Apr 27, 2022
db84a5d
Delete stub lists to avoid leaking to global environment
isVoid Apr 27, 2022
7635410
Merge branch 'fea/cuda_vector_types' of github.com:isVoid/numba into …
isVoid Apr 27, 2022
a0e9e2d
wrap vtype stubs in factory method to avoid variable leaking
isVoid Apr 27, 2022
daa82e3
Make stub more descriptive
isVoid Apr 27, 2022
d904a5b
Update prefix
isVoid May 2, 2022
a1b449b
Aliased vector types
isVoid May 2, 2022
d924c2a
Dynamically determine the stub to alias mapping
isVoid May 2, 2022
da5e299
Apply Graham's change to exploit python's module import-once.
isVoid May 16, 2022
dba5825
Update documentations
isVoid May 16, 2022
2720d23
Add comment to test case
isVoid May 16, 2022
5bfccc5
fix 1-component vector type in ctor, add coverage
isVoid May 17, 2022
b02740f
Fix type annotations for
isVoid May 17, 2022
fd49c27
skip vector type test in simulator
isVoid May 17, 2022
c160b63
fix attr_names type annotation
isVoid May 18, 2022
02b9db3
Apply several documentation updates
isVoid May 18, 2022
4449e84
move `type` page link under cuda-reference
isVoid May 18, 2022
2d72d9d
update built-in types link
isVoid May 18, 2022
9c1f6b9
Add field accessing demo code, update ctor demo
isVoid May 18, 2022
baac6b7
Add comments to separate out the result array, fix jagged comment ind…
isVoid May 18, 2022
4633470
Fix argument type annotation
isVoid May 19, 2022
457c91d
Minor doc updates
isVoid May 20, 2022
467a865
add simulator vector type
isVoid May 21, 2022
2522b85
Add missing vector type fake module
isVoid May 21, 2022
96a1968
Remove stale breakpoint
isVoid May 23, 2022
7deb8db
Asserts with number of elements
isVoid May 25, 2022
7b8711f
fix typo
isVoid May 25, 2022
1260b82
Separate tests with subtest
isVoid May 25, 2022
27e0427
wrap each test in subtest
isVoid May 25, 2022
ac91dfa
revert to only test construction with name
isVoid May 25, 2022
cbf41bd
several comment update
isVoid May 25, 2022
aabfb33
optimize simulator vector types code paths
isVoid May 25, 2022
60d872e
Merge branch 'main' into fea/cuda_vector_types
isVoid May 25, 2022
a43a474
Commit docs suggestions
isVoid May 25, 2022
cfe863a
better error with mismatch number of arguments when constructing simu…
isVoid May 25, 2022
4faf3f5
Raise more sensible error for simulator vector types.
isVoid May 25, 2022
d95ac9f
Add a basic sanity check test case
isVoid May 25, 2022
cc652b4
Insert the vector types in fake cuda module.
isVoid May 25, 2022
556174f
Remove leading empty line
isVoid May 25, 2022
a29bc97
Address various review comments
isVoid Jun 6, 2022
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
Prev Previous commit
Next Next commit
Remove binop logics and minor cleanups
  • Loading branch information
isVoid committed Apr 12, 2022
commit dc6223ab75f715e1e57c16f0b54b6a5d2c98e224
102 changes: 11 additions & 91 deletions numba/cuda/vector_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

from numba import types
from numba.core import cgutils
from numba.core.errors import TypingError
from numba.core.extending import make_attribute_wrapper, models, register_model
from numba.core.imputils import Registry as ImplRegistry
from numba.core.typing.templates import ConcreteTemplate
Expand All @@ -32,7 +31,7 @@ def wrapper(*args, **kwargs):


# TODO: double check the type mapping is correct for all platforms.
# TODO: see numba.core.types.__init__.py, create aliases such as int32x4=int4?
# QST: need aliases such as int32x4=int4?
_vector_type_to_base_types = {
"char": types.char,
"short": types.int16,
Expand Down Expand Up @@ -116,8 +115,8 @@ def enable_vector_type_ctor(
vector_type: VectorType
The type whose constructor to type and lower.
overloads: List of argument types tuples
A list containing different overloads of the factory function. Each
base type in the tuple should either be primitive type or VectorType.
A list containing different overloads of the constructor. Each base type
in the tuple should either be primitive type or VectorType.
"""
ctor = vector_type.user_facing_object

Expand All @@ -130,13 +129,13 @@ class CtorTemplate(ConcreteTemplate):

# Lowering

def make_lower_factory(fml_arg_list):
"""Meta function to create a lowering for the factory function. Flattens
def make_lowering(fml_arg_list):
"""Meta function to create a lowering for the constructor. Flattens
the arguments by converting vector_type into load instructions for each
of its attributes. Such as float2 -> float2.x, float2.y.
"""

def lower_factory(context, builder, sig, actual_args):
def lowering(context, builder, sig, actual_args):
# A list of elements to assign from
source_list = []
# Convert the list of argument types to a list of load IRs.
Expand Down Expand Up @@ -164,91 +163,11 @@ def lower_factory(context, builder, sig, actual_args):
setattr(out, attr_name, source)
return out._getvalue()

return lower_factory
return lowering

for arglist in overloads:
lower_factory = make_lower_factory(arglist)
lower(ctor, *arglist)(lower_factory)


def lower_vector_type_binops(
binop, vector_type: VectorType, overloads: List[Tuple[types.Type]]
):
"""Lower binops for ``vector_type``

Parameters
----------
binop: operation
The binop to lower
vector_type: VectorType
The type to lower op for.
overloads: List of argument types tuples
A list containing different overloads of the binop. Should be one of:
- vector_type x vector_type
- primitive_type x vector_type
- vector_type x primitive_type.
If one of the oprand is primitive_type, the operation is broadcasted.
"""
# Should we assume the above are the only possible cases?
class Vector_op_template(ConcreteTemplate):
key = binop
cases = [signature(vector_type, *arglist) for arglist in overloads]

def make_lower_op(fml_arg_list):
def op_impl(context, builder, sig, actual_args):
def _make_load_IR(typ, actual_arg):
if isinstance(typ, VectorType):
pxy = cgutils.create_struct_proxy(typ)(
context, builder, actual_arg
)
oprands = [getattr(pxy, attr) for attr in typ.attr_names]
else:
# Assumed primitive type, broadcast
oprands = [
actual_arg for _ in range(vector_type.num_elements)
]
return oprands

def element_wise_op(lhs, rhs, res, attr):
setattr(
res,
attr,
context.compile_internal(
builder,
lambda x, y: binop(x, y),
signature(types.float32, types.float32, types.float32),
(lhs, rhs),
),
)

lhs_typ, rhs_typ = fml_arg_list
# Construct a list of load IRs
lhs = _make_load_IR(lhs_typ, actual_args[0])
rhs = _make_load_IR(rhs_typ, actual_args[1])

if not len(lhs) == len(rhs) == vector_type.num_elements:
raise TypingError(
f"Unmatched number of lhs elements ({len(lhs)}), rhs "
f"elements ({len(rhs)}) and target elements "
f"({vector_type.num_elements})."
)

out = cgutils.create_struct_proxy(vector_type)(context, builder)
for attr, l, r in zip(vector_type.attr_names, lhs, rhs):
element_wise_op(l, r, out, attr)

return out._getvalue()

return op_impl

register_global(binop, types.Function(Vector_op_template))
for arglist in overloads:
impl = make_lower_op(arglist)
lower(binop, *arglist)(impl)


def vector_type_ctor_overloads(vty: VectorType) -> List[Tuple[types.Type]]:
return [(vty.base_type,) * vty.num_elements]
lowering = make_lowering(arglist)
lower(ctor, *arglist)(lowering)


vector_types : List[VectorType] = []
Expand All @@ -265,4 +184,5 @@ def initialize_once():
vector_types.append(vector_type)

for vty in vector_types:
enable_vector_type_ctor(vty, vector_type_ctor_overloads(vty))
arglists = [(vty.base_type,) * vty.num_elements]
enable_vector_type_ctor(vty, arglists)