Skip to content

Commit

Permalink
Merge pull request #1 from bdice/string_udfs-style
Browse files Browse the repository at this point in the history
Fix style checks for string_udfs.
  • Loading branch information
brandon-b-miller authored Jul 22, 2022
2 parents cc661b3 + 3710d9b commit 5602da8
Show file tree
Hide file tree
Showing 33 changed files with 512 additions and 471 deletions.
1 change: 1 addition & 0 deletions python/cudf/cudf/_lib/cpp/column/column_factories.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ from cudf._lib.cpp.column.column cimport column
from cudf._lib.cpp.scalar.scalar cimport scalar
from cudf._lib.cpp.types cimport data_type, mask_state, size_type


cdef extern from "cudf/column/column_factories.hpp" namespace "cudf" nogil:
cdef unique_ptr[column] make_numeric_column(data_type type,
size_type size,
Expand Down
10 changes: 8 additions & 2 deletions python/cudf/cudf/core/indexed_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,13 @@
from cudf.core.index import Index, RangeIndex, _index_from_columns
from cudf.core.missing import NA
from cudf.core.multiindex import MultiIndex
from cudf.core.udf.utils import _compile_or_get, _launch_arg_from_col, _supported_cols_from_frame, _return_col_from_dtype, _post_process_output_col
from cudf.core.udf.utils import (
_compile_or_get,
_launch_arg_from_col,
_post_process_output_col,
_return_col_from_dtype,
_supported_cols_from_frame,
)
from cudf.utils import docutils
from cudf.utils.utils import _cudf_nvtx_annotate

Expand Down Expand Up @@ -1809,7 +1815,7 @@ def _apply(self, func, kernel_getter, *args, **kwargs):
offsets.append(col.offset)
launch_args += offsets
launch_args += list(args)

try:
kernel.forall(len(self))(*launch_args)
except Exception as e:
Expand Down
14 changes: 4 additions & 10 deletions python/cudf/cudf/core/udf/masked_lowering.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,24 @@
from llvmlite import ir
from numba.core import cgutils
from numba.core.typing import signature as nb_signature
from numba.cuda.cudadrv import nvvm
from numba.cuda.cudaimpl import (
lower as cuda_lower,
registry as cuda_lowering_registry,
)
from numba.extending import lower_builtin, types

from strings_udf._typing import string_view

from cudf.core.udf import api
from cudf.core.udf._ops import (
arith_ops,
bitwise_ops,
comparison_ops,
unary_ops,
)
from cudf.core.udf.masked_typing import (
MaskedType,
NAType,
)

import operator
from cudf.core.udf.masked_typing import MaskedType, NAType


from strings_udf._typing import string_view

@cuda_lowering_registry.lower_constant(NAType)
def constant_na(context, builder, ty, pyval):
# This handles None, etc.
Expand Down Expand Up @@ -295,6 +289,7 @@ def pack_return_scalar_impl(context, builder, sig, args):

return outdata._getvalue()


@cuda_lower(operator.truth, MaskedType)
def masked_scalar_truth_impl(context, builder, sig, args):
indata = cgutils.create_struct_proxy(MaskedType(types.boolean))(
Expand Down Expand Up @@ -368,7 +363,6 @@ def masked_constructor(context, builder, sig, args):
return masked._getvalue()



# Allows us to make an instance of MaskedType a global variable
# and properly use it inside functions we will later compile
@cuda_lowering_registry.lower_constant(MaskedType)
Expand Down
10 changes: 5 additions & 5 deletions python/cudf/cudf/core/udf/masked_typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import operator

from numba import cuda, types
from numba import types
from numba.core.extending import (
make_attribute_wrapper,
models,
Expand All @@ -18,6 +18,8 @@
from numba.core.typing.typeof import typeof
from numba.cuda.cudadecl import registry as cuda_decl_registry

from strings_udf._typing import StringView, string_view

from cudf.core.missing import NA
from cudf.core.udf import api
from cudf.core.udf._ops import (
Expand All @@ -35,9 +37,6 @@
types.PyObject,
)

import operator

from strings_udf._typing import string_view, StringView

# Masked scalars of all types
class MaskedType(types.Type):
Expand Down Expand Up @@ -131,6 +130,7 @@ def __eq__(self, other):
# Require a cast for another masked with a different value type
return self.value_type == other.value_type


# For typing a Masked constant value defined outside a kernel (e.g. captured in
# a closure).
@typeof_impl.register(api.Masked)
Expand Down Expand Up @@ -163,6 +163,7 @@ class MaskedConstructor(ConcreteTemplate):
make_attribute_wrapper(MaskedType, "value", "value")
make_attribute_wrapper(MaskedType, "valid", "valid")


# Typing for `api.Masked`
@cuda_decl_registry.register_attr
class ClassesTemplate(AttributeTemplate):
Expand Down Expand Up @@ -365,7 +366,6 @@ def generic(self, args, kws):
return nb_signature(return_type, args[0])



for binary_op in arith_ops + bitwise_ops + comparison_ops:
# Every op shares the same typing class
cuda_decl_registry.register_global(binary_op)(MaskedScalarArithOp)
Expand Down
9 changes: 5 additions & 4 deletions python/cudf/cudf/core/udf/row_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,16 @@
from numba.np import numpy_support
from numba.types import Record

from strings_udf._typing import DString

from cudf.core.udf.api import Masked, pack_return
from cudf.core.udf.masked_typing import MaskedType
from cudf.core.udf.templates import (
masked_input_initializer_template,
row_initializer_template,
row_kernel_template,
unmasked_input_initializer_template,
)
from cudf.core.udf.masked_typing import MaskedType
from cudf.core.udf.utils import (
_all_dtypes_from_frame,
_construct_signature,
Expand All @@ -24,7 +26,6 @@
_supported_dtypes_from_frame,
)

from strings_udf._typing import DString
dstring = DString()


Expand All @@ -50,7 +51,7 @@ def _get_frame_row_type(dtype):

sizes = []
for field in dtype.fields.values():
if field[0] == np.dtype('object'):
if field[0] == np.dtype("object"):
sizes.append(dstring.size_bytes)
else:
sizes.append(field[0].itemsize)
Expand All @@ -71,7 +72,7 @@ def _get_frame_row_type(dtype):
fields.append((name, infos))

# increment offset by itemsize plus one byte for validity
if elemdtype == np.dtype('object'):
if elemdtype == np.dtype("object"):
itemsize = dstring.size_bytes
else:
itemsize = elemdtype.itemsize
Expand Down
2 changes: 1 addition & 1 deletion python/cudf/cudf/core/udf/scalar_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
from numba.np import numpy_support

from cudf.core.udf.api import Masked, pack_return
from cudf.core.udf.masked_typing import MaskedType
from cudf.core.udf.templates import (
masked_input_initializer_template,
scalar_kernel_template,
unmasked_input_initializer_template,
)
from cudf.core.udf.masked_typing import MaskedType
from cudf.core.udf.utils import (
_construct_signature,
_get_kernel,
Expand Down
Loading

0 comments on commit 5602da8

Please sign in to comment.