Skip to content

Commit

Permalink
initial port of hpxMP to riscv64
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris Taylor committed Aug 3, 2022
1 parent d55f686 commit 4fb1791
Show file tree
Hide file tree
Showing 11 changed files with 325 additions and 48 deletions.
48 changes: 34 additions & 14 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,40 @@ PROJECT(HPXMP CXX ASM)

cmake_minimum_required(VERSION 2.8)

set(hpxmp_sources
src/asm_functions.s
src/intel_hpxMP.cpp
src/hpx_runtime.cpp
src/kmp_atomic.cpp
src/loop_schedule.cpp
src/gcc_hpxMP.cpp)

set(hpxmp_headers
src/intel_hpxMP.h
src/hpx_runtime.h
src/kmp_atomic.h
src/loop_schedule.h
src/gcc_hpxMP.h)
execute_process(COMMAND gcc -dumpmachine OUTPUT_STRIP_TRAILING_WHITESPACE OUTPUT_VARIABLE ARCH)

if(ARCH STREQUAL "riscv64-linux-gnu")
set(hpxmp_sources
src/riscv64_asm_functions.s
src/intel_hpxMP.cpp
src/hpx_runtime.cpp
src/kmp_atomic.cpp
src/loop_schedule.cpp
src/gcc_hpxMP.cpp)

set(hpxmp_headers
src/intel_hpxMP.h
src/hpx_runtime.h
src/kmp_atomic.h
src/loop_schedule.h
src/gcc_hpxMP.h)

else()
set(hpxmp_sources
src/asm_functions.s
src/intel_hpxMP.cpp
src/hpx_runtime.cpp
src/kmp_atomic.cpp
src/loop_schedule.cpp
src/gcc_hpxMP.cpp)

set(hpxmp_headers
src/intel_hpxMP.h
src/hpx_runtime.h
src/kmp_atomic.h
src/loop_schedule.h
src/gcc_hpxMP.h)
endif()

set(HPXMP_WITH_TRACE OFF CACHE BOOL "display traces in debug mode")
if(HPXMP_WITH_TRACE)
Expand Down
14 changes: 12 additions & 2 deletions examples/omp/tests/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
# file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fopenmp")
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fopenmp")

