Skip to content

Commit 4d0c464

Browse files
committed
Fix: apply clang-format and update tests with %daphne_bin
1 parent e2ce23d commit 4d0c464

File tree

8 files changed

+50
-68
lines changed

8 files changed

+50
-68
lines changed

daphne-opt/daphne-opt.cpp

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,17 +36,14 @@ int main(int argc, char **argv) {
3636
mlir::daphne::registerDaphnePasses();
3737

3838
mlir::DialectRegistry registry;
39-
registry.insert<mlir::daphne::DaphneDialect, mlir::arith::ArithDialect,
40-
mlir::func::FuncDialect, mlir::scf::SCFDialect,
41-
mlir::LLVM::LLVMDialect, mlir::AffineDialect,
42-
mlir::memref::MemRefDialect, mlir::linalg::LinalgDialect,
43-
mlir::math::MathDialect>();
39+
registry.insert<mlir::daphne::DaphneDialect, mlir::arith::ArithDialect, mlir::func::FuncDialect,
40+
mlir::scf::SCFDialect, mlir::LLVM::LLVMDialect, mlir::AffineDialect, mlir::memref::MemRefDialect,
41+
mlir::linalg::LinalgDialect, mlir::math::MathDialect>();
4442
// Add the following to include *all* MLIR Core dialects, or selectively
4543
// include what you need like above. You only need to register dialects that
4644
// will be *parsed* by the tool, not the one generated
4745
// registerAllDialects(registry);
4846

49-
return mlir::asMainReturnCode(mlir::MlirOptMain(
50-
argc, argv, "Standalone DAPHNE optimizing compiler driver\n",
51-
registry));
47+
return mlir::asMainReturnCode(
48+
mlir::MlirOptMain(argc, argv, "Standalone DAPHNE optimizing compiler driver\n", registry));
5249
}

scripts/examples/extensions/myKernels/myKernels.cpp

Lines changed: 36 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -7,60 +7,43 @@
77
class DaphneContext;
88

