Skip to content

Commit

Permalink
Merge pull request #50 from ispras/dfcir_unit_tests
Browse files Browse the repository at this point in the history
DFCIR unit tests
  • Loading branch information
ssmolov authored Aug 19, 2024
2 parents 1d10adc + fddcb66 commit b43494f
Show file tree
Hide file tree
Showing 17 changed files with 1,633 additions and 0 deletions.
1 change: 1 addition & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ endif()
target_compile_definitions(utest
PUBLIC
NULLDEVICE="${NULLDEVICE}"
DATA_PATH="${CMAKE_CURRENT_SOURCE_DIR}/data"
)

target_include_directories(utest
Expand Down
10 changes: 10 additions & 0 deletions test/data/addconst.mlir
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>>)
}
}
1,254 changes: 1,254 additions & 0 deletions test/data/idct.mlir

Large diffs are not rendered by default.

32 changes: 32 additions & 0 deletions test/data/matrixmul2.mlir
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>>)
}
}
11 changes: 11 additions & 0 deletions test/data/movingsum.mlir
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>>)
}
}
13 changes: 13 additions & 0 deletions test/data/muxmul.mlir
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>>)
}
}
10 changes: 10 additions & 0 deletions test/data/polynomial2.mlir
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>>)
}
}
17 changes: 17 additions & 0 deletions test/data/scalar3.mlir
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>>)
}
}
2 changes: 2 additions & 0 deletions test/model/CMakeLists.txt
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
)
10 changes: 10 additions & 0 deletions test/model/dfcir/CMakeLists.txt
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
)
39 changes: 39 additions & 0 deletions test/model/dfcir/addconst.cpp
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());
}
39 changes: 39 additions & 0 deletions test/model/dfcir/idct.cpp
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());
}
39 changes: 39 additions & 0 deletions test/model/dfcir/matrixmul2.cpp
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());
}
39 changes: 39 additions & 0 deletions test/model/dfcir/movingsum.cpp
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());
}
39 changes: 39 additions & 0 deletions test/model/dfcir/muxmul.cpp
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());
}
39 changes: 39 additions & 0 deletions test/model/dfcir/polynomial2.cpp
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());
}
Loading

0 comments on commit b43494f

Please sign in to comment.