Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adiak related testing and updates #172

Closed
wants to merge 28 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
419dd69
Initial Structure for updating to the NewPassManager
tpatki Sep 19, 2024
83f20f6
Add a basic module pass structure for perfflow_weave_new_pass. Untested.
tpatki Sep 19, 2024
fd0ed97
Formatted.
tpatki Sep 19, 2024
9d1b1d8
Add headers, comment one registration technique
tpatki Sep 20, 2024
d96754e
Formatted.
tpatki Sep 20, 2024
2f8cd8f
Add missing brace
tpatki Sep 20, 2024
6b09d5a
Builds, but pass is not picked up with -XClang -load
tpatki Sep 20, 2024
5b3e7a0
Try the EP Early Simplification Callback, similar to our legacy pass
tpatki Sep 20, 2024
ea779be
Comment out the example code
tpatki Sep 20, 2024
430654b
Add missing ;
tpatki Sep 20, 2024
51d4b59
Try adding the -fpass-plugin for clang 14+
tpatki Sep 20, 2024
3d7a622
Clean up, edit CMake to add -fpass-plugin for Clang14+, edit host-config
tpatki Sep 20, 2024
e53ee4a
Update the CUDA compiler -Xcompiler flag.
tpatki Sep 20, 2024
ec2688a
Formatted
tpatki Sep 20, 2024
3719b52
Check if we can intercept main, so we know where to insert the Adiak …
tpatki Sep 24, 2024
fc94860
Builds correctly, can intercept main.
tpatki Sep 24, 2024
6dfa001
First attempt at restructuring. Will probably not build. May split in…
tpatki Sep 24, 2024
16c773c
Add relevant headers, only testing New pass
tpatki Sep 24, 2024
cd038cb
Pick the right flag
tpatki Sep 24, 2024
9103cc1
NewPassMgr builds correctly. Buildlegacy pass now
tpatki Sep 24, 2024
b9d1031
Woohoo! We have a working NewPassManager that generates PFW files. Fo…
tpatki Sep 24, 2024
77b8033
Comment out some parts of legacy code
tpatki Sep 24, 2024
f426ddb
Code Cleanup Pass 1. Rename some classes, variables, remove commented…
tpatki Sep 24, 2024
5c583a0
Split perfflow_weave_common into hpp and cpp
tpatki Sep 24, 2024
18a80b5
Formatting pass
tpatki Sep 24, 2024
7e8154d
Remove Adiak testing and main function hooks from this PR
tpatki Sep 24, 2024
ec15008
Formatting pass
tpatki Sep 24, 2024
89fcfca
Create a new branch based on the NewPassManager to test Adiak related…
tpatki Sep 25, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/c/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,15 @@ if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
# require at least Clang 9.0
if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 9.0)
message(FATAL_ERROR "Clang++ version must be at least 9.0!")
elseif (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 11)
elseif (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 14)
set(PERFFLOWASPECT_CLANG_14_NEWER TRUE CACHE BOOL "using >=clang14")
add_definitions(-DPERFFLOWASPECT_CLANG_14_NEWER)
elseif ((CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 11) AND (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 14))
set(PERFFLOWASPECT_CLANG_11_NEWER TRUE CACHE BOOL "using >=clang11")
set(PERFFLOWASPECT_CLANG_14_NEWER FALSE CACHE BOOL "using < clang14")
add_definitions(-DPERFFLOWASPECT_CLANG_11_NEWER)
elseif (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 11)
set(PERFFLOWASPECT_CLANG_11_NEWER FALSE CACHE BOOL "using >=clang11")
set(PERFFLOWASPECT_CLANG_11_NEWER FALSE CACHE BOOL "using < clang11")
endif()
else()
message(WARNING "Unsupported CXX compiler: please use Clang >= 9.0")
Expand Down
8 changes: 6 additions & 2 deletions src/c/host-configs/[email protected]@8.3.1.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
set(CMAKE_C_COMPILER "/usr/tce/packages/clang/clang-14.0.5-gcc-8.3.1/bin/clang" CACHE PATH "")
set(CMAKE_CXX_COMPILER "/usr/tce/packages/clang/clang-14.0.5-gcc-8.3.1/bin/clang++" CACHE PATH "")
set(LLVM_DIR "/usr/tce/packages/clang/clang-ibm-14.0.5-gcc-8.3.1/lib/cmake/llvm" CACHE PATH "")

