Compile-time constant tensors
Compile-time constant tensors
Some scalars should be fixed when the graph is built so the compiler and backend can fold them (constants in the plan), rather than supplied on every execute() like ordinary pass-by-value tensors.
The graph API distinguishes this with ScalarType:
C++ API
Create tensors from a scalar and ScalarType:
Under the hood, COMPILE_TIME_CONST sets the tensor’s compile-time constant payload (Tensor_attributes::set_compile_time_constant / get_has_compile_time_constant()). Such tensors must be pass-by-value, non-virtual, and must not also carry a runtime pass_by_value payload.
Python API
pygraph.tensor_scalar(value, scalar_type)- Overloads for floating and integer scalars;
scalar_typeiscudnn.scalar_type.RUNTIME_PARAMorcudnn.scalar_type.COMPILE_TIME_CONST.
- Overloads for floating and integer scalars;
You can still query flags on cudnn.tensor:
get_has_compile_time_constant()/set_compile_time_constant(advanced; prefertensor_scalarfor scalars).
Example
See samples/cpp/misc/compile_time_constant_example.cpp for a fused multiply-add using ScalarType::COMPILE_TIME_CONST.