-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #50 from ispras/dfcir_unit_tests
DFCIR unit tests
- Loading branch information
Showing
17 changed files
with
1,633 additions
and
0 deletions.
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,10 @@ | ||
module { | ||
dfcir.kernel "AddConst" { | ||
%0 = dfcir.constant<!dfcir.fixed<false, 32, 0>> 5 : ui32 | ||
%1 = dfcir.input<!dfcir.fixed<false, 32, 0>> ("x") | ||
%2 = dfcir.add(%1 : !dfcir.stream<!dfcir.fixed<false, 32, 0>>, %0 : !dfcir.const<!dfcir.fixed<false, 32, 0>>) : !dfcir.stream<!dfcir.fixed<false, 32, 0>> | ||
%3 = dfcir.add(%2 : !dfcir.stream<!dfcir.fixed<false, 32, 0>>, %1 : !dfcir.stream<!dfcir.fixed<false, 32, 0>>) : !dfcir.stream<!dfcir.fixed<false, 32, 0>> | ||
%4 = dfcir.output<!dfcir.fixed<false, 32, 0>> ("out") {operandSegmentSizes = array<i32: 0, 0>} | ||
dfcir.connect(%4 : !dfcir.stream<!dfcir.fixed<false, 32, 0>>, %3 : !dfcir.stream<!dfcir.fixed<false, 32, 0>>) | ||
} | ||
} |
Large diffs are not rendered by default.
Oops, something went wrong.
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,32 @@ | ||
module { | ||
dfcir.kernel "MatrixMul2" { | ||
%0 = dfcir.input<!dfcir.fixed<false, 32, 0>> ("y22") | ||
%1 = dfcir.input<!dfcir.fixed<false, 32, 0>> ("y21") | ||
%2 = dfcir.input<!dfcir.fixed<false, 32, 0>> ("y12") | ||
%3 = dfcir.input<!dfcir.fixed<false, 32, 0>> ("y11") | ||
%4 = dfcir.input<!dfcir.fixed<false, 32, 0>> ("x22") | ||
%5 = dfcir.mul(%4 : !dfcir.stream<!dfcir.fixed<false, 32, 0>>, %0 : !dfcir.stream<!dfcir.fixed<false, 32, 0>>) : !dfcir.stream<!dfcir.fixed<false, 32, 0>> | ||
%6 = dfcir.mul(%4 : !dfcir.stream<!dfcir.fixed<false, 32, 0>>, %1 : !dfcir.stream<!dfcir.fixed<false, 32, 0>>) : !dfcir.stream<!dfcir.fixed<false, 32, 0>> | ||
%7 = dfcir.input<!dfcir.fixed<false, 32, 0>> ("x21") | ||
%8 = dfcir.mul(%7 : !dfcir.stream<!dfcir.fixed<false, 32, 0>>, %2 : !dfcir.stream<!dfcir.fixed<false, 32, 0>>) : !dfcir.stream<!dfcir.fixed<false, 32, 0>> | ||
%9 = dfcir.add(%8 : !dfcir.stream<!dfcir.fixed<false, 32, 0>>, %5 : !dfcir.stream<!dfcir.fixed<false, 32, 0>>) : !dfcir.stream<!dfcir.fixed<false, 32, 0>> | ||
%10 = dfcir.output<!dfcir.fixed<false, 32, 0>> ("out22") {operandSegmentSizes = array<i32: 0, 0>} | ||
dfcir.connect(%10 : !dfcir.stream<!dfcir.fixed<false, 32, 0>>, %9 : !dfcir.stream<!dfcir.fixed<false, 32, 0>>) | ||
%11 = dfcir.mul(%7 : !dfcir.stream<!dfcir.fixed<false, 32, 0>>, %3 : !dfcir.stream<!dfcir.fixed<false, 32, 0>>) : !dfcir.stream<!dfcir.fixed<false, 32, 0>> | ||
%12 = dfcir.add(%11 : !dfcir.stream<!dfcir.fixed<false, 32, 0>>, %6 : !dfcir.stream<!dfcir.fixed<false, 32, 0>>) : !dfcir.stream<!dfcir.fixed<false, 32, 0>> | ||
%13 = dfcir.output<!dfcir.fixed<false, 32, 0>> ("out21") {operandSegmentSizes = array<i32: 0, 0>} | ||
dfcir.connect(%13 : !dfcir.stream<!dfcir.fixed<false, 32, 0>>, %12 : !dfcir.stream<!dfcir.fixed<false, 32, 0>>) | ||
%14 = dfcir.input<!dfcir.fixed<false, 32, 0>> ("x12") | ||
%15 = dfcir.mul(%14 : !dfcir.stream<!dfcir.fixed<false, 32, 0>>, %0 : !dfcir.stream<!dfcir.fixed<false, 32, 0>>) : !dfcir.stream<!dfcir.fixed<false, 32, 0>> | ||
%16 = dfcir.mul(%14 : !dfcir.stream<!dfcir.fixed<false, 32, 0>>, %1 : !dfcir.stream<!dfcir.fixed<false, 32, 0>>) : !dfcir.stream<!dfcir.fixed<false, 32, 0>> | ||
%17 = dfcir.input<!dfcir.fixed<false, 32, 0>> ("x11") | ||
%18 = dfcir.mul(%17 : !dfcir.stream<!dfcir.fixed<false, 32, 0>>, %2 : !dfcir.stream<!dfcir.fixed<false, 32, 0>>) : !dfcir.stream<!dfcir.fixed<false, 32, 0>> | ||
%19 = dfcir.add(%18 : !dfcir.stream<!dfcir.fixed<false, 32, 0>>, %15 : !dfcir.stream<!dfcir.fixed<false, 32, 0>>) : !dfcir.stream<!dfcir.fixed<false, 32, 0>> | ||
%20 = dfcir.output<!dfcir.fixed<false, 32, 0>> ("out12") {operandSegmentSizes = array<i32: 0, 0>} | ||
dfcir.connect(%20 : !dfcir.stream<!dfcir.fixed<false, 32, 0>>, %19 : !dfcir.stream<!dfcir.fixed<false, 32, 0>>) | ||
%21 = dfcir.mul(%17 : !dfcir.stream<!dfcir.fixed<false, 32, 0>>, %3 : !dfcir.stream<!dfcir.fixed<false, 32, 0>>) : !dfcir.stream<!dfcir.fixed<false, 32, 0>> | ||
%22 = dfcir.add(%21 : !dfcir.stream<!dfcir.fixed<false, 32, 0>>, %16 : !dfcir.stream<!dfcir.fixed<false, 32, 0>>) : !dfcir.stream<!dfcir.fixed<false, 32, 0>> | ||
%23 = dfcir.output<!dfcir.fixed<false, 32, 0>> ("out11") {operandSegmentSizes = array<i32: 0, 0>} | ||
dfcir.connect(%23 : !dfcir.stream<!dfcir.fixed<false, 32, 0>>, %22 : !dfcir.stream<!dfcir.fixed<false, 32, 0>>) | ||
} | ||
} |
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,11 @@ | ||
module { | ||
dfcir.kernel "MovingSum" { | ||
%0 = dfcir.input<!dfcir.fixed<false, 32, 0>> ("x") | ||
%1 = dfcir.offset(%0, 1 : i64) : !dfcir.stream<!dfcir.fixed<false, 32, 0>> | ||
%2 = dfcir.offset(%0, -1 : i64) : !dfcir.stream<!dfcir.fixed<false, 32, 0>> | ||
%3 = dfcir.add(%2 : !dfcir.stream<!dfcir.fixed<false, 32, 0>>, %0 : !dfcir.stream<!dfcir.fixed<false, 32, 0>>) : !dfcir.stream<!dfcir.fixed<false, 32, 0>> | ||
%4 = dfcir.add(%3 : !dfcir.stream<!dfcir.fixed<false, 32, 0>>, %1 : !dfcir.stream<!dfcir.fixed<false, 32, 0>>) : !dfcir.stream<!dfcir.fixed<false, 32, 0>> | ||
%5 = dfcir.output<!dfcir.fixed<false, 32, 0>> ("out") {operandSegmentSizes = array<i32: 0, 0>} | ||
dfcir.connect(%5 : !dfcir.stream<!dfcir.fixed<false, 32, 0>>, %4 : !dfcir.stream<!dfcir.fixed<false, 32, 0>>) | ||
} | ||
} |
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,13 @@ | ||
module { | ||
dfcir.kernel "MuxMul" { | ||
%0 = dfcir.constant<!dfcir.fixed<false, 32, 0>> 1 : ui32 | ||
%1 = dfcir.constant<!dfcir.fixed<false, 32, 0>> 0 : ui32 | ||
%2 = dfcir.input<!dfcir.fixed<false, 1, 0>> ("ctrl") | ||
%3 = dfcir.mux(%2: !dfcir.stream<!dfcir.fixed<false, 1, 0>>, %0, %1) : !dfcir.const<!dfcir.fixed<false, 32, 0>> | ||
%4 = dfcir.input<!dfcir.fixed<false, 32, 0>> ("x") | ||
%5 = dfcir.add(%4 : !dfcir.stream<!dfcir.fixed<false, 32, 0>>, %4 : !dfcir.stream<!dfcir.fixed<false, 32, 0>>) : !dfcir.stream<!dfcir.fixed<false, 32, 0>> | ||
%6 = dfcir.mul(%5 : !dfcir.stream<!dfcir.fixed<false, 32, 0>>, %3 : !dfcir.const<!dfcir.fixed<false, 32, 0>>) : !dfcir.stream<!dfcir.fixed<false, 32, 0>> | ||
%7 = dfcir.output<!dfcir.fixed<false, 32, 0>> ("out") {operandSegmentSizes = array<i32: 0, 0>} | ||
dfcir.connect(%7 : !dfcir.stream<!dfcir.fixed<false, 32, 0>>, %6 : !dfcir.stream<!dfcir.fixed<false, 32, 0>>) | ||
} | ||
} |
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,10 @@ | ||
module { | ||
dfcir.kernel "Polynomial2" { | ||
%0 = dfcir.input<!dfcir.fixed<false, 32, 0>> ("x") | ||
%1 = dfcir.mul(%0 : !dfcir.stream<!dfcir.fixed<false, 32, 0>>, %0 : !dfcir.stream<!dfcir.fixed<false, 32, 0>>) : !dfcir.stream<!dfcir.fixed<false, 32, 0>> | ||
%2 = dfcir.add(%1 : !dfcir.stream<!dfcir.fixed<false, 32, 0>>, %0 : !dfcir.stream<!dfcir.fixed<false, 32, 0>>) : !dfcir.stream<!dfcir.fixed<false, 32, 0>> | ||
%3 = dfcir.add(%2 : !dfcir.stream<!dfcir.fixed<false, 32, 0>>, %0 : !dfcir.stream<!dfcir.fixed<false, 32, 0>>) : !dfcir.stream<!dfcir.fixed<false, 32, 0>> | ||
%4 = dfcir.output<!dfcir.fixed<false, 32, 0>> ("out") {operandSegmentSizes = array<i32: 0, 0>} | ||
dfcir.connect(%4 : !dfcir.stream<!dfcir.fixed<false, 32, 0>>, %3 : !dfcir.stream<!dfcir.fixed<false, 32, 0>>) | ||
} | ||
} |
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,17 @@ | ||
module { | ||
dfcir.kernel "Scalar3" { | ||
%0 = dfcir.input<!dfcir.fixed<false, 32, 0>> ("y3") | ||
%1 = dfcir.input<!dfcir.fixed<false, 32, 0>> ("x3") | ||
%2 = dfcir.mul(%1 : !dfcir.stream<!dfcir.fixed<false, 32, 0>>, %0 : !dfcir.stream<!dfcir.fixed<false, 32, 0>>) : !dfcir.stream<!dfcir.fixed<false, 32, 0>> | ||
%3 = dfcir.input<!dfcir.fixed<false, 32, 0>> ("y2") | ||
%4 = dfcir.input<!dfcir.fixed<false, 32, 0>> ("x2") | ||
%5 = dfcir.mul(%4 : !dfcir.stream<!dfcir.fixed<false, 32, 0>>, %3 : !dfcir.stream<!dfcir.fixed<false, 32, 0>>) : !dfcir.stream<!dfcir.fixed<false, 32, 0>> | ||
%6 = dfcir.input<!dfcir.fixed<false, 32, 0>> ("y1") | ||
%7 = dfcir.input<!dfcir.fixed<false, 32, 0>> ("x1") | ||
%8 = dfcir.mul(%7 : !dfcir.stream<!dfcir.fixed<false, 32, 0>>, %6 : !dfcir.stream<!dfcir.fixed<false, 32, 0>>) : !dfcir.stream<!dfcir.fixed<false, 32, 0>> | ||
%9 = dfcir.add(%8 : !dfcir.stream<!dfcir.fixed<false, 32, 0>>, %5 : !dfcir.stream<!dfcir.fixed<false, 32, 0>>) : !dfcir.stream<!dfcir.fixed<false, 32, 0>> | ||
%10 = dfcir.add(%9 : !dfcir.stream<!dfcir.fixed<false, 32, 0>>, %2 : !dfcir.stream<!dfcir.fixed<false, 32, 0>>) : !dfcir.stream<!dfcir.fixed<false, 32, 0>> | ||
%11 = dfcir.output<!dfcir.fixed<false, 32, 0>> ("out") {operandSegmentSizes = array<i32: 0, 0>} | ||
dfcir.connect(%11 : !dfcir.stream<!dfcir.fixed<false, 32, 0>>, %10 : !dfcir.stream<!dfcir.fixed<false, 32, 0>>) | ||
} | ||
} |
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 |
---|---|---|
@@ -1,6 +1,8 @@ | ||
add_subdirectory(dfcir) | ||
add_subdirectory(dfcxx) | ||
|
||
set(MODEL_TESTS | ||
${DFCIR_TESTS} | ||
${DFCXX_TESTS} | ||
PARENT_SCOPE | ||
) |
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,10 @@ | ||
set(DFCIR_TESTS | ||
model/dfcir/polynomial2.cpp | ||
model/dfcir/scalar3.cpp | ||
model/dfcir/matrixmul2.cpp | ||
model/dfcir/muxmul.cpp | ||
model/dfcir/addconst.cpp | ||
model/dfcir/movingsum.cpp | ||
model/dfcir/idct.cpp | ||
PARENT_SCOPE | ||
) |
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,39 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// Part of the Utopia HLS Project, under the Apache License v2.0 | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// Copyright 2024 ISP RAS (http://www.ispras.ru) | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#include "dfcir/DFCIROperations.h" | ||
|
||
#include "gtest/gtest.h" | ||
#include "llvm/Support/raw_ostream.h" | ||
#include "mlir/Parser/Parser.h" | ||
|
||
#include <fstream> | ||
|
||
#define ADDCONST_DATA_PATH DATA_PATH "/addconst.mlir" | ||
|
||
TEST(DFCIRParsePrint, AddConst) { | ||
std::ifstream fStream(ADDCONST_DATA_PATH); | ||
std::stringstream buf; | ||
buf << fStream.rdbuf(); | ||
std::string inputDfcir = buf.str(); | ||
|
||
// Parse the input DFCIR file. | ||
mlir::MLIRContext ctx; | ||
ctx.getOrLoadDialect<mlir::dfcir::DFCIRDialect>(); | ||
mlir::ParserConfig parserCfg(&ctx); | ||
auto module = mlir::parseSourceString(inputDfcir, parserCfg); | ||
ASSERT_NE(*module, nullptr); | ||
|
||
// Print the parsed DFCIR file. | ||
std::string parsedDfcir; | ||
llvm::raw_string_ostream stream(parsedDfcir); | ||
module->print(stream); | ||
|
||
// Compare the initial and parsed representations. | ||
ASSERT_STREQ(parsedDfcir.c_str(), inputDfcir.c_str()); | ||
} |
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,39 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// Part of the Utopia HLS Project, under the Apache License v2.0 | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// Copyright 2024 ISP RAS (http://www.ispras.ru) | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#include "dfcir/DFCIROperations.h" | ||
|
||
#include "gtest/gtest.h" | ||
#include "llvm/Support/raw_ostream.h" | ||
#include "mlir/Parser/Parser.h" | ||
|
||
#include <fstream> | ||
|
||
#define IDCT_DATA_PATH DATA_PATH "/idct.mlir" | ||
|
||
TEST(DFCIRParsePrint, IDCT) { | ||
std::ifstream fStream(IDCT_DATA_PATH); | ||
std::stringstream buf; | ||
buf << fStream.rdbuf(); | ||
std::string inputDfcir = buf.str(); | ||
|
||
// Parse the input DFCIR file. | ||
mlir::MLIRContext ctx; | ||
ctx.getOrLoadDialect<mlir::dfcir::DFCIRDialect>(); | ||
mlir::ParserConfig parserCfg(&ctx); | ||
auto module = mlir::parseSourceString(inputDfcir, parserCfg); | ||
ASSERT_NE(*module, nullptr); | ||
|
||
// Print the parsed DFCIR file. | ||
std::string parsedDfcir; | ||
llvm::raw_string_ostream stream(parsedDfcir); | ||
module->print(stream); | ||
|
||
// Compare the initial and parsed representations. | ||
ASSERT_STREQ(parsedDfcir.c_str(), inputDfcir.c_str()); | ||
} |
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,39 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// Part of the Utopia HLS Project, under the Apache License v2.0 | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// Copyright 2024 ISP RAS (http://www.ispras.ru) | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#include "dfcir/DFCIROperations.h" | ||
|
||
#include "gtest/gtest.h" | ||
#include "llvm/Support/raw_ostream.h" | ||
#include "mlir/Parser/Parser.h" | ||
|
||
#include <fstream> | ||
|
||
#define MATRIXMUL2_DATA_PATH DATA_PATH "/matrixmul2.mlir" | ||
|
||
TEST(DFCIRParsePrint, MatrixMul2) { | ||
std::ifstream fStream(MATRIXMUL2_DATA_PATH); | ||
std::stringstream buf; | ||
buf << fStream.rdbuf(); | ||
std::string inputDfcir = buf.str(); | ||
|
||
// Parse the input DFCIR file. | ||
mlir::MLIRContext ctx; | ||
ctx.getOrLoadDialect<mlir::dfcir::DFCIRDialect>(); | ||
mlir::ParserConfig parserCfg(&ctx); | ||
auto module = mlir::parseSourceString(inputDfcir, parserCfg); | ||
ASSERT_NE(*module, nullptr); | ||
|
||
// Print the parsed DFCIR file. | ||
std::string parsedDfcir; | ||
llvm::raw_string_ostream stream(parsedDfcir); | ||
module->print(stream); | ||
|
||
// Compare the initial and parsed representations. | ||
ASSERT_STREQ(parsedDfcir.c_str(), inputDfcir.c_str()); | ||
} |
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,39 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// Part of the Utopia HLS Project, under the Apache License v2.0 | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// Copyright 2024 ISP RAS (http://www.ispras.ru) | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#include "dfcir/DFCIROperations.h" | ||
|
||
#include "gtest/gtest.h" | ||
#include "llvm/Support/raw_ostream.h" | ||
#include "mlir/Parser/Parser.h" | ||
|
||
#include <fstream> | ||
|
||
#define MOVINGSUM_DATA_PATH DATA_PATH "/movingsum.mlir" | ||
|
||
TEST(DFCIRParsePrint, MovingSum) { | ||
std::ifstream fStream(MOVINGSUM_DATA_PATH); | ||
std::stringstream buf; | ||
buf << fStream.rdbuf(); | ||
std::string inputDfcir = buf.str(); | ||
|
||
// Parse the input DFCIR file. | ||
mlir::MLIRContext ctx; | ||
ctx.getOrLoadDialect<mlir::dfcir::DFCIRDialect>(); | ||
mlir::ParserConfig parserCfg(&ctx); | ||
auto module = mlir::parseSourceString(inputDfcir, parserCfg); | ||
ASSERT_NE(*module, nullptr); | ||
|
||
// Print the parsed DFCIR file. | ||
std::string parsedDfcir; | ||
llvm::raw_string_ostream stream(parsedDfcir); | ||
module->print(stream); | ||
|
||
// Compare the initial and parsed representations. | ||
ASSERT_STREQ(parsedDfcir.c_str(), inputDfcir.c_str()); | ||
} |
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,39 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// Part of the Utopia HLS Project, under the Apache License v2.0 | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// Copyright 2024 ISP RAS (http://www.ispras.ru) | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#include "dfcir/DFCIROperations.h" | ||
|
||
#include "gtest/gtest.h" | ||
#include "llvm/Support/raw_ostream.h" | ||
#include "mlir/Parser/Parser.h" | ||
|
||
#include <fstream> | ||
|
||
#define MUXMUL_DATA_PATH DATA_PATH "/muxmul.mlir" | ||
|
||
TEST(DFCIRParsePrint, MuxMul) { | ||
std::ifstream fStream(MUXMUL_DATA_PATH); | ||
std::stringstream buf; | ||
buf << fStream.rdbuf(); | ||
std::string inputDfcir = buf.str(); | ||
|
||
// Parse the input DFCIR file. | ||
mlir::MLIRContext ctx; | ||
ctx.getOrLoadDialect<mlir::dfcir::DFCIRDialect>(); | ||
mlir::ParserConfig parserCfg(&ctx); | ||
auto module = mlir::parseSourceString(inputDfcir, parserCfg); | ||
ASSERT_NE(*module, nullptr); | ||
|
||
// Print the parsed DFCIR file. | ||
std::string parsedDfcir; | ||
llvm::raw_string_ostream stream(parsedDfcir); | ||
module->print(stream); | ||
|
||
// Compare the initial and parsed representations. | ||
ASSERT_STREQ(parsedDfcir.c_str(), inputDfcir.c_str()); | ||
} |
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,39 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// Part of the Utopia HLS Project, under the Apache License v2.0 | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// Copyright 2024 ISP RAS (http://www.ispras.ru) | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#include "dfcir/DFCIROperations.h" | ||
|
||
#include "gtest/gtest.h" | ||
#include "llvm/Support/raw_ostream.h" | ||
#include "mlir/Parser/Parser.h" | ||
|
||
#include <fstream> | ||
|
||
#define POLYNOMIAL2_DATA_PATH DATA_PATH "/polynomial2.mlir" | ||
|
||
TEST(DFCIRParsePrint, Polynomial2) { | ||
std::ifstream fStream(POLYNOMIAL2_DATA_PATH); | ||
std::stringstream buf; | ||
buf << fStream.rdbuf(); | ||
std::string inputDfcir = buf.str(); | ||
|
||
// Parse the input DFCIR file. | ||
mlir::MLIRContext ctx; | ||
ctx.getOrLoadDialect<mlir::dfcir::DFCIRDialect>(); | ||
mlir::ParserConfig parserCfg(&ctx); | ||
auto module = mlir::parseSourceString(inputDfcir, parserCfg); | ||
ASSERT_NE(*module, nullptr); | ||
|
||
// Print the parsed DFCIR file. | ||
std::string parsedDfcir; | ||
llvm::raw_string_ostream stream(parsedDfcir); | ||
module->print(stream); | ||
|
||
// Compare the initial and parsed representations. | ||
ASSERT_STREQ(parsedDfcir.c_str(), inputDfcir.c_str()); | ||
} |
Oops, something went wrong.