99
extern "C" {
10-
// Custom sequential sum-kernel.
11-
void mySumSeq(
12-
float * res,
13-
const DenseMatrix<float> * arg,
14-
DaphneContext * ctx
15-
) {
16-
std::cerr << "hello from mySumSeq()" << std::endl;
17-
const float * valuesArg = arg->getValues();
18-
*res = 0;
19-
for(size_t r = 0; r < arg->getNumRows(); r++) {
20-
for(size_t c = 0; c < arg->getNumCols(); c++)
21-
*res += valuesArg[c];
22-
valuesArg += arg->getRowSkip();
23-
}
10+
// Custom sequential sum-kernel.
11+
void mySumSeq(float *res, const DenseMatrix<float> *arg, DaphneContext *ctx) {
12+
std::cerr << "hello from mySumSeq()" << std::endl;
13+
const float *valuesArg = arg->getValues();
14+
*res = 0;
15+
for (size_t r = 0; r < arg->getNumRows(); r++) {
16+
for (size_t c = 0; c < arg->getNumCols(); c++)
17+
*res += valuesArg[c];
18+
valuesArg += arg->getRowSkip();
2419
}
25-
26-
// Custom SIMD-enabled sum-kernel.
27-
void mySumSIMD(
28-
float * res,
29-
const DenseMatrix<float> * arg,
30-
DaphneContext * ctx
31-
) {
32-
std::cerr << "hello from mySumSIMD()" << std::endl;
20+
}
3321

34-
// Validation.
35-
const size_t numCells = arg->getNumRows() * arg->getNumCols();
36-
if(numCells % 8)
37-
throw std::runtime_error(
38-
"for simplicity, the number of cells must be "
39-
"a multiple of 8"
40-
);
41-
if(arg->getNumCols() != arg->getRowSkip())
42-
throw std::runtime_error(
43-
"for simplicity, the argument must not be "
44-
"a column segment of another matrix"
45-
);
46-
47-
// SIMD accumulation (8x f32).
48-
const float * valuesArg = arg->getValues();
49-
__m256 acc = _mm256_setzero_ps();
50-
for(size_t i = 0; i < numCells / 8; i++) {
51-
acc = _mm256_add_ps(acc, _mm256_loadu_ps(valuesArg));
52-
valuesArg += 8;
53-
}
54-
55-
// Summation of accumulator elements.
56-
*res =
57-
(reinterpret_cast<float*>(&acc))[0] +
58-
(reinterpret_cast<float*>(&acc))[1] +
59-
(reinterpret_cast<float*>(&acc))[2] +
60-
(reinterpret_cast<float*>(&acc))[3] +
61-
(reinterpret_cast<float*>(&acc))[4] +
62-
(reinterpret_cast<float*>(&acc))[5] +
63-
(reinterpret_cast<float*>(&acc))[6] +
64-
(reinterpret_cast<float*>(&acc))[7];
22+
// Custom SIMD-enabled sum-kernel.
23+
void mySumSIMD(float *res, const DenseMatrix<float> *arg, DaphneContext *ctx) {
24+
std::cerr << "hello from mySumSIMD()" << std::endl;
25+
26+
// Validation.
27+
const size_t numCells = arg->getNumRows() * arg->getNumCols();
28+
if (numCells % 8)
29+
throw std::runtime_error("for simplicity, the number of cells must be "
30+
"a multiple of 8");
31+
if (arg->getNumCols() != arg->getRowSkip())
32+
throw std::runtime_error("for simplicity, the argument must not be "
33+
"a column segment of another matrix");
34+
35+
// SIMD accumulation (8x f32).
36+
const float *valuesArg = arg->getValues();
37+
__m256 acc = _mm256_setzero_ps();
38+
for (size_t i = 0; i < numCells / 8; i++) {
39+
acc = _mm256_add_ps(acc, _mm256_loadu_ps(valuesArg));
40+
valuesArg += 8;
6541
}
42+
43+
// Summation of accumulator elements.
44+
*res = (reinterpret_cast<float *>(&acc))[0] + (reinterpret_cast<float *>(&acc))[1] +
45+
(reinterpret_cast<float *>(&acc))[2] + (reinterpret_cast<float *>(&acc))[3] +
46+
(reinterpret_cast<float *>(&acc))[4] + (reinterpret_cast<float *>(&acc))[5] +
47+
(reinterpret_cast<float *>(&acc))[6] + (reinterpret_cast<float *>(&acc))[7];
48+
}
6649
}

test/util/lit.cfg

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,9 @@ config.environment["PATH"] = os.path.pathsep.join(
1313
os.path.abspath("bin/"),
1414
os.path.abspath("thirdparty/build/llvm-project/bin/"),
1515
config.environment["PATH"],
16+
1617
)
1718
)
19+
20+
21+
config.substitutions.append(('%daphne_bin', os.path.abspath('bin/daphne')))

test/util/test_mmRowCol.mlir

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
2-
// RUN: /daphne/bin/daphne --explain property_inference /daphne/scripts/examples/mm_RowCol.daph 2>&1 | /usr/lib/llvm-18/bin/FileCheck %s
1+
// RUN: %daphne_bin --explain property_inference /daphne/scripts/examples/mm_RowCol.daph 2>&1 | /usr/lib/llvm-18/bin/FileCheck %s
32

43
// COM: This test verifies the simplification of (X @ Y)[row, col] to X[row,] @ Y[,col]
54

test/util/test_mmRowColTranspose.mlir

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: /daphne/bin/daphne --explain property_inference /daphne/scripts/examples/mm_RowColTranspose.daph 2>&1 | /usr/lib/llvm-18/bin/FileCheck %s
1+
// RUN: %daphne_bin --explain property_inference /daphne/scripts/examples/mm_RowColTranspose.daph 2>&1 | /usr/lib/llvm-18/bin/FileCheck %s
22

33
// COM: This test verifies the simplification of (X @ Y)[row, col] to X[row,] @ Y[,col]
44
// COM: even when X or Y are transposed.

test/util/test_sumEwAdd.mlir

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: /daphne/bin/daphne --explain property_inference /daphne/scripts/examples/sum_ewAdd.daph 2>&1 | /usr/lib/llvm-18/bin/FileCheck %s
1+
// RUN: %daphne_bin--explain property_inference /daphne/scripts/examples/sum_ewAdd.daph 2>&1 | /usr/lib/llvm-18/bin/FileCheck %s
22

33

44
// COM: This test verifies the rewrite for the simplification SUM(X + Y) = SUM(X) + SUM(Y)

test/util/test_sumTranspose.mlir

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: /daphne/bin/daphne --explain property_inference /daphne/scripts/examples/sum_transpose.daph 2>&1 | /usr/lib/llvm-18/bin/FileCheck %s
1+
// RUN: %daphne_bin --explain property_inference /daphne/scripts/examples/sum_transpose.daph 2>&1 | /usr/lib/llvm-18/bin/FileCheck %s
22

33
// COM: This test verifies the simplification of sum(transpose(X)) to sum(X)
44

test/util/test_trace.mlir

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
2-
// RUN: /daphne/bin/daphne --explain property_inference /daphne/scripts/examples/trace.daph 2>&1 | /usr/lib/llvm-18/bin/FileCheck %s
1+
// RUN: %daphne_bin --explain property_inference /daphne/scripts/examples/trace.daph 2>&1 | /usr/lib/llvm-18/bin/FileCheck %s
32

43
// COM: This test verifies the simplification of: trace(X @ Y) = sum(diagVector(X @ Y)) → sum(X @ transpose(Y))
54

0 commit comments

Comments
 (0)