2022-09-29 11:01:30 +08:00
|
|
|
#pragma once
|
|
|
|
#include "core/operator.h"
|
|
|
|
|
|
|
|
namespace infini {
|
2023-02-13 22:48:20 +08:00
|
|
|
/**
|
|
|
|
* @brief Split a tensor into multiple ones.
|
|
|
|
*
|
|
|
|
*/
|
2022-09-29 11:01:30 +08:00
|
|
|
class SplitObj : public OperatorObj {
|
|
|
|
int dim, num; // split dim;Average split num or outputs size
|
|
|
|
vector<int> ratio; // output dim ratio
|
|
|
|
public:
|
2023-02-13 22:48:20 +08:00
|
|
|
/**
|
|
|
|
* @brief Construct a new Split object.
|
|
|
|
*
|
|
|
|
* @param graph The computation graph that this operator belongs to.
|
|
|
|
* @param input The input tensor.
|
|
|
|
* @param outputs The output tensors after splitting.
|
|
|
|
* @param dim The dimension to split.
|
|
|
|
* @param num The number of output tensors. The input tensor is split into
|
|
|
|
* `num` evenly chunk along dimension `dim. The last chunk will be smaller
|
|
|
|
* if the input tensor cannot be evenly split.
|
|
|
|
*/
|
2022-09-29 11:01:30 +08:00
|
|
|
SplitObj(GraphObj *graph, Tensor input, std::optional<TensorVec> outputs,
|
|
|
|
int dim, int num);
|
2023-02-13 22:48:20 +08:00
|
|
|
/**
|
|
|
|
* @brief Construct a new Split object.
|
|
|
|
*
|
|
|
|
* @param graph The computation graph that this operator belongs to.
|
|
|
|
* @param input The input tensor.
|
|
|
|
* @param outputs The output tensors after splitting.
|
|
|
|
* @param dim The dimension to split.
|
|
|
|
* @param ratio The size of dimension `dim` for the output tensors after
|
|
|
|
* splitting.
|
|
|
|
*/
|
2022-09-29 11:01:30 +08:00
|
|
|
SplitObj(GraphObj *graph, Tensor input, std::optional<TensorVec> outputs,
|
|
|
|
int dim, const vector<int> &ratio);
|
2023-02-12 18:27:52 +08:00
|
|
|
OP_CLONE(SplitObj);
|
2022-09-29 11:01: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 num; }
|
|
|
|
int getDim() const { return dim; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
vector<int> getWorkloadVector() const override;
|
|
|
|
vector<int> getOpAttrVector() const override;
|
|
|
|
};
|
|
|
|
} // namespace infini
|