2022-09-29 14:44:20 +08:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "core/operator.h"
|
|
|
|
|
|
|
|
namespace infini {
|
2023-10-12 09:18:12 +08:00
|
|
|
|
|
|
|
class GatherBaseObj : public OperatorObj {
|
|
|
|
protected:
|
|
|
|
int axis;
|
|
|
|
|
|
|
|
public:
|
|
|
|
GatherBaseObj(OpType opType, TensorVec inputs, TensorVec outputs, int axis)
|
|
|
|
: OperatorObj(opType, inputs, outputs), axis(axis) {}
|
|
|
|
|
|
|
|
virtual ~GatherBaseObj() {}
|
|
|
|
int numInputs() const override { return 2; }
|
|
|
|
int numOutputs() const override { return 1; }
|
|
|
|
|
|
|
|
int getAxis() const { return axis; }
|
|
|
|
};
|
|
|
|
|
2023-02-13 22:48:20 +08:00
|
|
|
/**
|
|
|
|
* @brief Gather and concatenate given positions on a certain dimension of the
|
|
|
|
* input tensor using an index tensor.
|
|
|
|
*
|
|
|
|
*/
|
2023-10-12 09:18:12 +08:00
|
|
|
class GatherObj : public GatherBaseObj {
|
2022-09-29 14:44:20 +08:00
|
|
|
public:
|
2023-02-13 22:48:20 +08:00
|
|
|
/**
|
|
|
|
* @brief Construct a new Gather object.
|
|
|
|
*
|
|
|
|
* @param graph The computation graph that this operator belongs to.
|
|
|
|
* @param input The input tensor.
|
2023-02-14 14:16:01 +08:00
|
|
|
* @param indices The index tensor.
|
2023-02-13 22:48:20 +08:00
|
|
|
* @param output The output tensor.
|
|
|
|
* @param axis The axis to gather on.
|
|
|
|
*/
|
2023-02-14 14:16:01 +08:00
|
|
|
GatherObj(GraphObj *graph, Tensor input, Tensor indices, Tensor output,
|
2022-09-29 14:44:20 +08:00
|
|
|
int axis);
|
2023-02-12 18:27:52 +08:00
|
|
|
OP_CLONE(GatherObj);
|
2022-09-29 14:44:20 +08:00
|
|
|
std::string toString() const override;
|
2023-11-23 13:11:50 +08:00
|
|
|
optional<vector<Shape>> inferShape(const TensorVec &inputs) override;
|
2022-09-29 14:44:20 +08:00
|
|
|
vector<DataType> inferDataType(const TensorVec &inputs) const override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
bool CheckIndexValid() const;
|
|
|
|
vector<int> getWorkloadVector() const override;
|
|
|
|
vector<int> getOpAttrVector() const override;
|
|
|
|
};
|
2023-10-12 09:18:12 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief GatherElements takes two inputs data and indices of the
|
|
|
|
* same rank r >= 1 and an optional attribute axis that identifies
|
|
|
|
* an axis of data.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
class GatherElementsObj : public GatherBaseObj {
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* @brief Construct a new GatherElements object.
|
|
|
|
*
|
|
|
|
* @param graph The computation graph that this operator belongs to.
|
|
|
|
* @param input The input tensor.
|
|
|
|
* @param indices The index tensor.
|
|
|
|
* @param output The output tensor. Same shape as indices.
|
|
|
|
* @param axis The axis to gather on.
|
|
|
|
*/
|
|
|
|
GatherElementsObj(GraphObj *graph, Tensor input, Tensor indices,
|
|
|
|
Tensor output, int axis);
|
|
|
|
OP_CLONE(GatherElementsObj);
|
|
|
|
std::string toString() const override;
|
2023-11-23 13:11:50 +08:00
|
|
|
optional<vector<Shape>> inferShape(const TensorVec &inputs) override;
|
2023-10-12 09:18:12 +08:00
|
|
|
vector<DataType> inferDataType(const TensorVec &inputs) const override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
vector<int> getWorkloadVector() const override;
|
|
|
|
vector<int> getOpAttrVector() const override;
|
|
|
|
};
|
2022-10-15 16:29:28 +08:00
|
|
|
} // namespace infini
|