MayaFlux 1.0.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
TensorConverter.hpp
Go to the documentation of this file.
1#pragma once
2
5
6namespace MayaFlux::Yantra {
7
8/**
9 * @struct TensorConversionConfig
10 * @brief Settings of TensorConverter, stored whole in the operation's facets.
11 */
13 /** Element type of the result. */
15 /** Quantization the result carries; the target must be an integer type of at most 32 bits. */
16 std::optional<Kakshya::TensorQuantization> quantization;
17};
18
20
21/**
22 * @class TensorConverter
23 * @brief Converts the element type of a tensor, reading and writing quantization.
24 *
25 * Takes a tensor container and produces a new one with the target element
26 * type, the source's name and axes, and dense C-order storage. A source that
27 * carries quantization is dequantized; a configured quantization is applied to
28 * the result. The input container is not modified. Facets and metadata of the
29 * input travel with the output.
30 *
31 * Supported element types are whole-byte integers, bool, half, bfloat16,
32 * float, double and complex of float and double. Everything else, and any
33 * combination convert_tensor refuses, is reported by validate_input and
34 * thrown by the operation with the reason.
35 *
36 * Usage:
37 * @code
38 * TensorConversionConfig config;
39 * config.target = Kakshya::TensorDType::of<float>();
40 * auto convert = std::make_shared<TensorConverter>();
41 * convert->set_config(config);
42 * auto result = convert->apply_operation(TensorContainerIO { weights });
43 * @endcode
44 */
45class MAYAFLUX_API TensorConverter final
46 : public ComputeOperation<std::shared_ptr<Kakshya::TensorContainer>> {
47public:
49
50 [[nodiscard]] std::string get_name() const override { return "TensorConverter"; }
51
52 [[nodiscard]] OperationType get_operation_type() const override { return OperationType::TRANSFORMER; }
53
54 /** @brief The stored settings, or none when defaults are in use. */
55 [[nodiscard]] ConfigRefs configs() const override
56 {
57 return stored_configs(supports {});
58 }
59
60 /** @brief True when the input holds a valid tensor the configured conversion accepts. */
61 [[nodiscard]] bool validate_input(const input_type& input) const override;
62
63protected:
64 output_type operation_function(const input_type& input) override;
65};
66
67}
#define MF_DESCRIBE(...)
Requests a generated member description for a struct at namespace scope.
Definition Describe.hpp:14
OperationType get_operation_type() const override
Returns the category of this operation for grammar and registry discovery.
ConfigRefs configs() const override
The stored settings, or none when defaults are in use.
std::string get_name() const override
Get operation name for debugging/introspection.
Supports< TensorConversionConfig > supports
Converts the element type of a tensor, reading and writing quantization.
OperationType
Operation categories for organization and discovery.
std::vector< std::reference_wrapper< const OperationConfig > > ConfigRefs
Borrowed views of the configs an operation holds.
static constexpr TensorDType of() noexcept
Type for a C++ scalar or complex element.
Element type as kind, bit width and lane count.
The config structs an operation class accepts, declared as using supports.
std::optional< Kakshya::TensorQuantization > quantization
Quantization the result carries; the target must be an integer type of at most 32 bits.
Kakshya::TensorDType target
Element type of the result.
Settings of TensorConverter, stored whole in the operation's facets.