forked from jiuyuan/InfiniTensor
Add: test for class GraphFactoryObj
This commit is contained in:
parent
fe535e72a7
commit
4836decc69
|
@ -8,7 +8,7 @@ Operator GraphFactoryObj::conv(Tensor input, Tensor weight, Tensor output,
|
|||
Tensor i0 = g->addTensor(input->getDims(), input->getDType());
|
||||
Tensor w0 = g->addTensor(weight->getDims(), weight->getDType());
|
||||
Tensor o0 = g->addTensor(output->getDims(), output->getDType());
|
||||
auto op = g->addOp<ConvObj>(i0, w0, o0, ph, ph, sh, sw, dh, dw, bias);
|
||||
auto op = g->addOpWithOutputs<ConvObj>(i0, w0, o0, ph, ph, sh, sw, dh, dw, bias);
|
||||
return op;
|
||||
}
|
||||
|
||||
|
@ -26,7 +26,7 @@ Operator GraphFactoryObj::conv(Tensor input, Tensor weight, Tensor output,
|
|||
Tensor i0 = g->addTensor(input->getDims(), input->getDType());
|
||||
Tensor w0 = g->addTensor(weight->getDims(), weight->getDType());
|
||||
Tensor o0 = g->addTensor(output->getDims(), output->getDType());
|
||||
auto op = g->addOp<ConvObj>(i0, w0, o0, pm, sh, sw, dh, dw, bias);
|
||||
auto op = g->addOpWithOutputs<ConvObj>(i0, w0, o0, pm, sh, sw, dh, dw, bias);
|
||||
return op;
|
||||
}
|
||||
|
||||
|
@ -44,7 +44,7 @@ Operator GraphFactoryObj::matmul(Tensor A, Tensor B, Tensor C, bool transA,
|
|||
Tensor i0 = g->addTensor(A->getDims(), A->getDType());
|
||||
Tensor i1 = g->addTensor(B->getDims(), B->getDType());
|
||||
Tensor o0 = g->addTensor(C->getDims(), C->getDType());
|
||||
auto op = g->addOp<MatmulObj>(i0, i1, o0, transA, transB, bias, act);
|
||||
auto op = g->addOpWithOutputs<MatmulObj>(i0, i1, o0, transA, transB, bias, act);
|
||||
return op;
|
||||
}
|
||||
|
||||
|
@ -63,7 +63,7 @@ Operator GraphFactoryObj::convTrans(Tensor input, Tensor weight, Tensor output,
|
|||
Tensor i0 = g->addTensor(input->getDims(), input->getDType());
|
||||
Tensor w0 = g->addTensor(weight->getDims(), weight->getDType());
|
||||
Tensor o0 = g->addTensor(output->getDims(), output->getDType());
|
||||
auto op = g->addOp<ConvTransposed2dObj>(i0, w0, o0, ph, pw, sh, sw, dh, dw,
|
||||
auto op = g->addOpWithOutputs<ConvTransposed2dObj>(i0, w0, o0, ph, pw, sh, sw, dh, dw,
|
||||
oph, opw, group, bias, act);
|
||||
return op;
|
||||
}
|
||||
|
@ -86,7 +86,7 @@ Operator GraphFactoryObj::convTrans(Tensor input, Tensor weight, Tensor output,
|
|||
Tensor i0 = g->addTensor(input->getDims(), input->getDType());
|
||||
Tensor w0 = g->addTensor(weight->getDims(), weight->getDType());
|
||||
Tensor o0 = g->addTensor(output->getDims(), output->getDType());
|
||||
auto op = g->addOp<ConvTransposed2dObj>(i0, w0, o0, pm, sh, sw, dh, dw, oph,
|
||||
auto op = g->addOpWithOutputs<ConvTransposed2dObj>(i0, w0, o0, pm, sh, sw, dh, dw, oph,
|
||||
opw, group, bias, act);
|
||||
return op;
|
||||
}
|
||||
|
@ -107,7 +107,7 @@ Operator GraphFactoryObj::g2bmm(Tensor A, Tensor B, Tensor C, const int width,
|
|||
Tensor i0 = g->addTensor(A->getDims(), A->getDType());
|
||||
Tensor i1 = g->addTensor(B->getDims(), B->getDType());
|
||||
Tensor o0 = g->addTensor(C->getDims(), C->getDType());
|
||||
auto op = g->addOp<G2BMMObj>(i0, i1, o0, width, dilation, bias, act);
|
||||
auto op = g->addOpWithOutputs<G2BMMObj>(i0, i1, o0, width, dilation, bias, act);
|
||||
return op;
|
||||
}
|
||||
|
||||
|
@ -124,7 +124,7 @@ Operator GraphFactoryObj::gbmml(Tensor A, Tensor B, Tensor C,
|
|||
Tensor i0 = g->addTensor(A->getDims(), A->getDType());
|
||||
Tensor i1 = g->addTensor(B->getDims(), B->getDType());
|
||||
Tensor o0 = g->addTensor(C->getDims(), C->getDType());
|
||||
auto op = g->addOp<GBMMObj>(i0, i1, o0, dilation, bias, act);
|
||||
auto op = g->addOpWithOutputs<GBMMObj>(i0, i1, o0, dilation, bias, act);
|
||||
return op;
|
||||
}
|
||||
|
||||
|
@ -141,7 +141,7 @@ Operator GraphFactoryObj::pad(Tensor input, Tensor output,
|
|||
const optional<const vector<int>> &axis) {
|
||||
Tensor i0 = g->addTensor(input->getDims(), input->getDType());
|
||||
Tensor o0 = g->addTensor(output->getDims(), output->getDType());
|
||||
auto op = g->addOp<PadObj>(i0, o0, pads, axis);
|
||||
auto op = g->addOpWithOutputs<PadObj>(i0, o0, pads, axis);
|
||||
return op;
|
||||
}
|
||||
|
||||
|
@ -159,7 +159,7 @@ Operator GraphFactoryObj::slice(Tensor input, Tensor output,
|
|||
const optional<vector<int>> &steps) {
|
||||
Tensor i0 = g->addTensor(input->getDims(), input->getDType());
|
||||
Tensor o0 = g->addTensor(output->getDims(), output->getDType());
|
||||
auto op = g->addOp<SliceObj>(i0, o0, starts, ends, axis, steps);
|
||||
auto op = g->addOpWithOutputs<SliceObj>(i0, o0, starts, ends, axis, steps);
|
||||
return op;
|
||||
}
|
||||
|
||||
|
@ -179,7 +179,7 @@ Operator GraphFactoryObj::concat(TensorVec inputs, Tensor output, int dim) {
|
|||
is.push_back(i);
|
||||
}
|
||||
Tensor o = g->addTensor(output->getDims(), output->getDType());
|
||||
auto op = g->addOp<ConcatObj>(is, o, dim);
|
||||
auto op = g->addOpWithOutputs<ConcatObj>(is, o, dim);
|
||||
return op;
|
||||
}
|
||||
|
||||
|
@ -202,7 +202,7 @@ Operator GraphFactoryObj::split(Tensor input, std::optional<TensorVec> outputs,
|
|||
Tensor o = g->addTensor(output->getDims(), output->getDType());
|
||||
os.push_back(o);
|
||||
}
|
||||
auto op = g->addOp<SplitObj>(i, os, dim, num);
|
||||
auto op = g->addOpWithOutputs<SplitObj>(i, os, dim, num);
|
||||
return op;
|
||||
} else {
|
||||
auto op = g->addOp<SplitObj>(i, std::nullopt, dim, num);
|
||||
|
@ -225,7 +225,7 @@ Operator GraphFactoryObj::split(Tensor input, std::optional<TensorVec> outputs,
|
|||
Tensor o = g->addTensor(output->getDims(), output->getDType());
|
||||
os.push_back(o);
|
||||
}
|
||||
auto op = g->addOp<SplitObj>(i, os, dim, ratio);
|
||||
auto op = g->addOpWithOutputs<SplitObj>(i, os, dim, ratio);
|
||||
return op;
|
||||
} else {
|
||||
auto op = g->addOp<SplitObj>(i, std::nullopt, dim, ratio);
|
||||
|
@ -244,7 +244,7 @@ Operator GraphFactoryObj::extend(Tensor input, Tensor output, int dim,
|
|||
int num) {
|
||||
Tensor i0 = g->addTensor(input->getDims(), input->getDType());
|
||||
Tensor o0 = g->addTensor(output->getDims(), output->getDType());
|
||||
auto op = g->addOp<ExtendObj>(i0, o0, dim, num);
|
||||
auto op = g->addOpWithOutputs<ExtendObj>(i0, o0, dim, num);
|
||||
return op;
|
||||
}
|
||||
|
||||
|
@ -259,7 +259,7 @@ Operator GraphFactoryObj::maxpool(Tensor input, Tensor output, int kh, int kw,
|
|||
int sw) {
|
||||
Tensor i0 = g->addTensor(input->getDims(), input->getDType());
|
||||
Tensor o0 = g->addTensor(output->getDims(), output->getDType());
|
||||
auto op = g->addOp<MaxPoolObj>(i0, o0, kh, kw, dh, dw, ph, pw, sh, sw);
|
||||
auto op = g->addOpWithOutputs<MaxPoolObj>(i0, o0, kh, kw, dh, dw, ph, pw, sh, sw);
|
||||
return op;
|
||||
}
|
||||
|
||||
|
@ -275,7 +275,7 @@ Operator GraphFactoryObj::avgpool(Tensor input, Tensor output, int kh, int kw,
|
|||
int sw) {
|
||||
Tensor i0 = g->addTensor(input->getDims(), input->getDType());
|
||||
Tensor o0 = g->addTensor(input->getDims(), input->getDType());
|
||||
auto op = g->addOp<AvgPoolObj>(i0, o0, kh, kw, dh, dw, ph, pw, sh, sw);
|
||||
auto op = g->addOpWithOutputs<AvgPoolObj>(i0, o0, kh, kw, dh, dw, ph, pw, sh, sw);
|
||||
return op;
|
||||
}
|
||||
|
||||
|
@ -290,7 +290,7 @@ Operator GraphFactoryObj::add(Tensor input0, Tensor input1, Tensor output) {
|
|||
Tensor i0 = g->addTensor(input0->getDims(), input0->getDType());
|
||||
Tensor i1 = g->addTensor(input1->getDims(), input1->getDType());
|
||||
Tensor o0 = g->addTensor(output->getDims(), output->getDType());
|
||||
auto op = g->addOp<AddObj>(i0, i1, o0);
|
||||
auto op = g->addOpWithOutputs<AddObj>(i0, i1, o0);
|
||||
return op;
|
||||
}
|
||||
|
||||
|
@ -305,7 +305,7 @@ Operator GraphFactoryObj::sub(Tensor input0, Tensor input1, Tensor output) {
|
|||
Tensor i0 = g->addTensor(input0->getDims(), input0->getDType());
|
||||
Tensor i1 = g->addTensor(input1->getDims(), input1->getDType());
|
||||
Tensor o0 = g->addTensor(output->getDims(), output->getDType());
|
||||
auto op = g->addOp<SubObj>(i0, i1, o0);
|
||||
auto op = g->addOpWithOutputs<SubObj>(i0, i1, o0);
|
||||
return op;
|
||||
}
|
||||
|
||||
|
@ -320,7 +320,7 @@ Operator GraphFactoryObj::mul(Tensor input0, Tensor input1, Tensor output) {
|
|||
Tensor i0 = g->addTensor(input0->getDims(), input0->getDType());
|
||||
Tensor i1 = g->addTensor(input1->getDims(), input1->getDType());
|
||||
Tensor o0 = g->addTensor(output->getDims(), output->getDType());
|
||||
auto op = g->addOp<MulObj>(i0, i1, o0);
|
||||
auto op = g->addOpWithOutputs<MulObj>(i0, i1, o0);
|
||||
return op;
|
||||
}
|
||||
|
||||
|
@ -335,7 +335,7 @@ Operator GraphFactoryObj::div(Tensor input0, Tensor input1, Tensor output) {
|
|||
Tensor i0 = g->addTensor(input0->getDims(), input0->getDType());
|
||||
Tensor i1 = g->addTensor(input1->getDims(), input1->getDType());
|
||||
Tensor o0 = g->addTensor(output->getDims(), output->getDType());
|
||||
auto op = g->addOp<DivObj>(i0, i1, o0);
|
||||
auto op = g->addOpWithOutputs<DivObj>(i0, i1, o0);
|
||||
return op;
|
||||
}
|
||||
|
||||
|
@ -350,7 +350,7 @@ Operator GraphFactoryObj::pow(Tensor input0, Tensor input1, Tensor output) {
|
|||
Tensor i0 = g->addTensor(input0->getDims(), input0->getDType());
|
||||
Tensor i1 = g->addTensor(input1->getDims(), input1->getDType());
|
||||
Tensor o0 = g->addTensor(output->getDims(), output->getDType());
|
||||
auto op = g->addOp<PowObj>(i0, i1, o0);
|
||||
auto op = g->addOpWithOutputs<PowObj>(i0, i1, o0);
|
||||
return op;
|
||||
}
|
||||
|
||||
|
@ -365,7 +365,7 @@ Operator GraphFactoryObj::gather(Tensor input, Tensor index, Tensor output,
|
|||
int axis) {
|
||||
Tensor i0 = g->addTensor(input->getDims(), input->getDType());
|
||||
Tensor o0 = g->addTensor(output->getDims(), output->getDType());
|
||||
auto op = g->addOp<GatherObj>(i0, index, o0, axis);
|
||||
auto op = g->addOpWithOutputs<GatherObj>(i0, index, o0, axis);
|
||||
return op;
|
||||
}
|
||||
|
||||
|
@ -379,7 +379,7 @@ Operator GraphFactoryObj::reshape(Tensor input, Tensor output,
|
|||
const Shape &dims) {
|
||||
Tensor i0 = g->addTensor(input->getDims(), input->getDType());
|
||||
Tensor o0 = g->addTensor(output->getDims(), output->getDType());
|
||||
auto op = g->addOp<ReshapeObj>(i0, o0, dims);
|
||||
auto op = g->addOpWithOutputs<ReshapeObj>(i0, o0, dims);
|
||||
return op;
|
||||
}
|
||||
|
||||
|
@ -392,7 +392,7 @@ Operator GraphFactoryObj::reshape(Tensor input, const Shape &dims) {
|
|||
Operator GraphFactoryObj::flatten(Tensor input, Tensor output) {
|
||||
Tensor i0 = g->addTensor(input->getDims(), input->getDType());
|
||||
Tensor o0 = g->addTensor(output->getDims(), output->getDType());
|
||||
auto op = g->addOp<FlattenObj>(i0, o0);
|
||||
auto op = g->addOpWithOutputs<FlattenObj>(i0, o0);
|
||||
return op;
|
||||
}
|
||||
|
||||
|
@ -405,7 +405,7 @@ Operator GraphFactoryObj::flatten(Tensor input) {
|
|||
Operator GraphFactoryObj::identity(Tensor input, Tensor output) {
|
||||
Tensor i0 = g->addTensor(input->getDims(), input->getDType());
|
||||
Tensor o0 = g->addTensor(output->getDims(), output->getDType());
|
||||
auto op = g->addOp<IdentityObj>(i0, o0);
|
||||
auto op = g->addOpWithOutputs<IdentityObj>(i0, o0);
|
||||
return op;
|
||||
}
|
||||
|
||||
|
@ -418,7 +418,7 @@ Operator GraphFactoryObj::identity(Tensor input) {
|
|||
Operator GraphFactoryObj::softmax(Tensor input, Tensor output) {
|
||||
Tensor i0 = g->addTensor(input->getDims(), input->getDType());
|
||||
Tensor o0 = g->addTensor(output->getDims(), output->getDType());
|
||||
auto op = g->addOp<SoftmaxObj>(i0, o0);
|
||||
auto op = g->addOpWithOutputs<SoftmaxObj>(i0, o0);
|
||||
return op;
|
||||
}
|
||||
|
||||
|
@ -431,7 +431,7 @@ Operator GraphFactoryObj::softmax(Tensor input) {
|
|||
Operator GraphFactoryObj::relu(Tensor input, Tensor output) {
|
||||
Tensor i0 = g->addTensor(input->getDims(), input->getDType());
|
||||
Tensor o0 = g->addTensor(output->getDims(), output->getDType());
|
||||
auto op = g->addOp<ReluObj>(i0, o0);
|
||||
auto op = g->addOpWithOutputs<ReluObj>(i0, o0);
|
||||
return op;
|
||||
}
|
||||
|
||||
|
@ -444,7 +444,7 @@ Operator GraphFactoryObj::relu(Tensor input) {
|
|||
Operator GraphFactoryObj::sigmoid(Tensor input, Tensor output) {
|
||||
Tensor i0 = g->addTensor(input->getDims(), input->getDType());
|
||||
Tensor o0 = g->addTensor(output->getDims(), output->getDType());
|
||||
auto op = g->addOp<SigmoidObj>(i0, o0);
|
||||
auto op = g->addOpWithOutputs<SigmoidObj>(i0, o0);
|
||||
return op;
|
||||
}
|
||||
|
||||
|
@ -457,7 +457,7 @@ Operator GraphFactoryObj::sigmoid(Tensor input) {
|
|||
Operator GraphFactoryObj::tanh(Tensor input, Tensor output) {
|
||||
Tensor i0 = g->addTensor(input->getDims(), input->getDType());
|
||||
Tensor o0 = g->addTensor(output->getDims(), output->getDType());
|
||||
auto op = g->addOp<TanhObj>(i0, o0);
|
||||
auto op = g->addOpWithOutputs<TanhObj>(i0, o0);
|
||||
return op;
|
||||
}
|
||||
|
||||
|
@ -470,7 +470,7 @@ Operator GraphFactoryObj::tanh(Tensor input) {
|
|||
Operator GraphFactoryObj::abs(Tensor input, Tensor output) {
|
||||
Tensor i0 = g->addTensor(input->getDims(), input->getDType());
|
||||
Tensor o0 = g->addTensor(output->getDims(), output->getDType());
|
||||
auto op = g->addOp<AbsObj>(i0, o0);
|
||||
auto op = g->addOpWithOutputs<AbsObj>(i0, o0);
|
||||
return op;
|
||||
}
|
||||
|
||||
|
@ -495,7 +495,7 @@ Operator GraphFactoryObj::memBound(const TensorVec &inputs,
|
|||
auto o = g->addTensor(output->getDims(), output->getDType());
|
||||
os.push_back(o);
|
||||
}
|
||||
auto op = g->addOp<MemBoundObj>(is, os, nnetInputs, expr, exec_time, hint);
|
||||
auto op = g->addOpWithOutputs<MemBoundObj>(is, os, nnetInputs, expr, exec_time, hint);
|
||||
return op;
|
||||
}
|
||||
|
||||
|
|
|
@ -3,9 +3,260 @@
|
|||
|
||||
namespace infini {
|
||||
|
||||
TEST(GraphFactory, build_and_run) {
|
||||
TEST(GraphFactory, ops) {
|
||||
Runtime runtime = CpuRuntimeObj::getInstance();
|
||||
GraphFactory gf = make_ref<GraphFactoryObj>(runtime);
|
||||
{ // conv without output
|
||||
GraphFactory gf = make_ref<GraphFactoryObj>(runtime);
|
||||
auto input =
|
||||
make_ref<TensorObj>(Shape{1, 3, 4, 4}, DataType::UInt32, runtime);
|
||||
auto weight =
|
||||
make_ref<TensorObj>(Shape{2, 3, 3, 3}, DataType::UInt32, runtime);
|
||||
auto conv =
|
||||
gf->conv(input, weight, 1, 1);
|
||||
EXPECT_EQ(conv->getOutput()->getDims(), (Shape{1, 2, 4, 4}));
|
||||
}
|
||||
{ // conv with output
|
||||
GraphFactory gf = make_ref<GraphFactoryObj>(runtime);
|
||||
auto input =
|
||||
make_ref<TensorObj>(Shape{1, 3, 4, 4}, DataType::UInt32, runtime);
|
||||
auto weight =
|
||||
make_ref<TensorObj>(Shape{2, 3, 3, 3}, DataType::UInt32, runtime);
|
||||
auto output =
|
||||
make_ref<TensorObj>(Shape{1, 2, 4, 4}, DataType::UInt32, runtime);
|
||||
auto conv = gf->conv(input, weight, output, 1, 1);
|
||||
}
|
||||
{ // matmul without output
|
||||
GraphFactory gf = make_ref<GraphFactoryObj>(runtime);
|
||||
auto A = make_ref<TensorObj>(Shape{1, 3, 5}, DataType::UInt32, runtime);
|
||||
auto B = make_ref<TensorObj>(Shape{1, 5, 2}, DataType::UInt32, runtime);
|
||||
auto matmul = gf->matmul(A, B);
|
||||
EXPECT_EQ(matmul->getOutput()->getDims(), (Shape{1, 3, 2}));
|
||||
}
|
||||
{ // matmul with output
|
||||
GraphFactory gf = make_ref<GraphFactoryObj>(runtime);
|
||||
auto A = make_ref<TensorObj>(Shape{1, 3, 5}, DataType::UInt32, runtime);
|
||||
auto B = make_ref<TensorObj>(Shape{1, 5, 2}, DataType::UInt32, runtime);
|
||||
auto C = make_ref<TensorObj>(Shape{1, 3, 2}, DataType::UInt32, runtime);
|
||||
auto matmul = gf->matmul(A, B, C);
|
||||
}
|
||||
{ // convtrans without output
|
||||
GraphFactory gf = make_ref<GraphFactoryObj>(runtime);
|
||||
auto input =
|
||||
make_ref<TensorObj>(Shape{1, 228, 1, 1}, DataType::UInt32, runtime);
|
||||
auto weight =
|
||||
make_ref<TensorObj>(Shape{228, 448, 2, 2}, DataType::UInt32, runtime);
|
||||
auto convtrans = gf->convTrans(input, weight, 0, 0);
|
||||
EXPECT_EQ(convtrans->getOutput()->getDims(), (Shape{1, 448, 2, 2}));
|
||||
}
|
||||
{ // convtrans with output
|
||||
GraphFactory gf = make_ref<GraphFactoryObj>(runtime);
|
||||
auto input =
|
||||
make_ref<TensorObj>(Shape{1, 228, 1, 1}, DataType::UInt32, runtime);
|
||||
auto weight = make_ref<TensorObj>(Shape{228, 448, 2, 2},
|
||||
DataType::UInt32, runtime);
|
||||
auto output =
|
||||
make_ref<TensorObj>(Shape{1, 448, 2, 2}, DataType::UInt32, runtime);
|
||||
auto convtrans = gf->convTrans(input, weight, 0, 0);
|
||||
}
|
||||
{ // pad without output
|
||||
GraphFactory gf = make_ref<GraphFactoryObj>(runtime);
|
||||
auto input =
|
||||
make_ref<TensorObj>(Shape{1, 64, 162, 162}, DataType::UInt32, runtime);
|
||||
vector<int> pads = {2, 10, 1, 5, 0, 10, 1, 5};
|
||||
auto pad = gf->pad(input, pads, std::nullopt);
|
||||
EXPECT_EQ(pad->getOutput()->getDims(), (Shape{3, 84, 164, 172}));
|
||||
}
|
||||
{ // pad with output
|
||||
GraphFactory gf = make_ref<GraphFactoryObj>(runtime);
|
||||
auto input = make_ref<TensorObj>(Shape{1, 64, 162, 162},
|
||||
DataType::UInt32, runtime);
|
||||
auto output = make_ref<TensorObj>(Shape{3, 84, 164, 172},
|
||||
DataType::UInt32, runtime);
|
||||
vector<int> pads = {2, 10, 1, 5, 0, 10, 1, 5};
|
||||
auto pad = gf->pad(input, output, pads, std::nullopt);
|
||||
}
|
||||
{ // slice without output
|
||||
GraphFactory gf = make_ref<GraphFactoryObj>(runtime);
|
||||
auto input = make_ref<TensorObj>(Shape{10, 64, 162, 162},
|
||||
DataType::UInt32, runtime);
|
||||
vector<int> starts = {2, 10, 1, 5};
|
||||
vector<int> ends = {3, 10, 100, 100};
|
||||
auto slice = gf->slice(input, starts, ends, std::nullopt, std::nullopt);
|
||||
EXPECT_EQ(slice->getOutput()->getDims(), (Shape{2, 1, 100, 96}));
|
||||
}
|
||||
{ // slice with output
|
||||
GraphFactory gf = make_ref<GraphFactoryObj>(runtime);
|
||||
auto input = make_ref<TensorObj>(Shape{10, 64, 162, 162},
|
||||
DataType::UInt32, runtime);
|
||||
auto output = make_ref<TensorObj>(Shape{2, 1, 100, 96},
|
||||
DataType::UInt32, runtime);
|
||||
vector<int> starts = {2, 10, 1, 5};
|
||||
vector<int> ends = {3, 10, 100, 100};
|
||||
auto slice = gf->slice(input, output, starts, ends, std::nullopt, std::nullopt);
|
||||
}
|
||||
{ // concat without output
|
||||
GraphFactory gf = make_ref<GraphFactoryObj>(runtime);
|
||||
auto t1 =
|
||||
make_ref<TensorObj>(Shape{1, 3, 2, 4}, DataType::Float32, runtime);
|
||||
auto t2 =
|
||||
make_ref<TensorObj>(Shape{1, 3, 2, 5}, DataType::Float32, runtime);
|
||||
auto concat = gf->concat(TensorVec{t1, t2}, 3);
|
||||
EXPECT_EQ(concat->getOutput()->getDims(), (Shape{1, 3, 2, 9}));
|
||||
}
|
||||
{ // concat with output
|
||||
GraphFactory gf = make_ref<GraphFactoryObj>(runtime);
|
||||
auto t1 =
|
||||
make_ref<TensorObj>(Shape{1, 3, 2, 4}, DataType::Float32, runtime);
|
||||
auto t2 =
|
||||
make_ref<TensorObj>(Shape{1, 3, 2, 5}, DataType::Float32, runtime);
|
||||
auto o0 =
|
||||
make_ref<TensorObj>(Shape{1, 3, 2, 9}, DataType::Float32, runtime);
|
||||
auto concat = gf->concat(TensorVec{t1, t2}, o0, 3);
|
||||
}
|
||||
{ // split without output
|
||||
GraphFactory gf = make_ref<GraphFactoryObj>(runtime);
|
||||
auto input = make_ref<TensorObj>(Shape{1, 3, 2, 15}, DataType::Float32, runtime);
|
||||
auto split = gf->split(input, 3, 4);
|
||||
EXPECT_EQ(split->numOutputs(), 4);
|
||||
EXPECT_EQ(split->getOutputs().size(), (size_t)4);
|
||||
EXPECT_EQ(split->getOutput(0)->getDims(), (Shape{1, 3, 2, 3}));
|
||||
EXPECT_EQ(split->getOutput(1)->getDims(), (Shape{1, 3, 2, 3}));
|
||||
EXPECT_EQ(split->getOutput(2)->getDims(), (Shape{1, 3, 2, 3}));
|
||||
EXPECT_EQ(split->getOutput(3)->getDims(), (Shape{1, 3, 2, 6}));
|
||||
}
|
||||
{ // split with output
|
||||
GraphFactory gf = make_ref<GraphFactoryObj>(runtime);
|
||||
auto input =
|
||||
make_ref<TensorObj>(Shape{1, 3, 2, 15}, DataType::Float32, runtime);
|
||||
auto output0 =
|
||||
make_ref<TensorObj>(Shape{1, 3, 2, 3}, DataType::Float32, runtime);
|
||||
auto output1 =
|
||||
make_ref<TensorObj>(Shape{1, 3, 2, 3}, DataType::Float32, runtime);
|
||||
auto output2 =
|
||||
make_ref<TensorObj>(Shape{1, 3, 2, 3}, DataType::Float32, runtime);
|
||||
auto output3 =
|
||||
make_ref<TensorObj>(Shape{1, 3, 2, 6}, DataType::Float32, runtime);
|
||||
auto split = gf->split(input, TensorVec{output0, output1, output2, output3}, 3, 4);
|
||||
}
|
||||
{ // extend without output
|
||||
GraphFactory gf = make_ref<GraphFactoryObj>(runtime);
|
||||
auto input =
|
||||
make_ref<TensorObj>(Shape{2, 3, 3, 4}, DataType::UInt32, runtime);
|
||||
auto extend = gf->extend(input, 2, 1);
|
||||
EXPECT_EQ(extend->getOutput()->getDims(), (Shape{2, 3, 6, 4}));
|
||||
}
|
||||
{ // extend with output
|
||||
GraphFactory gf = make_ref<GraphFactoryObj>(runtime);
|
||||
auto input =
|
||||
make_ref<TensorObj>(Shape{2, 3, 3, 4}, DataType::UInt32, runtime);
|
||||
auto output =
|
||||
make_ref<TensorObj>(Shape{2, 3, 6, 4}, DataType::UInt32, runtime);
|
||||
auto extend = gf->extend(input, output, 2, 1);
|
||||
}
|
||||
{ // maxpool without output
|
||||
GraphFactory gf = make_ref<GraphFactoryObj>(runtime);
|
||||
auto input =
|
||||
make_ref<TensorObj>(Shape{1, 64, 162, 162}, DataType::UInt32, runtime);
|
||||
const int kh = 3, kw = 3, dh = 1, dw = 1, ph = 0, pw = 0, sh = 2,
|
||||
sw = 2;
|
||||
auto maxpool = gf->maxpool(input, kh, kw, dh, dw, ph, pw, sh, sw);
|
||||
EXPECT_EQ(maxpool->getOutput()->getDims(), (Shape{1, 64, 80, 80}));
|
||||
}
|
||||
{ // maxpool with output
|
||||
GraphFactory gf = make_ref<GraphFactoryObj>(runtime);
|
||||
auto input = make_ref<TensorObj>(Shape{1, 64, 162, 162},
|
||||
DataType::UInt32, runtime);
|
||||
auto output = make_ref<TensorObj>(Shape{1, 64, 80, 80},
|
||||
DataType::UInt32, runtime);
|
||||
const int kh = 3, kw = 3, dh = 1, dw = 1, ph = 0, pw = 0, sh = 2,
|
||||
sw = 2;
|
||||
auto maxpool = gf->maxpool(input, output, kh, kw, dh, dw, ph, pw, sh, sw);
|
||||
}
|
||||
{ // add without output
|
||||
GraphFactory gf = make_ref<GraphFactoryObj>(runtime);
|
||||
auto input0 = make_ref<TensorObj>(Shape{2, 3, 3, 4},
|
||||
DataType::UInt32, runtime);
|
||||
auto input1 =
|
||||
make_ref<TensorObj>(Shape{2, 3, 3, 4}, DataType::UInt32, runtime);
|
||||
auto add = gf->add(input0, input1);
|
||||
EXPECT_EQ(add->getOutput()->getDims(), (Shape{2, 3, 3, 4}));
|
||||
}
|
||||
{ // add with output
|
||||
GraphFactory gf = make_ref<GraphFactoryObj>(runtime);
|
||||
auto input0 =
|
||||
make_ref<TensorObj>(Shape{2, 3, 3, 4}, DataType::UInt32, runtime);
|
||||
auto input1 =
|
||||
make_ref<TensorObj>(Shape{2, 3, 3, 4}, DataType::UInt32, runtime);
|
||||
auto output =
|
||||
make_ref<TensorObj>(Shape{2, 3, 3, 4}, DataType::UInt32, runtime);
|
||||
auto add = gf->add(input0, input1, output);
|
||||
}
|
||||
{ // gather without output
|
||||
GraphFactory gf = make_ref<GraphFactoryObj>(runtime);
|
||||
auto input =
|
||||
make_ref<TensorObj>(Shape{1, 3, 4, 4}, DataType::UInt32, runtime);
|
||||
auto index =
|
||||
make_ref<TensorObj>(Shape{2, 1, 2}, DataType::UInt32, runtime);
|
||||
auto gather = gf->gather(input, index, 1);
|
||||
EXPECT_EQ(gather->getOutput()->getDims(), (Shape{1, 2, 1, 2, 4, 4}));
|
||||
}
|
||||
{ // gather with output
|
||||
GraphFactory gf = make_ref<GraphFactoryObj>(runtime);
|
||||
auto input =
|
||||
make_ref<TensorObj>(Shape{1, 3, 4, 4}, DataType::UInt32, runtime);
|
||||
auto index =
|
||||
make_ref<TensorObj>(Shape{2, 1, 2}, DataType::UInt32, runtime);
|
||||
auto output =
|
||||
make_ref<TensorObj>(Shape{1, 2, 1, 2, 4, 4}, DataType::UInt32, runtime);
|
||||
auto gather = gf->gather(input, index, output, 1);
|
||||
}
|
||||
{ // reshape without output
|
||||
GraphFactory gf = make_ref<GraphFactoryObj>(runtime);
|
||||
auto input =
|
||||
make_ref<TensorObj>(Shape{2, 3, 3, 4}, DataType::Float32, runtime);
|
||||
vector<int> dims = {3, 2, 4, 3};
|
||||
auto reshape = gf->reshape(input, dims);
|
||||
EXPECT_EQ(reshape->getOutput()->getDims(), (Shape{3, 2, 4, 3}));
|
||||
}
|
||||
{ // reshape with output
|
||||
GraphFactory gf = make_ref<GraphFactoryObj>(runtime);
|
||||
auto input =
|
||||
make_ref<TensorObj>(Shape{2, 3, 3, 4}, DataType::Float32, runtime);
|
||||
vector<int> dims = {3, 2, 4, 3};
|
||||
auto output =
|
||||
make_ref<TensorObj>(Shape{3, 2, 4, 3}, DataType::Float32, runtime);
|
||||
auto reshape = gf->reshape(input, output, dims);
|
||||
}
|
||||
{ // flatten without output
|
||||
GraphFactory gf = make_ref<GraphFactoryObj>(runtime);
|
||||
auto input =
|
||||
make_ref<TensorObj>(Shape{2, 3, 3, 4}, DataType::Float32, runtime);
|
||||
auto flatten = gf->flatten(input);
|
||||
EXPECT_EQ(flatten->getOutput()->getDims(), (Shape{72}));
|
||||
}
|
||||
{ // flatten without output
|
||||
GraphFactory gf = make_ref<GraphFactoryObj>(runtime);
|
||||
auto input =
|
||||
make_ref<TensorObj>(Shape{2, 3, 3, 4}, DataType::Float32, runtime);
|
||||
auto output =
|
||||
make_ref<TensorObj>(Shape{72}, DataType::Float32, runtime);
|
||||
auto flatten = gf->flatten(input, output);
|
||||
}
|
||||
{ // identity without output
|
||||
GraphFactory gf = make_ref<GraphFactoryObj>(runtime);
|
||||
auto input =
|
||||
make_ref<TensorObj>(Shape{2, 3, 3, 4}, DataType::Float32, runtime);
|
||||
auto identity = gf->identity(input);
|
||||
EXPECT_EQ(identity->getOutput()->getDims(), (Shape{2, 3, 3, 4}));
|
||||
}
|
||||
{ // identity without output
|
||||
GraphFactory gf = make_ref<GraphFactoryObj>(runtime);
|
||||
auto input =
|
||||
make_ref<TensorObj>(Shape{2, 3, 3, 4}, DataType::Float32, runtime);
|
||||
auto output =
|
||||
make_ref<TensorObj>(Shape{2, 3, 3, 4}, DataType::Float32, runtime);
|
||||
auto identity = gf->identity(input, output);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace infini
|
Loading…
Reference in New Issue