# Clang 14 supports both legacy and new pass manager.
# Use the -flegacy-pass-manager if you want to use the legacy pass.
# Use -fpass-plugin=<weavePass.so> to use the new pass
# Use both C and CXX flags to support both targets.
set(CMAKE_C_FLAGS "-flegacy-pass-manager" CACHE STRING "")
set(CMAKE_CXX_FLAGS "-flegacy-pass-manager" CACHE STRING "")
# set(CMAKE_C_FLAGS "-flegacy-pass-manager" CACHE STRING "")
# set(CMAKE_CXX_FLAGS "-flegacy-pass-manager" CACHE STRING "")
24 changes: 20 additions & 4 deletions src/c/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,29 +11,45 @@ message(STATUS "Adding CXX unit tests")
foreach(TEST ${SMOKETESTS})
message(STATUS " [*] Adding test: ${TEST}")
add_executable(${TEST} ${TEST}.cpp)
set_source_files_properties(${TEST}.cpp COMPILE_FLAGS "-Xclang -load -Xclang ../weaver/weave/libWeavePass.so -fPIC")
if (PERFFLOWASPECT_CLANG_14_NEWER)
set_source_files_properties(${TEST}.cpp COMPILE_FLAGS "-Xclang -load -Xclang ../weaver/weave/libWeavePass.so -fpass-plugin=../weaver/weave/libWeavePass.so -fPIC")
else()
set_source_files_properties(${TEST}.cpp COMPILE_FLAGS "-Xclang -load -Xclang ../weaver/weave/libWeavePass.so -fPIC")
endif()
target_link_libraries(${TEST} ${perfflow_deps})
endforeach()

if(PERFFLOWASPECT_WITH_MULTITHREADS)
message(STATUS " [*] Adding test: smoketest_MT")
add_executable(smoketest_MT smoketest_MT.cpp)
set_source_files_properties(smoketest_MT.cpp COMPILE_FLAGS "-Xclang -load -Xclang ../weaver/weave/libWeavePass.so -fPIC")
if (PERFFLOWASPECT_CLANG_14_NEWER)
set_source_files_properties(smoketest_MT.cpp COMPILE_FLAGS "-Xclang -load -Xclang ../weaver/weave/libWeavePass.so -fpass-plugin=../weaver/weave/libWeavePass.so -fPIC")
else()
set_source_files_properties(smoketest_MT.cpp COMPILE_FLAGS "-Xclang -load -Xclang ../weaver/weave/libWeavePass.so -fPIC")
endif()
set(THREADS_PREFER_PTHREAD_FLAG ON)
target_link_libraries(smoketest_MT ${perfflow_deps} pthread)
endif()

if(PERFFLOWASPECT_WITH_MPI)
message(STATUS " [*] Adding test: smoketest_MPI")
add_executable(smoketest_MPI smoketest_MPI.cpp)
set_source_files_properties(smoketest_MPI.cpp COMPILE_FLAGS "-Xclang -load -Xclang ../weaver/weave/libWeavePass.so -fPIC")
if (PERFFLOWASPECT_CLANG_14_NEWER)
set_source_files_properties(smoketest_MPI.cpp COMPILE_FLAGS "-Xclang -load -Xclang ../weaver/weave/libWeavePass.so -fpass-plugin=../weaver/weave/libWeavePass.so -fPIC")
else()
set_source_files_properties(smoketest_MPI.cpp COMPILE_FLAGS "-Xclang -load -Xclang ../weaver/weave/libWeavePass.so -fPIC")
endif()
include_directories(${MPI_INCLUDE_PATH})
target_link_libraries(smoketest_MPI ${perfflow_deps} ${MPI_LIBRARIES})
endif()

