2022-09-21 14:04:30 +08:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "core/operator.h"
|
|
|
|
|
|
|
|
namespace infini {
|
2023-02-13 22:48:20 +08:00
|
|
|
/**
|
|
|
|
* @brief Change the shape of the input tensor.
|
|
|
|
*
|
|
|
|
*/
|
2022-09-21 14:04:30 +08:00
|
|
|
class ReshapeObj : public OperatorObj {
|
|
|
|
Shape dims;
|
|
|
|
|
|
|
|
public:
|
2023-02-13 22:48:20 +08:00
|
|
|
/**
|
|
|
|
* @brief Construct a new Reshape object.
|
|
|
|
*
|
|
|
|
* @param graph The computation graph that this operator belongs to.
|
|
|
|
* @param input The input tensor.
|
|
|
|
* @param output The output tensor.
|
|
|
|
* @param dims The shape of the output tensor.
|
|
|
|
*/
|
2023-02-14 09:50:32 +08:00
|
|
|
ReshapeObj(GraphObj *graph, Tensor input, Tensor output, Shape dims);
|
2023-02-12 18:27:52 +08:00
|
|
|
OP_CLONE(ReshapeObj);
|
2022-09-21 14:04:30 +08:00
|
|
|
|
|
|
|
optional<vector<Shape>> inferShape(const TensorVec &inputs) const override;
|
|
|
|
|
|
|
|
std::string toString() const override;
|
|
|
|
int numInputs() const override { return 1; }
|
|
|
|
int numOutputs() const override { return 1; }
|
|
|
|
|
2023-02-21 14:30:06 +08:00
|
|
|
inline Shape getShape() const { return dims; }
|
|
|
|
|
2022-09-21 14:04:30 +08:00
|
|
|
private:
|
|
|
|
vector<int> getWorkloadVector() const override;
|
|
|
|
vector<int> getOpAttrVector() const override;
|
|
|
|
};
|
|
|
|
|
2023-02-13 22:48:20 +08:00
|
|
|
/**
|
|
|
|
* @brief Reshape the input tensor into a one-dimensional tensor.
|
|
|
|
* FIXME: Move to an independent file.
|
|
|
|
* FIXME: Different parameter list with ONNX and Pytorch.
|
|
|
|
*
|
|
|
|
*/
|
2022-09-21 14:04:30 +08:00
|
|
|
class FlattenObj : public OperatorObj {
|
2023-04-17 12:15:23 +08:00
|
|
|
int axis;
|
2022-09-21 14:04:30 +08:00
|
|
|
|
|
|
|
public:
|
2023-02-13 22:48:20 +08:00
|
|
|
/**
|
|
|
|
* @brief Construct a new Flatten object.
|
|
|
|
*
|
|
|
|
* @param graph The computation graph that this operator belongs to.
|
|
|
|
* @param input The input tensor.
|
|
|
|
* @param output The output one-dimensional tensor.
|
|
|
|
*/
|
2023-04-17 12:15:23 +08:00
|
|
|
FlattenObj(GraphObj *graph, Tensor input, Tensor output, int axis);
|
2023-02-12 18:27:52 +08:00
|
|
|
OP_CLONE(FlattenObj);
|
2022-09-21 14:04:30 +08:00
|
|
|
|
|
|
|
optional<vector<Shape>> inferShape(const TensorVec &inputs) const override;
|
|
|
|
|
|
|
|
std::string toString() const override;
|
|
|
|
int numInputs() const override { return 1; }
|
|
|
|
int numOutputs() const override { return 1; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
vector<int> getWorkloadVector() const override;
|
|
|
|
vector<int> getOpAttrVector() const override;
|
|
|
|
};
|
|
|
|
|
2023-02-13 22:48:20 +08:00
|
|
|
/**
|
|
|
|
* @brief Copy the input tensor.
|
|
|
|
* FIXME: Move to an independent file.
|
|
|
|
*
|
|
|
|
*/
|
2022-09-21 14:04:30 +08:00
|
|
|
class IdentityObj : public OperatorObj {
|
|
|
|
|
|
|
|
public:
|
2023-02-13 22:48:20 +08:00
|
|
|
/**
|
|
|
|
* @brief Construct a new Identity object.
|
|
|
|
*
|
|
|
|
* @param graph The computation graph that this operator belongs to.
|
|
|
|
* @param input The input tensor.
|
|
|
|
* @param output The output tensor, which is the same as the input tensor.
|
|
|
|
*/
|
2022-09-21 14:04:30 +08:00
|
|
|
IdentityObj(GraphObj *graph, Tensor input, Tensor output);
|
2023-02-12 18:27:52 +08:00
|
|
|
OP_CLONE(IdentityObj);
|
2022-09-21 14:04:30 +08:00
|
|
|
|
|
|
|
optional<vector<Shape>> inferShape(const TensorVec &inputs) const override;
|
|
|
|
|
|
|
|
std::string toString() const override;
|
|
|
|
int numInputs() const override { return 1; }
|
|
|
|
int numOutputs() const override { return 1; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
vector<int> getWorkloadVector() const override;
|
|
|
|
vector<int> getOpAttrVector() const override;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace infini
|