cupy.make_aligned_dtype#

cupy.make_aligned_dtype(dtype, *, int alignment=-1, bool recurse=True)#

Create a new structured dtype from a NumPy dtype or dtype-like with sufficient alignment for GPU use.

Parameters:
  • dtype – Data type specifier compatible with NumPy.

  • alignment

    Desired alignment of the resulting dtype. The dtype will be padded to ensure this alignment for CuPy.

    Note

    When the requested alignment is smaller than the minimal inferred one an error will be raised. When it is larger, CuPy will attach this alignment as metadata to the structured dtype. This is used for structured dtypes in the kernel and when nesting.

    Note that metadata may be lost in many operations.

  • recurse – Whether to recurse into nested structures, defaults to True. When False, the nested struct is assumed to be already sufficiently aligned.

Returns:

A dtype object with the desired alignment.

Return type:

numpy.dtype

Notes

By default this function recurses into nested structures as if alignment=-1 is passed for these. You can nest a dtype with larger alignment by creating it with make_aligned_dtype().

NumPy promotion (e.g. in concatenate) may “canonicalize” the dtype and drop the struct layout and CuPy alignment metadata.