if(PERFFLOWASPECT_WITH_CUDA)
message(STATUS " [*] Adding test: smoketest_cuda")
set(CUDA_NVCC_FLAGS "-ccbin ${CMAKE_CXX_COMPILER} -Xcompiler=-Xclang -Xcompiler=-load -Xcompiler=-Xclang -Xcompiler=../../../weaver/weave/libWeavePass.so")
if (PERFFLOWASPECT_CLANG_14_NEWER)
set(CUDA_NVCC_FLAGS "-ccbin ${CMAKE_CXX_COMPILER} -Xcompiler=-Xclang -Xcompiler=-load -Xcompiler=-Xclang -Xcompiler=../../../weaver/weave/libWeavePass.so -Xcompiler=-fpass-plugin=../../../weaver/weave/libWeavePass.so")
else()
set(CUDA_NVCC_FLAGS "-ccbin ${CMAKE_CXX_COMPILER} -Xcompiler=-Xclang -Xcompiler=-load -Xcompiler=-Xclang -Xcompiler=../../../weaver/weave/libWeavePass.so")
endif()
cuda_add_executable(smoketest_cuda smoketest_cuda_wrapper.cpp smoketest_cuda_kernel.cu)
target_link_libraries(smoketest_cuda ${perfflow_deps} ${CUDA_LIBRARIES})
endif()
Expand Down
17 changes: 13 additions & 4 deletions src/c/weaver/weave/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
add_library(WeavePass MODULE
# List your source files here.
perfflow_weave.cpp
)
if (PERFFLOWASPECT_CLANG_14_NEWER)
# Add the new pass
add_library(WeavePass MODULE
# List your source files here.
perfflow_weave_new_pass.cpp
)
else()
# Add the legacy pass if we have Clang < 14.
add_library(WeavePass MODULE
# List your source files here.
perfflow_weave_legacy_pass.cpp
)
endif()

# Use C++11 to compile our pass (i.e., supply -std=c++11).
target_compile_features(WeavePass PRIVATE cxx_range_for cxx_auto_type)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,34 +8,87 @@
* SPDX-License-Identifier: LGPL-3.0
\************************************************************/

#include "llvm/IR/Value.h"
#include "llvm/IR/Attributes.h"
#include "llvm/IR/Constants.h"
#include "llvm/IR/LegacyPassManager.h"
#ifdef PERFFLOWASPECT_CLANG_11_NEWER
#include "llvm/IR/AbstractCallSite.h"
#else
#include "llvm/IR/CallSite.h"
#endif
#include "llvm/IR/Module.h"
#include "llvm/IR/Argument.h"
#include "llvm/IR/IRBuilder.h"
#include "llvm/Transforms/IPO/PassManagerBuilder.h"
#include "llvm/Support/raw_ostream.h"

#include "../../parser/perfflow_parser.hpp"
#include "perfflow_weave.hpp"

using namespace llvm;
#include "perfflow_weave_common.hpp"

/******************************************************************************
* *
* Public Method of WeaveCommon Class *
* *
******************************************************************************/

bool WeaveCommon::modifyAnnotatedFunctions(Module &m)
{
auto annotations = m.getNamedGlobal("llvm.global.annotations");
if (!annotations)
{
return false;
}

bool changed = false;
auto a = cast<ConstantArray> (annotations->getOperand(0));
for (unsigned int i = 0; i < a->getNumOperands(); i++)
{
auto e = cast<ConstantStruct> (a->getOperand(i));
if (auto *fn = dyn_cast<Function> (e->getOperand(0)->getOperand(0)))
{
auto anno = cast<ConstantDataArray>(
cast<GlobalVariable>(e->getOperand(1)->getOperand(0))
->getOperand(0))
->getAsCString();
std::string pcut, scope, flow;
if (perfflow_parser_parse(anno.data(), pcut, scope, flow) == 0)
{
if (pcut == "around" || pcut == "before")
changed = insertBefore(m, *fn,
anno, 0, scope, flow, pcut) || changed;
else if (pcut == "around_async" || pcut == "before_async")
{
changed = insertBefore(m, *fn,
anno, 1, scope, flow, pcut) || changed;
}
if (pcut == "around" || pcut == "after")
{
if (pcut == "around")
{
if (flow == "in" || flow == "out")
{
flow = "NA";
}
}
changed = insertAfter(m, *fn,
anno, 0, scope, flow, pcut) || changed;
}
else if (pcut == "around_async" || pcut == "after_async")
{
if (pcut == "around")
{
if (flow == "in" || flow == "out")
{
flow = "NA";
}
}
changed = insertAfter(m, *fn,
anno, 1, scope, flow, pcut) || changed;
}
}
else
{
errs() << "WeavePass[WARN]: Ignoring " << anno << "\n";
}
}
}
return changed;

}


