From 6a90772a440c1f4ec5088f2814cae7126a92777b Mon Sep 17 00:00:00 2001 From: sant0s12 Date: Sun, 26 May 2024 15:44:29 +0200 Subject: [PATCH] [software] Fix clang warnings --- software/runtime/kmp/barrier.cpp | 2 +- software/runtime/kmp/cppsupport.cpp | 18 +++- software/runtime/kmp/entrypoints.cpp | 122 ++++++++++++++------------ software/runtime/kmp/main_wrapper.cpp | 15 ++-- software/runtime/kmp/runtime.cpp | 4 - software/runtime/kmp/runtime.hpp | 14 ++- software/runtime/kmp/task.cpp | 6 +- software/runtime/kmp/team.cpp | 7 +- software/runtime/kmp/team.hpp | 94 +++++++++++--------- software/runtime/kmp/thread.cpp | 6 +- software/runtime/kmp/thread.hpp | 3 +- software/runtime/link.ld | 2 +- 12 files changed, 159 insertions(+), 134 deletions(-) diff --git a/software/runtime/kmp/barrier.cpp b/software/runtime/kmp/barrier.cpp index 0c009b536..4c5217131 100644 --- a/software/runtime/kmp/barrier.cpp +++ b/software/runtime/kmp/barrier.cpp @@ -1,7 +1,7 @@ #include "barrier.hpp" namespace kmp { -Barrier::Barrier(uint32_t numThreads) : numThreads(numThreads) {} +Barrier::Barrier(uint32_t numThreads) : barrier(0), numThreads(numThreads) {} Barrier::~Barrier() { DEBUG_PRINT("Destroying barrier at %p\n", this); } diff --git a/software/runtime/kmp/cppsupport.cpp b/software/runtime/kmp/cppsupport.cpp index 6590bd55d..dd4f5aa4e 100644 --- a/software/runtime/kmp/cppsupport.cpp +++ b/software/runtime/kmp/cppsupport.cpp @@ -1,3 +1,4 @@ +#include #include // Comment so that is imported before @@ -25,13 +26,24 @@ void *operator new[](size_t size) { return operator new(size); } void operator delete[](void *ptr) noexcept { return operator delete(ptr); } namespace std { -void __throw_bad_alloc() { printf("Bad alloc\n"); } -void __throw_length_error(const char *msg) { printf("Length error: %s\n", msg); } +void __throw_bad_alloc() { + printf("Bad alloc\n"); + abort(); +} + +void __throw_length_error(const char *msg) { + printf("Length error: %s\n", msg); + abort(); +} + void __throw_bad_optional_access() { printf("Bad optional access\n"); } } // namespace std extern "C" void abort() { printf("Aborting\n"); + while (true) { + mempool_wfi(); + } } extern "C" int __cxa_atexit(void (*func)(void *), void *arg, void *dso_handle) { @@ -45,5 +57,5 @@ extern "C" void __assert_func(const char *file, int line, const char *func, const char *failedexpr) { printf("Assertion failed: %s, file %s, line %d, function %s\n", failedexpr, file, line, func); - mempool_wfi(); + abort(); } diff --git a/software/runtime/kmp/entrypoints.cpp b/software/runtime/kmp/entrypoints.cpp index d9c8455d2..db2ad88f1 100644 --- a/software/runtime/kmp/entrypoints.cpp +++ b/software/runtime/kmp/entrypoints.cpp @@ -1,28 +1,28 @@ #include "kmp/runtime.hpp" -#include "kmp/types.h" #include "kmp/team.hpp" +#include "kmp/types.h" + +using kmp::Mutex; extern "C" { #include "runtime.h" -// NOLINTBEGIN(bugprone-reserved-identifier) - -void __kmpc_barrier(ident_t *loc, kmp_int32 global_tid) { - // DEBUG_PRINT("__kmpc_barrier called by %d\n", global_tid); - kmp::runtime::getCurrentThread(global_tid) +void __kmpc_barrier(ident_t * /*loc*/, kmp_int32 global_tid) { + kmp::runtime::getCurrentThread(static_cast(global_tid)) .getCurrentTeam() ->getBarrier() .wait(); }; // Parallel -void __kmpc_fork_call(ident_t *loc, kmp_int32 argc, kmpc_micro microtask, ...) { - // NOLINTBEGIN(cppcoreguidelines-pro-type-vararg,cppcoreguidelines-pro-bounds-array-to-pointer-decay) +void __kmpc_fork_call(ident_t * /*loc*/, kmp_int32 argc, kmpc_micro microtask, + ...) { + // NOLINTBEGIN(cppcoreguidelines-pro-bounds-array-to-pointer-decay) va_list args; va_start(args, microtask); kmp::Microtask kmpMicrotask(microtask, args, argc); va_end(args); - // NOLINTEND(cppcoreguidelines-pro-type-vararg,cppcoreguidelines-pro-bounds-array-to-pointer-decay) + // NOLINTEND(cppcoreguidelines-pro-bounds-array-to-pointer-decay) kmp::runtime::getCurrentThread().forkCall(std::move(kmpMicrotask)); }; @@ -47,22 +47,24 @@ void __kmpc_for_static_init_4u(ident_t *loc, kmp_int32 gtid, pupper, pstride, incr, chunk); }; -void __kmpc_for_static_init_8(ident_t *loc, kmp_int32 gtid, kmp_int32 schedtype, - kmp_int64 *plastiter, kmp_int64 *plower, - kmp_int64 *pupper, kmp_int64 *pstride, - kmp_int64 incr, kmp_int64 chunk) { +void __kmpc_for_static_init_8(ident_t * /*loc*/, kmp_int32 /*gtid*/, + kmp_int32 /*schedtype*/, + kmp_int64 * /*plastiter*/, kmp_int64 * /*plower*/, + kmp_int64 * /*pupper*/, kmp_int64 * /*pstride*/, + kmp_int64 /*incr*/, kmp_int64 /*chunk*/) { assert(false && "Unsupported loop index type"); }; -void __kmpc_for_static_init_8u(ident_t *loc, kmp_int32 gtid, - kmp_int32 schedtype, kmp_uint64 *plastiter, - kmp_uint64 *plower, kmp_uint64 *pupper, - kmp_int64 *pstride, kmp_int64 incr, - kmp_int64 chunk) { +void __kmpc_for_static_init_8u(ident_t * /*loc*/, kmp_int32 /*gtid*/, + kmp_int32 /*schedtype*/, + kmp_uint64 * /*plastiter*/, + kmp_uint64 * /*plower*/, kmp_uint64 * /*pupper*/, + kmp_int64 * /*pstride*/, kmp_int64 /*incr*/, + kmp_int64 /*chunk*/) { assert(false && "Unsupported loop index type"); }; -void __kmpc_for_static_fini(ident_t *loc, kmp_int32 global_tid){}; +void __kmpc_for_static_fini(ident_t * /*loc*/, kmp_int32 /*global_tid*/){}; // Dynamic loops void __kmpc_dispatch_init_4(ident_t *loc, kmp_int32 gtid, kmp_int32 schedtype, @@ -83,75 +85,84 @@ void __kmpc_dispatch_init_4u(ident_t *loc, kmp_int32 gtid, kmp_int32 schedtype, upper, incr, chunk); } -void __kmpc_dispatch_init_8(ident_t *loc, kmp_int64 gtid, - kmp_sched_type schedtype, kmp_int64 lower, - kmp_int64 upper, kmp_int64 incr, kmp_int64 chunk) { +void __kmpc_dispatch_init_8(ident_t * /*loc*/, kmp_int64 /*gtid*/, + kmp_sched_type /*schedtype*/, kmp_int64 /*lower*/, + kmp_int64 /*upper*/, kmp_int64 /*incr*/, + kmp_int64 /*chunk*/) { assert(false && "Unsupported loop index type"); } -void __kmpc_dispatch_init_8u(ident_t *loc, kmp_int64 gtid, - kmp_sched_type schedtype, kmp_uint64 lower, - kmp_uint64 upper, kmp_int64 incr, - kmp_int64 chunk) { +void __kmpc_dispatch_init_8u(ident_t * /*loc*/, kmp_int64 /*gtid*/, + kmp_sched_type /*schedtype*/, kmp_uint64 /*lower*/, + kmp_uint64 /*upper*/, kmp_int64 /*incr*/, + kmp_int64 /*chunk*/) { assert(false && "Unsupported loop index type"); } int __kmpc_dispatch_next_4(ident_t *loc, kmp_int32 gtid, kmp_int32 *plastiter, kmp_int32 *plower, kmp_int32 *pupper, kmp_int32 *pstride) { - return kmp::runtime::getCurrentThread().getCurrentTeam()->dispatchNext( - loc, gtid, plastiter, plower, pupper, pstride); + return static_cast( + kmp::runtime::getCurrentThread().getCurrentTeam()->dispatchNext( + loc, gtid, plastiter, plower, pupper, pstride)); } int __kmpc_dispatch_next_4u(ident_t *loc, kmp_int32 gtid, kmp_int32 *plastiter, kmp_uint32 *plower, kmp_uint32 *pupper, kmp_int32 *pstride) { - return kmp::runtime::getCurrentThread().getCurrentTeam()->dispatchNext( - loc, gtid, plastiter, plower, pupper, pstride); + return static_cast( + kmp::runtime::getCurrentThread().getCurrentTeam()->dispatchNext( + loc, gtid, plastiter, plower, pupper, pstride)); } -int __kmpc_dispatch_next_8(ident_t *loc, kmp_int64 gtid, kmp_int64 *plastiter, - kmp_int64 *plower, kmp_int64 *pupper, - kmp_int64 *pstride) { +int __kmpc_dispatch_next_8(ident_t * /*loc*/, kmp_int64 /*gtid*/, + kmp_int64 * /*plastiter*/, kmp_int64 * /*plower*/, + kmp_int64 * /*pupper*/, kmp_int64 * /*pstride*/) { assert(false && "Unsupported loop index type"); } -int __kmpc_dispatch_next_8u(ident_t *loc, kmp_int64 gtid, kmp_int64 *plastiter, - kmp_uint64 *plower, kmp_uint64 *pupper, - kmp_int64 *pstride) { +int __kmpc_dispatch_next_8u(ident_t * /*loc*/, kmp_int64 /*gtid*/, + kmp_int64 * /*plastiter*/, kmp_uint64 * /*plower*/, + kmp_uint64 * /*pupper*/, kmp_int64 * /*pstride*/) { assert(false && "Unsupported loop index type"); } -void __kmpc_push_num_threads(ident_t *loc, kmp_int32 global_tid, +void __kmpc_push_num_threads(ident_t * /*loc*/, kmp_int32 /*global_tid*/, kmp_int32 num_threads) { kmp::runtime::getCurrentThread().requestNumThreads(num_threads); }; // Critical sections -void __kmpc_critical(ident_t *, kmp_int32 gtid, kmp_critical_name *crit) { +void __kmpc_critical(ident_t * /*unused*/, kmp_int32 /*gtid*/, + kmp_critical_name *crit) { static_assert(sizeof(kmp::Mutex) <= sizeof(kmp_critical_name)); + + // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast) kmp::Mutex *mutex = reinterpret_cast(*crit); mutex->lock(); }; -void __kmpc_end_critical(ident_t *, kmp_int32 gtid, kmp_critical_name *crit) { - kmp::Mutex *mutex = reinterpret_cast(*crit); +void __kmpc_end_critical(ident_t * /*unused*/, kmp_int32 /*gtid*/, + kmp_critical_name *crit) { + + // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast) + Mutex *mutex = reinterpret_cast(*crit); mutex->unlock(); }; // Master -kmp_int32 __kmpc_master(ident_t *loc, int32_t gtid) { +kmp_int32 __kmpc_master(ident_t * /*loc*/, kmp_int32 /*gtid*/) { return static_cast(kmp::runtime::getCurrentThread().getTid() == 0); }; -void __kmpc_end_master(ident_t *loc, int32_t gtid){/* NOOP */}; +void __kmpc_end_master(ident_t * /*loc*/, kmp_int32 /*gtid*/){/* NOOP */}; // Single (same as master for now) -kmp_int32 __kmpc_single(ident_t *loc, int32_t gtid) { +kmp_int32 __kmpc_single(ident_t * /*loc*/, kmp_int32 /*gtid*/) { return static_cast(kmp::runtime::getCurrentThread().getTid() == 0); }; -void __kmpc_end_single(ident_t *loc, int32_t gtid){/* NOOP */}; +void __kmpc_end_single(ident_t * /*loc*/, kmp_int32 /*gtid*/){/* NOOP */}; // Copyprivate void __kmpc_copyprivate(ident_t *loc, kmp_int32 gtid, size_t cpy_size, @@ -162,16 +173,17 @@ void __kmpc_copyprivate(ident_t *loc, kmp_int32 gtid, size_t cpy_size, }; // Reduction -kmp_int32 -__kmpc_reduce_nowait(ident_t *loc, kmp_int32 global_tid, kmp_int32 num_vars, - size_t reduce_size, void *reduce_data, - void (*reduce_func)(void *lhs_data, void *rhs_data), - kmp_critical_name *lck) { +kmp_int32 __kmpc_reduce_nowait(ident_t * /*loc*/, kmp_int32 /*global_tid*/, + kmp_int32 /*num_vars*/, size_t /*reduce_size*/, + void * /*reduce_data*/, + void (* /*reduce_func*/)(void *lhs_data, + void *rhs_data), + kmp_critical_name * /*lck*/) { return 2; // Atomic reduction } -void __kmpc_end_reduce_nowait(ident_t *loc, kmp_int32 global_tid, - kmp_critical_name *lck) { +void __kmpc_end_reduce_nowait(ident_t * /*loc*/, kmp_int32 /*global_tid*/, + kmp_critical_name * /*lck*/) { /* NOOP */ } @@ -185,13 +197,11 @@ kmp_int32 __kmpc_reduce(ident_t *loc, kmp_int32 global_tid, kmp_int32 num_vars, } void __kmpc_end_reduce(ident_t *loc, kmp_int32 global_tid, - kmp_critical_name *lck) { + kmp_critical_name * /*lck*/) { return __kmpc_barrier(loc, global_tid); } -kmp_int32 __kmpc_global_thread_num(ident_t *loc) { - return mempool_get_core_id(); +kmp_int32 __kmpc_global_thread_num(ident_t * /*loc*/) { + return static_cast(mempool_get_core_id()); }; - -// NOLINTEND(bugprone-reserved-identifier) } diff --git a/software/runtime/kmp/main_wrapper.cpp b/software/runtime/kmp/main_wrapper.cpp index 6858d6aef..827567f76 100644 --- a/software/runtime/kmp/main_wrapper.cpp +++ b/software/runtime/kmp/main_wrapper.cpp @@ -6,12 +6,15 @@ extern "C" { // https://etherealwake.com/2021/09/crt-startup/ typedef void (*init_func)(void); -extern init_func __init_array_start[]; -extern init_func __init_array_end[]; +extern init_func *__init_array_start; +extern init_func *__init_array_end; static inline void initGlobals() { - uint32_t n = __init_array_end - __init_array_start; - for (size_t i = 0; i < n; i++) { + //NOLINTNEXTLINE(*-narrowing-conversions) + int32_t len = __init_array_end - __init_array_start; + for (int32_t i = 0; i < len; i++) { + + // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) __init_array_start[i](); } } @@ -23,7 +26,7 @@ std::atomic initLock = true; extern "C" int __wrap_main() { const mempool_id_t core_id = mempool_get_core_id(); if (core_id == 0) { - printf("Running OpenMP program on %d cores\n", mempool_get_core_count()); + DEBUG_PRINT("Running OpenMP program on %d cores\n", mempool_get_core_count()); // Init heap allocators mempool_init(0); @@ -36,7 +39,7 @@ extern "C" int __wrap_main() { initLock = false; - printf("Init done\n"); + DEBUG_PRINT("Init done\n"); // Run the program __real_main(); diff --git a/software/runtime/kmp/runtime.cpp b/software/runtime/kmp/runtime.cpp index 76cf684c3..e1647d1dc 100644 --- a/software/runtime/kmp/runtime.cpp +++ b/software/runtime/kmp/runtime.cpp @@ -3,10 +3,6 @@ #include #include -extern "C" { -#include "runtime.h" -} - namespace kmp { namespace runtime { diff --git a/software/runtime/kmp/runtime.hpp b/software/runtime/kmp/runtime.hpp index 53561a505..e87948ace 100644 --- a/software/runtime/kmp/runtime.hpp +++ b/software/runtime/kmp/runtime.hpp @@ -1,18 +1,16 @@ #pragma once +#include "etl/error_handler.h" #include "kmp/thread.hpp" #include "kmp/types.h" -#include "etl/error_handler.h" - -extern "C" { -#include "runtime.h" -} // NOLINTNEXTLINE(bugprone-reserved-identifier) extern void __assert_func(const char *file, int line, const char *func, const char *failedexpr); -static inline void assertWrapper(const etl::exception &e) { - __assert_func(e.file_name(), e.line_number(), "n/a", e.what()); + +static inline void assertWrapper(const etl::exception &exception) { + __assert_func(exception.file_name(), exception.line_number(), "n/a", + exception.what()); }; namespace kmp { @@ -33,7 +31,7 @@ static inline void init() { static inline void runThread(kmp_uint32 core_id) { threads[core_id].run(); }; -static inline Thread &getCurrentThread(kmp_int32 gtid) { +static inline Thread &getCurrentThread(kmp_uint32 gtid) { return threads[gtid]; }; diff --git a/software/runtime/kmp/task.cpp b/software/runtime/kmp/task.cpp index b22933d65..c6d51c022 100644 --- a/software/runtime/kmp/task.cpp +++ b/software/runtime/kmp/task.cpp @@ -19,7 +19,7 @@ Microtask::Microtask(kmpc_micro func, va_list args, kmp_int32 argc) return; } - this->args = new void *[argc]; + this->args = new void *[static_cast(argc)]; DEBUG_PRINT("Microtask constructor, args: %p\n", this->args); @@ -49,9 +49,7 @@ Microtask &Microtask::operator=(Microtask &&other) noexcept { return *this; }; -Microtask::~Microtask() { - delete[] args; -}; +Microtask::~Microtask() { delete[] args; }; void Microtask::run() const { kmp_int32 gtid = static_cast(mempool_get_core_id()); diff --git a/software/runtime/kmp/team.cpp b/software/runtime/kmp/team.cpp index 5364cb8ec..96a0d3e9b 100644 --- a/software/runtime/kmp/team.cpp +++ b/software/runtime/kmp/team.cpp @@ -4,10 +4,9 @@ namespace kmp { -Team::Team(kmp_int32 masterGtid, kmp_uint32 numThreads, +Team::Team(kmp_uint32 masterGtid, kmp_uint32 numThreads, std::optional implicitTask) - : numThreads(numThreads), barrier(numThreads), - dynamicSchedule{.valid = false}, implicitTask(std::move(implicitTask)), - copyPrivateData(nullptr), masterGtid(masterGtid) {} + : masterGtid(masterGtid), numThreads(numThreads), barrier(numThreads), + implicitTask(std::move(implicitTask)) {} } // namespace kmp diff --git a/software/runtime/kmp/team.hpp b/software/runtime/kmp/team.hpp index 42099eef5..a42197245 100644 --- a/software/runtime/kmp/team.hpp +++ b/software/runtime/kmp/team.hpp @@ -1,5 +1,6 @@ #pragma once +#include "kmp/barrier.hpp" #include "kmp/runtime.hpp" #include "kmp/types.h" #include "kmp/util.hpp" @@ -7,6 +8,7 @@ #include #include #include +#include namespace kmp { @@ -16,20 +18,24 @@ class Barrier; class Team { + template ::type, + typename UnsignedT = typename std::make_unsigned::type> struct DynamicSchedule { - kmp_uint32 lowerNext; - kmp_uint32 upper; - kmp_uint32 chunk; - kmp_uint32 incr; - kmp_uint32 stride; + DynamicSchedule() {} - bool valid; + T lowerNext = 0; + T upper = 0; + SignedT chunk = 0; + SignedT incr = 0; + SignedT stride = 0; + + bool valid = false; Mutex mutex; }; public: - Team(kmp_int32 masterGtid, kmp_uint32 numThreads, + Team(kmp_uint32 masterGtid, kmp_uint32 numThreads, std::optional implicitTask = std::nullopt); inline Barrier &getBarrier() { return barrier; } @@ -51,7 +57,9 @@ class Team { inline auto getCopyPrivateData() const { return copyPrivateData; } - inline void invalidateSchedule() { dynamicSchedule.valid = false; } + inline void invalidateSchedule() { + std::get>(this->dynamicSchedule).valid = false; + } inline void run() { for (kmp_uint32 i = 0; i < numThreads; i++) { @@ -79,12 +87,12 @@ class Team { * @param incr Loop increment (this is always 1 in LLVM 14) * @param chunk Chunk size */ - template - void forStaticInit(ident_t *loc, kmp_int32 gtid, kmp_sched_type schedtype, - T *plastiter, T *plower, T *pupper, - typename std::make_signed::type *pstride, - typename std::make_signed::type incr, - typename std::make_signed::type chunk) const { + template ::type, + typename UnsignedT = typename std::make_unsigned::type> + void forStaticInit(ident_t * /*loc*/, kmp_int32 /*gtid*/, + kmp_sched_type schedtype, T *plastiter, T *plower, + T *pupper, SignedT *pstride, SignedT incr, + SignedT chunk) const { assert(incr == 1 && "Loop increment is not 1"); assert(chunk > 0 && "Chunk size is not positive"); @@ -92,32 +100,31 @@ class Team { "Chunk size is greater than loop size"); kmp_uint32 tid = runtime::getCurrentThread().getTid(); - kmp_uint32 numChunks = (pupper - plower + chunk) / chunk; + + UnsignedT numChunks = (static_cast(pupper - plower) + + static_cast(chunk)) / + static_cast(chunk); switch (schedtype) { case kmp_sch_static: { // Calculate chunk size // https://stackoverflow.com/a/14878734 - chunk = (*pupper - *plower + 1) / numThreads + - ((*pupper - *plower + 1) % numThreads != 0); - - // Same as static chunked - kmp_uint32 span = incr * chunk; - *pstride = span * numThreads; - *plower = *plower + tid * span; - *pupper = *plower + span - incr; - *plastiter = (tid == (numChunks - 1) % numThreads); + chunk = static_cast(*pupper - *plower + 1) / + static_cast(numThreads) + + (static_cast(*pupper - *plower + 1) % + static_cast(numThreads) != + 0); - break; + // Fall through to static chunked } case kmp_sch_static_chunked: { assert(incr != 0 && "Loop increment must be non-zero"); - kmp_uint32 span = incr * chunk; - *pstride = span * numThreads; - *plower = *plower + tid * span; - *pupper = *plower + span - incr; + SignedT span = incr * chunk; + *pstride = span * static_cast(numThreads); + *plower = *plower + static_cast(tid) * static_cast(span); + *pupper = *plower + static_cast(span - incr); *plastiter = (tid == (numChunks - 1) % numThreads); break; @@ -129,10 +136,11 @@ class Team { } } - template - void dispatchInit(ident_t *loc, kmp_int32 gtid, kmp_sched_type schedtype, - T lower, T upper, typename std::make_signed::type incr, - typename std::make_signed::type chunk) { + template ::type, + typename UnsignedT = typename std::make_unsigned::type> + void dispatchInit(ident_t * /*loc*/, kmp_int32 /*gtid*/, + kmp_sched_type schedtype, T lower, T upper, SignedT incr, + SignedT chunk) { assert(incr == 1 && "Loop increment is not 1"); assert(chunk > 0 && "Chunk size is not positive"); @@ -141,6 +149,8 @@ class Team { DEBUG_PRINT("Dispatch init\n"); + auto &dynamicSchedule = std::get>(this->dynamicSchedule); + switch (schedtype) { case kmp_sch_dynamic_chunked: { std::lock_guard lock(dynamicSchedule.mutex); @@ -150,13 +160,13 @@ class Team { return; } - kmp_uint32 span = incr * chunk; + SignedT span = incr * chunk; dynamicSchedule.lowerNext = lower; dynamicSchedule.upper = upper; dynamicSchedule.chunk = chunk; dynamicSchedule.incr = incr; - dynamicSchedule.stride = span * numThreads; + dynamicSchedule.stride = span * static_cast(numThreads); DEBUG_PRINT( "Dynamic schedule: lowerNext=%d, upper=%d, chunk=%d, incr=%d, " @@ -176,13 +186,14 @@ class Team { }; } - template - bool dispatchNext(ident_t *loc, kmp_int32 gtid, - typename std::make_signed::type *plastiter, T *plower, - T *pupper, typename std::make_signed::type *pstride) { + template ::type> + bool dispatchNext(ident_t * /*loc*/, kmp_int32 /*gtid*/, SignedT *plastiter, + T *plower, T *pupper, SignedT *pstride) { DEBUG_PRINT("Dispatch next\n"); + auto &dynamicSchedule = std::get>(this->dynamicSchedule); + std::lock_guard lock(dynamicSchedule.mutex); assert(dynamicSchedule.valid && "Dynamic schedule is not valid"); @@ -193,7 +204,7 @@ class Team { *plower = dynamicSchedule.lowerNext; - dynamicSchedule.lowerNext += dynamicSchedule.chunk; + dynamicSchedule.lowerNext += static_cast(dynamicSchedule.chunk); if (dynamicSchedule.lowerNext > dynamicSchedule.upper) { *pupper = dynamicSchedule.upper; *plastiter = true; @@ -214,7 +225,8 @@ class Team { Barrier barrier; - DynamicSchedule dynamicSchedule; + std::variant, DynamicSchedule> + dynamicSchedule; void *copyPrivateData = nullptr; diff --git a/software/runtime/kmp/thread.cpp b/software/runtime/kmp/thread.cpp index 774815641..8cc22d6c3 100644 --- a/software/runtime/kmp/thread.cpp +++ b/software/runtime/kmp/thread.cpp @@ -57,18 +57,16 @@ void Thread::forkCall(Microtask microtask) { DEBUG_PRINT("Done running task\n"); team->getBarrier().wait(); - - team->invalidateSchedule(); }; void Thread::requestNumThreads(kmp_int32 numThreads) { this->requestedNumThreads = numThreads; } -void Thread::copyPrivate(ident_t *loc, kmp_int32 gtid, size_t cpy_size, +void Thread::copyPrivate(ident_t * /*loc*/, kmp_int32 gtid, size_t /*cpy_size*/, void *cpy_data, void (*cpy_func)(void *, void *), kmp_int32 didit) { - auto team = getCurrentTeam(); + auto *team = getCurrentTeam(); if (didit != 0) { team->setCopyPrivateData(cpy_data); diff --git a/software/runtime/kmp/thread.hpp b/software/runtime/kmp/thread.hpp index 95858fd25..26c282a87 100644 --- a/software/runtime/kmp/thread.hpp +++ b/software/runtime/kmp/thread.hpp @@ -1,6 +1,5 @@ #pragma once -#include "kmp/barrier.hpp" #include "kmp/task.hpp" #include "kmp/types.h" #include "kmp/util.hpp" @@ -61,6 +60,6 @@ class Thread { std::atomic currentTeam; Mutex running; - std::optional requestedNumThreads; + std::optional requestedNumThreads; }; }; // namespace kmp diff --git a/software/runtime/link.ld b/software/runtime/link.ld index 2f5c3d685..7ac443922 100644 --- a/software/runtime/link.ld +++ b/software/runtime/link.ld @@ -84,5 +84,5 @@ SECTIONS { .comment : { *(.comment) - } > l2 + } }