In this article
A raw elementwise argument is excluded from automatic broadcasting; the wrapper must still establish the intended iteration domain.
Identify the array that defines the output domain
A custom feature operation reads a lookup table through manual indexing while applying a formula to a batch. The CuPy kernel guide distinguishes raw ElementwiseKernel arguments from automatically broadcast operands. The lookup table’s shape is not automatically part of the iteration shape. State which ordinary inputs or output arrays define the batch domain. Otherwise a change made to control indexing can also change how the wrapper determines the amount of work.
Keep lookup coordinates separate from loop coordinates
The elementwise loop index identifies a position in the chosen operation domain; an index into a raw table follows the lookup’s own schema. A table can contain more or fewer entries than the output batch. Validate the application’s lookup indices independently from the batch size instead of assuming a valid elementwise position is also a valid table offset. Distinguishable table values make an accidental reuse of the loop coordinate visible in a small correctness example.
Specify size only under the documented condition
The ElementwiseKernel API explains size inference and the explicit size requirement when all ndarray arguments are raw and the domain cannot be inferred. Follow that interface rather than passing a guessed size into every call. An explicit range describes how many loop positions exist; it does not validate every manually computed table access or establish that the output representation matches the intended batch shape.
Preserve logical broadcasting in a reference
The broadcast_to reference provides a broadcasted view of a specified shape. Build a simple reference that expresses the desired logical operation with ordinary array semantics before replacing selected accesses with manual indexing. Do not import RawKernel pointer rules into this different abstraction without checking its contract. A strided view, a broadcast operand and a raw lookup play distinct roles even when they refer to the same underlying array values.
Test independent changes in each shape
Vary batch shape and lookup-table shape separately, including a broadcast scalar and a noncontiguous table view where supported. Compare values and output shape with the reference. The guides on broadcasting mask axes and array memory layout provide related context. A successful kernel launch does not prove that automatic broadcasting inferred the intended domain or that manual accesses used the correct logical coordinates.
Earn rental income from GPUs
Have idle GPUs or looking to fund AI infrastructure? Retrivium finds a rental platform, sets up the server and helps you assess income and costs with a pilot.