Skip to content
class

AmpScope

AmpScope

The autocast entry of an engine composite — an op with no schema of its own, built from other *_op calls.

The composite's row in the policy table is applied once, here, to its inputs; autocast is then off on the device until the scope ends, as SchemaGuard does for a primitive. Without it each primitive inside applied its own row: log1p lowered its add to float16 and raised its log to float32, then refused to combine the two (DtypeMismatch), and log10 came out in float16 because its last step is a div.

Only float16, bfloat16 and float32 inputs are cast; float64, complex and integer inputs pass through. Outside an autocast scope nothing is cast, nothing is turned off and the table is not read.

Examples

.. code-block:: cpp
    TensorImplPtr log10_op(const TensorImplPtr& a_in) {
        const AmpScope amp{"log10", a_in->device()};
        const TensorImplPtr a = amp.cast(a_in);
        ...

Constructors

1
ctor

AmpScope

void AmpScope(int name, Device device)

Inside an autocast scope, resolves name's row for device and turns autocast off on device until the scope is destroyed.

Operators

1
op

operator=

AmpScope & operator=(const AmpScope &)

Methods

2
fnconst

cast

int cast(const int & t)

t at the dtype the row gives one input. PromoteWidest leaves a lone input alone — use cast_widest for an op's operands.

fnconst

cast_widest

int cast_widest(int ts)

The operands of one op, cast together. Under PromoteWidest every eligible operand goes to the widest eligible dtype among them — float16 with bfloat16 is float32, as the reference promotes them; under any other policy each is cast on its own. The one owner of PromoteWidest: SchemaGuard sees one input and keeps it.