passlab / rexompiler

REX OpenMP Compiler
https://passlab.github.io/rexompiler/
Other
1 stars 1 forks source link

Fix omp lowering and enable basic automated tests #104

Open ouankou opened 3 years ago

ouankou commented 3 years ago

It's been a while since we tested the omp lowering thoroughly last time. Due to unknown reasons, it stops working. For example, given AXPY OpenMP GPU offloading code, it will throw the following errors and no source code is generated. https://github.com/passlab/rexomptest/blob/main/REXCompiler/REXReferenceManual/axpy/axpy.c

Start parsing...
Start parsing...
ompparser directive is ready.
Got expression: x
Got expression: y
Got expression: n
Got expression: a
Shared Clause added!
Got expression: i
Private Clause added!
ompparser directive is ready.
ompparser map clause is ready.
ompparser map clause is added.
ompparser map clause is ready.
ompparser map clause is added.
A default schedule clause is added.
func                            = 0x7feb3865b520 
func->get_definingDeclaration() = 0x7feb3865b520 
func                            = 0x7feb3865b520 
Start parsing...
Start parsing...
ompparser directive is ready.
Got expression: x
Got expression: y
Got expression: n
Got expression: a
Shared Clause added!
Got expression: i
Private Clause added!
ompparser directive is ready.
ompparser map clause is ready.
ompparser map clause is added.
ompparser map clause is ready.
ompparser map clause is added.
ompparser directive is ready.
fatal error: ROSE::getNextStatement(): current statement is not found within its scope's statement list
current statement is SgPragmaDeclaration
Inside of Sg_File_Info::displayString() 
isTransformation    = false  isCompilerGenerated = false  line number = 68 column number = 1 filename = /home/ouankou/Projects/rexomptest/REXCompiler/REXReferenceManual/axpy/axpy.c 
Its scope is SgBasicBlock
Inside of Sg_File_Info::displayString() 
isTransformation    = false  isCompilerGenerated = false  line number = 60 column number = 51 filename = /home/ouankou/Projects/rexomptest/REXCompiler/REXReferenceManual/axpy/axpy.c 
rose-compiler: ../../../rex_src/src/roseSupport/utility_functions.C:1654: SgStatement* Rose::getNextStatement(SgStatement*): Assertion `false' failed.
Aborted (core dumped)

The last version before our recent synchronization with ROSE works (working commit: https://github.com/passlab/rexompiler/commit/61a515798dd87c977e30a79e772b86eb2b3a4ba8). For the same input, the output is:

Start parsing...
Start parsing...
ompparser directive is ready.
ompparser clause is ready.
Got expression: x
Got expression: y
Got expression: n
Got expression: a
Shared Clause added!
ompparser clause is ready.
Got expression: i
Private Clause added!
ompparser directive is ready.
ompparser map clause is ready.
ompparser map clause is added.
ompparser map clause is ready.
ompparser map clause is added.
A default schedule clause is added.

It seems that the current version of REX run the second time and encountered the errors (the lines after "func ..."). We need to check the relevant changes within these three months. To avoid similar issues in the future, even though the omp lowering is still being developed and not stable, we should enable some basic tests at least. For now, we can generate lowered code to make sure something can be produced successfully, regardless of whether it's correct or not. In the GitHub CI system, there is no GPU, so the GPU programs can't be executed.

ouankou commented 3 years ago

Last synchronization with ROSE brought a change in the file src/frontend/SageIII/sageInterface/sageBuilder.C.

When creating a new source file for the outlined function, it was attaching some necessary preprocessing info to the new file. In the latest commits from ROSE, during outlining, it calls a secondary pass to duplicate the original source file, which contains all the OpenMP source code, and then repeats the whole processing from scratch again. This secondary pass will parse the source code, create the AST and lower the AST. The lowering will trigger the secondary pass again. Therefore, it falls to an infinite loop here.

As a temporary fix (commit https://github.com/passlab/rexompiler/commit/f13670d7c703b9d7de5a928ab7b2b7d57936e3e2), we reverted this particular change for now. The change to src/frontend/SageIII/ompAstConstruction.cpp come from the ROSE commit https://github.com/rose-compiler/rose/commit/2ecad6f533ab6ce1a01a32c4b02f94a12f913332. It solved the fatal error listed above that happened in the infinite loop, but not the infinite loop itself.

It could be some compatibility issue of our code or a bug from ROSE's commits. More details should be investigated to find a better solution to follow ROSE's workflow.

To test this fix, please check the sample code: https://github.com/passlab/rexomptest/tree/main/REXCompiler/REXReferenceManual/multi_src Build the latest REX compiler, regenerate the lowered code of target.c and foo.c, and then run make.