/******************************************************************************
* *
* Private Methods of WeavingPass Class *
* Private Methods of WeaveCommon Class *
* *
******************************************************************************/

bool WeavingPass::insertAfter(Module &m, Function &f, StringRef &a,
bool WeaveCommon::insertAfter(Module &m, Function &f, StringRef &a,
int async, std::string &scope, std::string &flow, std::string pcut)
{
if (m.empty() || f.empty())
Expand Down Expand Up @@ -88,7 +141,7 @@ bool WeavingPass::insertAfter(Module &m, Function &f, StringRef &a,
return true;
}

bool WeavingPass::insertBefore(Module &m, Function &f, StringRef &a,
bool WeaveCommon::insertBefore(Module &m, Function &f, StringRef &a,
int async, std::string &scope, std::string &flow, std::string pcut)
{
if (m.empty() || f.empty())
Expand Down Expand Up @@ -135,98 +188,6 @@ bool WeavingPass::insertBefore(Module &m, Function &f, StringRef &a,
return true;
}


/******************************************************************************
* *
* Public Methods of WeavingPass Class *
* *
******************************************************************************/

bool WeavingPass::doInitialization(Module &m)
{
outs() << "WeavePass loaded successfully. \n";

auto annotations = m.getNamedGlobal("llvm.global.annotations");
if (!annotations)
{
return false;
}

bool changed = false;
auto a = cast<ConstantArray> (annotations->getOperand(0));
for (unsigned int i = 0; i < a->getNumOperands(); i++)
{
auto e = cast<ConstantStruct> (a->getOperand(i));
if (auto *fn = dyn_cast<Function> (e->getOperand(0)->getOperand(0)))
{
auto anno = cast<ConstantDataArray>(
cast<GlobalVariable>(e->getOperand(1)->getOperand(0))
->getOperand(0))
->getAsCString();
std::string pcut, scope, flow;
if (perfflow_parser_parse(anno.data(), pcut, scope, flow) == 0)
{
if (pcut == "around" || pcut == "before")
changed = insertBefore(m, *fn,
anno, 0, scope, flow, pcut) || changed;
else if (pcut == "around_async" || pcut == "before_async")
{
changed = insertBefore(m, *fn,
anno, 1, scope, flow, pcut) || changed;
}
if (pcut == "around" || pcut == "after")
{
if (pcut == "around")
{
if (flow == "in" || flow == "out")
{
flow = "NA";
}
}
changed = insertAfter(m, *fn,
anno, 0, scope, flow, pcut) || changed;
}
else if (pcut == "around_async" || pcut == "after_async")
{
if (pcut == "around")
{
if (flow == "in" || flow == "out")
{
flow = "NA";
}
}
changed = insertAfter(m, *fn,
anno, 1, scope, flow, pcut) || changed;
}
}
else
{
errs() << "WeavePass[WARN]: Ignoring " << anno << "\n";
}
}
}
return changed;
}

bool WeavingPass::runOnFunction(Function &F)
{
return false;
}

char WeavingPass::ID = 0;

// Automatically enable the pass.
// http://adriansampson.net/blog/clangpass.html
static void registerWeavingPass(const PassManagerBuilder &,
legacy::PassManagerBase &PM)
{
PM.add(new WeavingPass());
}

static RegisterStandardPasses
RegisterMyPass(PassManagerBuilder::EP_EarlyAsPossible,
registerWeavingPass);

/*
* vi:tabstop=4 shiftwidth=4 expandtab
*/
Loading
Loading