-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: YdrMaster <[email protected]>
- Loading branch information
Showing
4 changed files
with
83 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// #include "computation/operators/einsum.h" | ||
#include "einsum.hh" | ||
#include "common.h" | ||
#include "refactor/common.h" | ||
#include <variant> | ||
|
||
namespace refactor::onnx { | ||
using Op = Einsum; | ||
|
||
Op::Einsum(std::string equation_) | ||
: Operator(), equation(std::move(equation_)) {} | ||
|
||
auto Op::build(std::string_view, Attributes attributes) -> OpBox { | ||
return OpBox(std::make_unique<Op>(std::move(attributes.at("equation").string()))); | ||
} | ||
auto Op::typeId() -> size_t { | ||
static uint8_t ID = 1; | ||
return reinterpret_cast<size_t>(&ID); | ||
} | ||
|
||
auto Op::opTypeId() const -> size_t { return typeId(); } | ||
auto Op::opTypeName() const -> std::string_view { return "onnx::Einsum"; } | ||
|
||
auto Op::infer(TensorRefs inputs, InferOptions const &) const -> InferResult { | ||
if (inputs.empty()) { | ||
return Err(InferError(ERROR_MSG("Input size error"))); | ||
} | ||
TODO(""); | ||
} | ||
|
||
auto Op::lower(TensorRefs) const -> computation::OpBox { | ||
TODO(""); | ||
} | ||
|
||
}// namespace refactor::onnx |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#ifndef ONNX_EINSUM_HH | ||
#define ONNX_EINSUM_HH | ||
|
||
#include "frontend/operator.h" | ||
|
||
namespace refactor::onnx { | ||
using namespace frontend; | ||
|
||
struct Einsum final : public Operator { | ||
std::string equation; | ||
|
||
Einsum(std::string); | ||
|
||
static OpBox build(std::string_view, Attributes); | ||
static size_t typeId(); | ||
|
||
size_t opTypeId() const final; | ||
std::string_view opTypeName() const final; | ||
InferResult infer(TensorRefs, InferOptions const &) const final; | ||
computation::OpBox lower(TensorRefs) const final; | ||
}; | ||
|
||
}// namespace refactor::onnx | ||
|
||
#endif// ONNX_EINSUM_HH |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#include "../src/operators/einsum.hh" | ||
#include "onnx/operators.h" | ||
#include <gtest/gtest.h> | ||
|
||
using namespace refactor; | ||
using namespace frontend; | ||
using namespace onnx; | ||
|
||
TEST(infer, Einsum) { | ||
onnx::register_(); | ||
auto edges = Edges{{Tensor::share(DataType::F32, Shape{DimExpr(2), DimExpr(5)}, {}), ""}}; | ||
graph_topo::idx_t inputs[]{0}; | ||
// auto infered = Einsum("ij->ji").infer(TensorRefs(edges, slice(inputs, 1)), {true}); | ||
// ASSERT_TRUE(infered.isOk()); | ||
// auto outputs = std::move(infered.unwrap()); | ||
// ASSERT_EQ(outputs.size(), 1); | ||
// auto y = std::move(outputs[0]); | ||
// ASSERT_EQ(y->dataType, DataType::F32); | ||
// ASSERT_EQ(y->shape, (Shape{DimExpr(5), DimExpr(2)})); | ||
} |