Skip to content

Commit

Permalink
CMake updates/fixes + parallel-overhead updates (#16)
Browse files Browse the repository at this point in the history
- OMNITRACE_INSTALL_EXAMPLES option
- Fix lulesh standalone HIP compilation
- Fix transpose standalone HIP compilation
- Tweaks to parallel-overhead
  • Loading branch information
jrmadsen authored May 31, 2022
1 parent 8b97c70 commit a9ff15f
Show file tree
Hide file tree
Showing 12 changed files with 129 additions and 37 deletions.
2 changes: 2 additions & 0 deletions examples/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/build*
/install*
7 changes: 7 additions & 0 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ if(CMAKE_PROJECT_NAME STREQUAL "omnitrace")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
omnitrace_add_option(OMNITRACE_INSTALL_EXAMPLES "Install omnitrace examples" OFF)
else()
option(OMNITRACE_INSTALL_EXAMPLES "Install omnitrace examples" ON)
endif()

if(OMNITRACE_INSTALL_EXAMPLES)
include(GNUInstallDirs)
endif()

add_subdirectory(transpose)
Expand Down
7 changes: 5 additions & 2 deletions examples/code-coverage/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ add_executable(code-coverage code-coverage.cpp)
target_link_libraries(code-coverage PRIVATE Threads::Threads)
target_compile_options(code-coverage PRIVATE ${_FLAGS})

if(NOT CMAKE_PROJECT_NAME STREQUAL "omnitrace")
install(TARGETS code-coverage DESTINATION bin)
if(OMNITRACE_INSTALL_EXAMPLES)
install(
TARGETS code-coverage
DESTINATION bin
COMPONENT omnitrace-examples)
endif()
30 changes: 27 additions & 3 deletions examples/lulesh/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,20 @@ list(INSERT CMAKE_MODULE_PATH 0 ${PROJECT_SOURCE_DIR}/cmake/Modules)
option(LULESH_BUILD_KOKKOS "Build Kokkos from submodule" ON)
if(LULESH_BUILD_KOKKOS)
add_subdirectory(external)
if(LULESH_USE_CUDA OR LULESH_USE_HIP)
if(LULESH_USE_CUDA)
kokkos_compilation(PROJECT)
elseif(LULESH_USE_HIP AND NOT "${CMAKE_CXX_COMPILER}" MATCHES "hipcc")
if(NOT HIPCC_EXECUTABLE)
find_package(hip QUIET)

find_program(
HIPCC_EXECUTABLE
NAMES hipcc
HINTS ${ROCM_PATH} ENV ROCM_PATH /opt/rocm
PATHS ${ROCM_PATH} ENV ROCM_PATH /opt/rocm)
mark_as_advanced(HIPCC_EXECUTABLE)
endif()
kokkos_compilation(PROJECT COMPILER ${HIPCC_EXECUTABLE})
endif()
else()
find_package(Kokkos REQUIRED COMPONENTS separable_compilation)
Expand Down Expand Up @@ -44,6 +56,18 @@ add_executable(${PROJECT_NAME} ${sources} ${headers})
target_include_directories(${PROJECT_NAME} PRIVATE ${PROJECT_SOURCE_DIR}/includes)
target_link_libraries(${PROJECT_NAME} PRIVATE Kokkos::kokkos lulesh-mpi)

if(NOT CMAKE_PROJECT_NAME STREQUAL "omnitrace")
install(TARGETS ${PROJECT_NAME} DESTINATION bin)
if(OMNITRACE_INSTALL_EXAMPLES)
if(LULESH_BUILD_KOKKOS)
install(
TARGETS kokkoscore kokkoscontainers
DESTINATION ${CMAKE_INSTALL_LIBDIR}
COMPONENT omnitrace-examples)
set_target_properties(
${PROJECT_NAME} PROPERTIES INSTALL_RPATH
"\$ORIGIN/../${CMAKE_INSTALL_LIBDIR}")
endif()
install(
TARGETS ${PROJECT_NAME}
DESTINATION bin
COMPONENT omnitrace-examples)
endif()
2 changes: 1 addition & 1 deletion examples/lulesh/external/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ checkout_git_submodule(

set(CMAKE_SKIP_INSTALL_ALL_DEPENDENCY ON)

add_subdirectory(kokkos)
add_subdirectory(kokkos EXCLUDE_FROM_ALL)
7 changes: 5 additions & 2 deletions examples/mpi/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ endif()

target_link_libraries(mpi-example PRIVATE MPI::MPI_CXX)

if(NOT CMAKE_PROJECT_NAME STREQUAL "omnitrace")
install(TARGETS mpi-example DESTINATION bin)
if(OMNITRACE_INSTALL_EXAMPLES)
install(
TARGETS mpi-example
DESTINATION bin
COMPONENT omnitrace-examples)
endif()
7 changes: 5 additions & 2 deletions examples/openmp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ else()
endif()
endif()

if(NOT CMAKE_PROJECT_NAME STREQUAL "omnitrace")
install(TARGETS openmp-cg openmp-lu DESTINATION bin)
if(OMNITRACE_INSTALL_EXAMPLES)
install(
TARGETS openmp-cg openmp-lu
DESTINATION bin
COMPONENT omnitrace-examples)
endif()
7 changes: 5 additions & 2 deletions examples/parallel-overhead/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ add_executable(parallel-overhead-locks parallel-overhead.cpp)
target_link_libraries(parallel-overhead-locks PRIVATE Threads::Threads)
target_compile_definitions(parallel-overhead-locks PRIVATE USE_LOCKS=1)

if(NOT CMAKE_PROJECT_NAME STREQUAL "omnitrace")
install(TARGETS parallel-overhead parallel-overhead-locks DESTINATION bin)
if(OMNITRACE_INSTALL_EXAMPLES)
install(
TARGETS parallel-overhead parallel-overhead-locks
DESTINATION bin
COMPONENT omnitrace-examples)
endif()
44 changes: 31 additions & 13 deletions examples/parallel-overhead/parallel-overhead.cpp
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@

#include <atomic>
#include <cstdio>
#include <cstdlib>
#include <pthread.h>
#include <random>
#include <string>
#include <thread>
#include <vector>

#if defined(USE_LOCKS)
#if !defined(USE_LOCKS)
# define USE_LOCKS 0
#endif

#if USE_LOCKS > 0
# include <mutex>
using auto_lock_t = std::unique_lock<std::mutex>;
long total = 0;
std::mutex mtx{};
#else
# include <atomic>
std::atomic<long> total{ 0 };
#endif

Expand All @@ -31,17 +36,29 @@ fib(long n)
void
run(size_t nitr, long n)
{
#if defined(USE_LOCKS)
static std::atomic<int> _tids{ 0 };
auto _tid = ++_tids;

std::default_random_engine eng(std::random_device{}() * (100 + _tid));
std::uniform_int_distribution<long> distr{ n - 2, n + 2 };

auto _get_n = [&]() { return distr(eng); };

printf("[%i] number of iterations: %zu\n", _tid, nitr);

#if USE_LOCKS > 0
for(size_t i = 0; i < nitr; ++i)
{
auto _v = fib(n);
auto _v = fib(_get_n());
auto_lock_t _lk{ mtx };
total += _v;
}
#else
long local = 0;
for(size_t i = 0; i < nitr; ++i)
local += fib(n);
{
local += fib(_get_n());
}
total += local;
#endif
}
Expand All @@ -64,8 +81,11 @@ main(int argc, char** argv)
printf("\n[%s] Threads: %zu\n[%s] Iterations: %zu\n[%s] fibonacci(%li)...\n",
_name.c_str(), nthread, _name.c_str(), nitr, _name.c_str(), nfib);

bool run_on_main_thread = (USE_LOCKS == 0);
auto nwait = nthread + ((run_on_main_thread) ? 1 : 0);

pthread_barrier_t _barrier;
pthread_barrier_init(&_barrier, nullptr, nthread);
pthread_barrier_init(&_barrier, nullptr, nwait);

auto _run = [&_barrier](size_t nitr, long n) {
pthread_barrier_wait(&_barrier);
Expand All @@ -75,15 +95,13 @@ main(int argc, char** argv)
std::vector<std::thread> threads{};
for(size_t i = 0; i < nthread; ++i)
{
size_t _nitr = ((i % 2) == 1) ? (nitr - (0.1 * nitr)) : (nitr + (0.1 * nitr));
_nitr = std::max<size_t>(_nitr, 1);
threads.emplace_back(_run, _nitr, nfib);
threads.emplace_back(_run, nitr, nfib);
}

#if !defined(USE_LOCKS)
auto _nitr = std::max<size_t>(nitr - 0.25 * nitr, 1);
run(_nitr, nfib - 0.1 * nfib);
#endif
if(run_on_main_thread)
{
_run(nitr, nfib);
}

for(auto& itr : threads)
itr.join();
Expand Down
7 changes: 5 additions & 2 deletions examples/python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,17 @@ project(omnitrace-python)

set(PYTHON_FILES builtin.py external.py source.py)

if(NOT CMAKE_PROJECT_NAME STREQUAL "omnitrace")
if(OMNITRACE_INSTALL_EXAMPLES)
find_package(Python3 COMPONENTS Interpreter)
if(Python3_FOUND)
set(PYTHON_EXECUTABLE "${Python3_EXECUTABLE}")
foreach(_FILE ${PYTHON_FILES})
configure_file(${PROJECT_SOURCE_DIR}/${_FILE} ${PROJECT_BINARY_DIR}/${_FILE}
@ONLY)
install(PROGRAMS ${PROJECT_BINARY_DIR}/${_FILE} DESTINATION bin)
install(
PROGRAMS ${PROJECT_BINARY_DIR}/${_FILE}
DESTINATION bin
COMPONENT omnitrace-examples)
endforeach()
endif()
endif()
39 changes: 31 additions & 8 deletions examples/transpose/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,32 @@ cmake_minimum_required(VERSION 3.16 FATAL_ERROR)

project(omnitrace-transpose LANGUAGES CXX)

find_program(HIPCC_EXECUTABLE NAMES hipcc)
find_package(hip QUIET)

find_program(
HIPCC_EXECUTABLE
NAMES hipcc
HINTS ${ROCM_PATH} ENV ROCM_PATH /opt/rocm
PATHS ${ROCM_PATH} ENV ROCM_PATH /opt/rocm)
mark_as_advanced(HIPCC_EXECUTABLE)

if(NOT HIPCC_EXECUTABLE)
message(AUTHOR_WARNING "hipcc could not be found. Cannot build transpose target")
return()
endif()

if(NOT CMAKE_CXX_COMPILER_IS_HIPCC
AND HIPCC_EXECUTABLE
AND NOT COMMAND omnitrace_custom_compilation)
if(NOT CMAKE_CXX_COMPILER_IS_HIPCC AND HIPCC_EXECUTABLE)
if(CMAKE_CXX_COMPILER STREQUAL HIPCC_EXECUTABLE OR "${CMAKE_CXX_COMPILER}" MATCHES
"hipcc")
set(CMAKE_CXX_COMPILER_IS_HIPCC
1
CACHE BOOL "HIP compiler")
endif()
endif()

if((NOT CMAKE_CXX_COMPILER_IS_HIPCC OR (NOT CMAKE_CXX_COMPILER_ID MATCHES "Clang"
AND NOT hip_FOUND))
AND (NOT COMMAND omnitrace_custom_compilation AND NOT HIPCC_EXECUTABLE))
message(AUTHOR_WARNING "transpose target could not be built")
return()
endif()
Expand All @@ -25,8 +40,13 @@ endif()

add_executable(transpose transpose.cpp)

if(CMAKE_CXX_COMPILER_IS_CLANG AND TARGET omnitrace::omnitrace-compile-options)
target_link_libraries(transpose PRIVATE omnitrace::omnitrace-compile-options)
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
target_link_libraries(
transpose
PRIVATE
$<IF:$<TARGET_EXISTS:omnitrace::omnitrace-compile-options>,omnitrace::omnitrace-compile-options,>
$<IF:$<TARGET_EXISTS:hip::host>,hip::host,>
$<IF:$<TARGET_EXISTS:hip::device>,hip::device,>)
else()
target_compile_options(transpose PRIVATE -W -Wall)
endif()
Expand All @@ -41,6 +61,9 @@ if(NOT CMAKE_CXX_COMPILER_IS_HIPCC AND HIPCC_EXECUTABLE)
omnitrace_custom_compilation(COMPILER ${HIPCC_EXECUTABLE} TARGET transpose)
endif()

if(NOT CMAKE_PROJECT_NAME STREQUAL "omnitrace")
install(TARGETS transpose DESTINATION bin)
if(OMNITRACE_INSTALL_EXAMPLES)
install(
TARGETS transpose
DESTINATION bin
COMPONENT omnitrace-examples)
endif()
7 changes: 5 additions & 2 deletions examples/user-api/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ endif()
add_executable(user-api user-api.cpp)
target_link_libraries(user-api PRIVATE Threads::Threads omnitrace::omnitrace-user-library)

if(NOT CMAKE_PROJECT_NAME STREQUAL "omnitrace")
install(TARGETS user-api DESTINATION bin)
if(OMNITRACE_INSTALL_EXAMPLES)
install(
TARGETS user-api
DESTINATION bin
COMPONENT omnitrace-examples)
endif()

0 comments on commit a9ff15f

Please sign in to comment.