set(examples
omp-barrier
omp-for
Expand All @@ -30,7 +32,15 @@ set(examples
#task_spawn_time
)


foreach(example ${examples})
set(sources ${example}.c)
add_executable(${example} ${sources})
project(${example})
set(SOURCE_FILES ./${example}.c)
add_executable(${example} ${SOURCE_FILES})
set_target_properties(${example} PROPERTIES LINKER_LANGUAGE CXX)
endforeach()

#project(omp-for)
#set(SOURCE_FILES ./omp-for.c)
#add_executable(omp-for ${SOURCE_FILES})
#set_target_properties(omp-for PROPERTIES LINKER_LANGUAGE CXX)
16 changes: 13 additions & 3 deletions src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,19 @@ CFLAGS=
#LIBS=/usr/common/software/boost/1.62/gnu/haswell/lib/libboost_fiber.so
#ATOMIC_FLAGS=-Qoption,cpp,--extended_float_type

ARCH_SCRIPT=$(shell gcc -dumpmachine)
GET_ARCH=$(eval ARCH=$(ARCH_SCRIPT))

ifeq($(GET_ARCH),riscv64-linux-gnu)
asm_file=riscv_asm_functions.s
else
asm_file=asm_functions.s
endif


all: libiomp5.so libomp.so
echo "HERE"


libomp.so: intel_rt.o hpx_runtime.o loop_schedule.o kmp_atomic.o asm_functions.o
$(CC) $(FLAGS) -shared -Wl,-x -Wl,-soname=libomp.so,--version-script=exports_so.txt -o libomp.so intel_rt.o loop_schedule.o kmp_atomic.o hpx_runtime.o asm_functions.o -L. `pkg-config --cflags --libs $(HPX_BUILD_TYPE)` $(LIBS)

Expand All @@ -23,8 +33,8 @@ intel_rt.o: intel_hpxMP.cpp intel_hpxMP.h
kmp_atomic.o: kmp_atomic.cpp kmp_atomic.h
$(CC) $(FLAGS) -I ./ -D USE_ITT_BUILD -D NDEBUG -D KMP_ARCH_STR="\"Intel(R) 64\"" -D _GNU_SOURCE -D _REENTRANT -D KMP_USE_ASSERT -D BUILD_I8 -D BUILD_TV -D KMP_LIBRARY_FILE=\"libiomp5.so\" -D KMP_VERSION_MAJOR=5 -D CACHE_LINE=64 -D KMP_ADJUST_BLOCKTIME=1 -D BUILD_PARALLEL_ORDERED -D KMP_ASM_INTRINS -D KMP_USE_INTERNODE_ALIGNMENT=0 -D KMP_USE_VERSION_SYMBOLS -D USE_LOAD_BALANCE -D USE_CBLKDATA -D GUIDEDLL_EXPORTS -D KMP_GOMP_COMPAT -D KMP_NESTED_HOT_TEAMS -D KMP_USE_ADAPTIVE_LOCKS=1 -D KMP_DEBUG_ADAPTIVE_LOCKS=0 -D KMP_STATS_ENABLED=0 -D OMP_50_ENABLED=0 -D OMP_41_ENABLED=0 -D OMP_40_ENABLED=1 -D USE_ITT_NOTIFY=1 -D INTEL_ITTNOTIFY_PREFIX=__kmp_itt_ -D KMP_TDATA_GTID -c -fPIC -Wsign-compare -o kmp_atomic.o kmp_atomic.cpp `pkg-config --cflags --libs $(HPX_BUILD_TYPE)` $(LIBS) $(ATOMIC_FLAGS)

asm_functions.o: asm_functions.s
$(cc) $(FLAGS) -c -x assembler-with-cpp -o asm_functions.o asm_functions.s
asm_functions.o: $(asm_file)
$(cc) $(FLAGS) -c -x assembler-with-cpp -o asm_functions.o $(asm_file)

hpx_runtime.o: hpx_runtime.cpp hpx_runtime.h
$(CC) $(FLAGS) -fPIC -c hpx_runtime.cpp -o hpx_runtime.o `pkg-config --cflags --libs $(HPX_BUILD_TYPE)` $(LIBS)
Expand Down
2 changes: 1 addition & 1 deletion src/gcc_hpxMP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include <boost/shared_ptr.hpp>
#include <iostream>
#include <assert.h>
#include <hpx/assertion.hpp>
#include <hpx/assert.hpp>

extern boost::shared_ptr<hpx_runtime> hpx_backend;

Expand Down
49 changes: 31 additions & 18 deletions src/hpx_runtime.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2013 Jeremy Kemp
// Copyright hpx/threading_base(c) 2013 Jeremy Kemp
// Copyright (c) 2013 Bryce Adelstein-Lelbach
// Copyright (c) 2018 Tianyi Zhang
//
Expand All @@ -12,7 +12,9 @@
// We need to explicitly include the implementations for hpx::start if hpxMP is
// being compiled as part of HPX itself
#include <hpx/hpx_start_impl.hpp>
#include <hpx/runtime/threads/run_as_hpx_thread.hpp>
//#include <hpx/runtime/threads/run_as_hpx_thread.hpp>
#include <hpx/include/run_as.hpp>
#include <hpx/threading_base/register_thread.hpp>
#include <hpx/program_options/options_description.hpp>

using std::cout;
Expand Down Expand Up @@ -98,14 +100,19 @@ void start_hpx(size_t initial_num_threads)
#ifdef OMP_COMPLIANT
argv[1] = const_cast<char*>("--hpx:queuing=static");
#endif
hpx::util::function_nonser<int(boost::program_options::variables_map& vm)> f;
hpx::function<int(hpx::program_options::variables_map& vm)> f;
hpx::program_options::options_description desc_cmdline;

std::mutex startup_mtx;
std::condition_variable cond;//TODO: replace this with something that can be checked later, once hpx is needed.
bool running = false;
hpx::start(f, desc_cmdline, argc, argv, cfg,
std::bind(&wait_for_startup, boost::ref(startup_mtx), boost::ref(cond), boost::ref(running)));
//hpx::start(f, desc_cmdline, argc, argv, cfg,
// std::bind(&wait_for_startup, boost::ref(startup_mtx), boost::ref(cond), boost::ref(running)));

hpx::init_params init_args;
init_args.desc_cmdline = desc_cmdline;
hpx::start(f, argc, argv, init_args); //,
// std::bind(&wait_for_startup, boost::ref(startup_mtx), boost::ref(cond), boost::ref(running)));

{
//std::scoped_lock lk(startup_mtx);
Expand Down Expand Up @@ -356,10 +363,13 @@ void hpx_runtime::create_task( kmp_routine_entry_t task_func, int gtid, intrusiv
current_task_ptr->taskgroupLatch->count_up(1);
//this fixes hpx::apply changes in hpx backend
//TPool.enqueue(&task_setup, gtid, kmp_task_ptr, current_task_ptr);
hpx::applier::register_thread_nullary(
std::bind(&task_setup, gtid, kmp_task_ptr, current_task_ptr),
"omp_explicit_task", hpx::threads::pending, true,
hpx::threads::thread_priority_normal);
//hpx::applier::register_thread_nullary(
hpx::threads::thread_init_data tdata ( hpx::threads::make_thread_function_nullary(
std::bind(&task_setup, gtid, kmp_task_ptr, current_task_ptr) ), "omp_explicit_task" );
hpx::threads::register_thread(tdata);
// ; //,
//"omp_explicit_task", hpx::threads::thread_schedule_state::pending, true,
//hpx::threads::thread_priority::normal);
#endif
}
// else {
Expand Down Expand Up @@ -439,17 +449,17 @@ void hpx_runtime::create_df_task( int gtid, kmp_task_t *thunk,

if(task->in_taskgroup) {
new_task = dataflow( *(task->tg_exec),
unwrapping(df_tg_task_wrapper), gtid, thunk, task->icv,
hpx::unwrapping(df_tg_task_wrapper), gtid, thunk, task->icv,
task->tg_exec,
team, hpx::when_all(dep_futures) );
} else {
new_task = dataflow( *(team->exec),
unwrapping(df_task_wrapper), gtid, thunk, task->icv,
hpx::unwrapping(df_task_wrapper), gtid, thunk, task->icv,
task->num_child_tasks,
team, hpx::when_all(dep_futures) );
}
#else
new_task = dataflow( unwrapping(df_task_wrapper), gtid, thunk, current_task_ptr, hpx::when_all(dep_futures));
new_task = dataflow( hpx::unwrapping(df_task_wrapper), gtid, thunk, current_task_ptr, hpx::when_all(dep_futures));
#endif
}
for(int i = 0 ; i < ndeps; i++) {
Expand Down Expand Up @@ -622,12 +632,15 @@ void fork_worker( invoke_func kmp_invoke, microtask_t thread_func,
}
#else
for( int i = 0; i < parent->threads_requested; i++ ) {
hpx::applier::register_thread_nullary(
std::bind( &thread_setup, kmp_invoke, thread_func, argc, argv, i, &team, parent,
boost::ref(threadLatch)),
"omp_implicit_task", hpx::threads::pending,
true, hpx::threads::thread_priority_low, i );
//true, hpx::threads::thread_priority_normal, i );

hpx::threads::thread_init_data tdata ( hpx::threads::make_thread_function_nullary(
std::bind( &thread_setup, kmp_invoke, thread_func, argc, argv, i, &team, parent,
boost::ref(threadLatch)) ), "omp_implicit_task" ); //,
hpx::threads::register_thread(tdata);

//"omp_implicit_task", hpx::threads::thread_schedule_state::pending,
//true, hpx::threads::thread_priority::low, i );
//true, hpx::threads::thread_priority::normal, i );
}
#endif
threadLatch.count_down_and_wait();
Expand Down
25 changes: 16 additions & 9 deletions src/hpx_runtime.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,21 @@
#include <hpx/hpx.hpp>
#include <hpx/hpx_start.hpp>
#include <hpx/topology/topology.hpp>
#include <hpx/lcos/local/barrier.hpp>
#include <hpx/condition_variable.hpp>
//#include <hpx/lcos/local/barrier.hpp>
#include <hpx/type_support/static.hpp>
#include <hpx/include/lcos.hpp>
#include <hpx/lcos/local/condition_variable.hpp>
#include <hpx/condition_variable.hpp>
//#include <hpx/lcos/local/condition_variable.hpp>

#include <hpx/parallel/executors/thread_pool_executors.hpp>
#include <hpx/executors/thread_pool_executor.hpp>

#include <boost/algorithm/string/split.hpp>
#include <boost/algorithm/string/classification.hpp>
#include <boost/lexical_cast.hpp>
#include <boost/assign/std/vector.hpp>
#include <boost/cstdint.hpp>
#include <boost/shared_ptr.hpp>
#include <boost/intrusive_ptr.hpp>
//#include <boost/thread/mutex.hpp>
//#include <boost/thread/condition.hpp>
Expand All @@ -42,13 +45,14 @@

using std::atomic;
using boost::shared_ptr;
using hpx::threads::executors::local_priority_queue_executor;
//using hpx::threads::executors::local_priority_queue_executor;
using hpx::execution::parallel_executor;
using hpx::lcos::local::barrier;
using hpx::lcos::local::latch;
using hpx::lcos::shared_future;
using hpx::shared_future;
using hpx::lcos::future;
using std::vector;
using hpx::util::high_resolution_timer;
using hpx::chrono::high_resolution_timer;
using boost::intrusive_ptr;


Expand All @@ -61,7 +65,8 @@ typedef void (*omp_micro)(int , frame_pointer_t);

typedef void (*omp_task_func)(void *firstprivates, void *fp);

typedef hpx::lcos::local::spinlock mutex_type;
//typedef hpx::lcos::local::spinlock mutex_type;
typedef hpx::spinlock mutex_type;
//typedef hpx::lcos::local::mutex mutex_type;
typedef boost::shared_ptr<mutex_type> mtx_ptr;

Expand Down Expand Up @@ -241,7 +246,8 @@ struct parallel_region {
ompt_data_t parallel_data = ompt_data_none;
#endif
#ifdef OMP_COMPLIANT
shared_ptr<local_priority_queue_executor> exec;
//shared_ptr<local_priority_queue_executor> exec;
shared_ptr<parallel_executor> exec;
#endif
};

Expand Down Expand Up @@ -311,7 +317,8 @@ class omp_task_data {
#endif

#ifdef OMP_COMPLIANT
shared_ptr<local_priority_queue_executor> tg_exec;
//shared_ptr<local_priority_queue_executor> tg_exec;
shared_ptr<parallel_executor> tg_exec;
#else
shared_ptr<hpxmp_latch> taskgroupLatch;
#endif
Expand Down
11 changes: 10 additions & 1 deletion src/kmp_atomic.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,11 @@ typedef unsigned long kmp_uintptr_t;
128-bit extended precision type yet */
typedef long double _Quad;
#elif KMP_COMPILER_GCC
#ifdef __riscv
typedef _Float128 _Quad;
#else
typedef __float128 _Quad;
#endif
# undef KMP_HAVE_QUAD
# define KMP_HAVE_QUAD 1
#elif KMP_COMPILER_MSVC
Expand All @@ -107,6 +111,11 @@ typedef unsigned long kmp_uintptr_t;

# define KMP_ARCH_X86 0

#ifdef __riscv
#undef KMP_HAVE_QUAD
#define KMP_HAVE_QUAD 0
#endif

//Is not set. When/why would I need it?
#ifdef USE_VOLATILE_CAST
# define VOLATILE_CAST(x) (volatile x)
Expand Down Expand Up @@ -190,7 +199,7 @@ extern "C" {
// Atomic locks can easily become contended, so we use queuing locks for them.

//typedef kmp_queuing_lock_t kmp_atomic_lock_t;
typedef hpx::lcos::local::spinlock kmp_atomic_lock_t;
typedef hpx::spinlock kmp_atomic_lock_t; //hpx::lcos::local::spinlock kmp_atomic_lock_t;

//typedef boost::shared_ptr<mutex_type> mtx_ptr;

Expand Down
Loading

0 comments on commit 4fb1791

Please sign in to comment.