/// Creates a pass to check memref access dependences in an ML Function.
FunctionPassBase *createMemRefDependenceCheckPass();
-/// Creates a pass to test parallelism detection; marks parallel loops.
-FunctionPassBase *createLoopParallelismDetectionPass();
+/// Creates a pass to test parallelism detection; emits note for parallel loops.
+FunctionPassBase *createParallelismDetectionTestPass();
} // end namespace mlir
namespace {
-struct LoopParallelismDetection
- : public FunctionPass<LoopParallelismDetection> {
+struct TestParallelismDetection
+ : public FunctionPass<TestParallelismDetection> {
void runOnFunction() override;
};
} // end anonymous namespace
-FunctionPassBase *mlir::createLoopParallelismDetectionPass() {
- return new LoopParallelismDetection();
+FunctionPassBase *mlir::createParallelismDetectionTestPass() {
+ return new TestParallelismDetection();
}
-// Walks the function and marks all parallel 'for' ops with an attribute.
-void LoopParallelismDetection::runOnFunction() {
+// Walks the function and emits a note for all 'for' ops detected as parallel.
+void TestParallelismDetection::runOnFunction() {
Function *f = getFunction();
FuncBuilder b(f);
f->walk<AffineForOp>([&](OpPointer<AffineForOp> forOp) {
- forOp->getInstruction()->setAttr("parallel",
- b.getBoolAttr(isLoopParallel(forOp)));
+ if (isLoopParallel(forOp))
+ forOp->emitNote("parallel loop");
});
}
-static PassRegistration<LoopParallelismDetection> pass("detect-parallel",
- "Detect parallel loops");
+static PassRegistration<TestParallelismDetection>
+ pass("test-detect-parallel", "Test parallelism detection ");
-// RUN: mlir-opt %s -detect-parallel | mlir-opt | FileCheck %s
+// RUN: mlir-opt %s -test-detect-parallel -split-input-file -verify | FileCheck %s
+// CHECK-LABEL: func @loop_nest_3d_outer_two_parallel
func @loop_nest_3d_outer_two_parallel(%N : index) {
%0 = alloc() : memref<1024 x 1024 x vector<64xf32>>
%1 = alloc() : memref<1024 x 1024 x vector<64xf32>>
%2 = alloc() : memref<1024 x 1024 x vector<64xf32>>
for %i = 0 to %N {
+ // expected-note@-1 {{parallel loop}}
for %j = 0 to %N {
+ // expected-note@-1 {{parallel loop}}
for %k = 0 to %N {
%5 = load %0[%i, %k] : memref<1024x1024xvector<64xf32>>
%6 = load %1[%k, %j] : memref<1024x1024xvector<64xf32>>
%8 = mulf %5, %6 : vector<64xf32>
%9 = addf %7, %8 : vector<64xf32>
store %9, %2[%i, %j] : memref<1024x1024xvector<64xf32>>
- } // CHECK: } {parallel: false}
- } // CHECK: } {parallel: true}
- } // CHECK: } {parallel: true}
+ }
+ }
+ }
return
}