Skip to content

Commit

Permalink
Implement changes, remove dead code, fix clang warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
ikbuibui committed Mar 28, 2024
1 parent 43e6370 commit f158501
Show file tree
Hide file tree
Showing 36 changed files with 182 additions and 487 deletions.
8 changes: 4 additions & 4 deletions examples/1_resources.cpp
Expand Up @@ -27,10 +27,10 @@ int main(int, char*[])

redGrapes::ResourceUser<TTask> user3({b.read(), c.write()});

std::cout << "is_serial(user1,user1) = " << redGrapes::ResourceUser<TTask>::is_serial(user1, user1) << std::endl;
std::cout << "is_serial(user1,user2) = " << redGrapes::ResourceUser<TTask>::is_serial(user1, user2) << std::endl;
std::cout << "is_serial(user1,user3) = " << redGrapes::ResourceUser<TTask>::is_serial(user1, user3) << std::endl;
std::cout << "is_serial(user2,user3) = " << redGrapes::ResourceUser<TTask>::is_serial(user2, user3) << std::endl;
std::cout << "is_serial(user1,user1) = " << is_serial(user1, user1) << std::endl;
std::cout << "is_serial(user1,user2) = " << is_serial(user1, user2) << std::endl;
std::cout << "is_serial(user1,user3) = " << is_serial(user1, user3) << std::endl;
std::cout << "is_serial(user2,user3) = " << is_serial(user2, user3) << std::endl;

return 0;
}
2 changes: 2 additions & 0 deletions examples/6_resource_scope.cpp
Expand Up @@ -8,6 +8,8 @@
#include <redGrapes/redGrapes.hpp>
#include <redGrapes/resource/ioresource.hpp>

#include <iostream>

namespace rg = redGrapes;

int main()
Expand Down
2 changes: 1 addition & 1 deletion examples/CMakeLists.txt
Expand Up @@ -55,7 +55,7 @@ if(CMAKE_CUDA_COMPILER)
enable_language(CUDA)

add_executable(cuda_mandelbrot cuda_mandelbrot.cu)
target_compile_features(cuda_mandelbrot PUBLIC cuda_std_14)
target_compile_features(cuda_mandelbrot PUBLIC cxx_std_${redGrapes_CXX_STANDARD})
set_target_properties(cuda_mandelbrot PROPERTIES
CUDA_EXTENSIONS OFF
CUDA_STANDARD_REQUIRED ON
Expand Down
25 changes: 7 additions & 18 deletions examples/cholesky.cpp
Expand Up @@ -5,24 +5,13 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/

#include <cblas.h>

#include <iostream>
// work-around, see
// https://github.com/xianyi/OpenBLAS/issues/1992#issuecomment-459474791
// https://github.com/xianyi/OpenBLAS/pull/1998
#include <complex>
#define lapack_complex_float std::complex<float>
#define lapack_complex_double std::complex<double>
// end work-around
#include <redGrapes/redGrapes.hpp>
#include <redGrapes/resource/ioresource.hpp>

#include <cblas.h>
#include <lapacke.h>

#define REDGRAPES_TASK_PROPERTIES redGrapes::LabelProperty

#include "redGrapes/resource/ioresource.hpp"

#include <redGrapes/redGrapes.hpp>
#include <iostream>

template<typename TTask>
void print_matrix(std::vector<redGrapes::IOResource<double*, TTask>> A, int nblks, int blocksize)
Expand Down Expand Up @@ -139,7 +128,7 @@ int main(int argc, char* argv[])
{
// A[j,j] = A[j,j] - A[j,i] * (A[j,i])^t
rg.emplace_task(
[blksz, nblks](auto a, auto c)
[blksz](auto a, auto c)
{
spdlog::debug("dsyrk");
cblas_dsyrk(
Expand All @@ -161,7 +150,7 @@ int main(int argc, char* argv[])

// Cholesky Factorization of A[j,j]
rg.emplace_task(
[j, blksz, nblks](auto a)
[blksz](auto a)
{
spdlog::debug("dpotrf");
LAPACKE_dpotrf(LAPACK_COL_MAJOR, 'L', blksz, *a, blksz);
Expand All @@ -172,7 +161,7 @@ int main(int argc, char* argv[])
{
// A[i,j] <- A[i,j] = X * (A[j,j])^t
rg.emplace_task(
[blksz, nblks](auto a, auto b)
[blksz](auto a, auto b)
{
spdlog::debug("dtrsm");
cblas_dtrsm(
Expand Down
16 changes: 8 additions & 8 deletions examples/mpi.cpp
Expand Up @@ -4,6 +4,7 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#define ENABLE_WORKSTEALING 1

#include <redGrapes/SchedulerDescription.hpp>
#include <redGrapes/dispatch/mpi/mpiWorker.hpp>
Expand All @@ -14,6 +15,8 @@
#include <redGrapes/scheduler/thread_scheduler.hpp>
#include <redGrapes/task/property/label.hpp>

#include <iostream>

/**
* This example shows how to use MPI with redGrapes.
*
Expand All @@ -40,8 +43,6 @@ enum SchedulerTags
SCHED_CUDA
};

#define ENABLE_WORKSTEALING 1

struct MPIConfig
{
int world_rank;
Expand All @@ -64,16 +65,15 @@ int main()

auto rg = redGrapes::init(
redGrapes::SchedulerDescription(
std::make_shared<
redGrapes::scheduler::PoolScheduler<RGTask, redGrapes::dispatch::thread::DefaultWorker<RGTask>>>(17),
std::make_shared<redGrapes::scheduler::PoolScheduler<redGrapes::dispatch::thread::DefaultWorker<RGTask>>>(
17),
UselessWorkers{}),
redGrapes::SchedulerDescription(
std::make_shared<
redGrapes::scheduler::PoolScheduler<RGTask, redGrapes::dispatch::thread::DefaultWorker<RGTask>>>(4),
std::make_shared<redGrapes::scheduler::PoolScheduler<redGrapes::dispatch::thread::DefaultWorker<RGTask>>>(
4),
redGrapes::DefaultTag{}),
redGrapes::SchedulerDescription(
std::make_shared<
redGrapes::scheduler::ThreadScheduler<RGTask, redGrapes::dispatch::mpi::MPIWorker<RGTask>>>(),
std::make_shared<redGrapes::scheduler::ThreadScheduler<redGrapes::dispatch::mpi::MPIWorker<RGTask>>>(),
MPITag{}));


Expand Down
5 changes: 5 additions & 0 deletions redGrapes/TaskFreeCtx.hpp
Expand Up @@ -10,6 +10,11 @@
#include "redGrapes/memory/chunked_bump_alloc.hpp"
#include "redGrapes/memory/hwloc_alloc.hpp"

#include <functional>
#include <memory>
#include <optional>
#include <vector>

namespace redGrapes
{

Expand Down
1 change: 1 addition & 0 deletions redGrapes/dispatch/mpi/mpiWorker.hpp
Expand Up @@ -23,6 +23,7 @@ namespace redGrapes
template<typename TTask>
struct MPIWorker
{
using task_type = TTask;
std::shared_ptr<RequestPool<TTask>> requestPool;
WorkerId id;

Expand Down
12 changes: 6 additions & 6 deletions redGrapes/dispatch/thread/DefaultWorker.hpp
Expand Up @@ -25,7 +25,7 @@ namespace redGrapes
namespace thread
{

template<typename TTask, typename Worker>
template<typename Worker>
struct WorkerPool;

/*!
Expand All @@ -37,10 +37,11 @@ namespace redGrapes
template<typename TTask>
struct DefaultWorker
{
using task_type = TTask;
// private:
WorkerId id;
AtomicBitfield& m_worker_state;
WorkerPool<TTask, DefaultWorker>& m_worker_pool;
WorkerPool<DefaultWorker>& m_worker_pool;

/*! if true, the thread shall stop
* instead of waiting when it is out of jobs
Expand All @@ -57,10 +58,7 @@ namespace redGrapes
task::Queue<TTask> emplacement_queue{queue_capacity};
task::Queue<TTask> ready_queue{queue_capacity};

DefaultWorker(
WorkerId worker_id,
AtomicBitfield& worker_state,
WorkerPool<TTask, DefaultWorker>& worker_pool)
DefaultWorker(WorkerId worker_id, AtomicBitfield& worker_state, WorkerPool<DefaultWorker>& worker_pool)
: id(worker_id)
, m_worker_state(worker_state)
, m_worker_pool(worker_pool)
Expand Down Expand Up @@ -117,3 +115,5 @@ namespace redGrapes
} // namespace thread
} // namespace dispatch
} // namespace redGrapes

#include "redGrapes/dispatch/thread/DefaultWorker.tpp"
4 changes: 2 additions & 2 deletions redGrapes/dispatch/thread/WorkerThread.hpp
Expand Up @@ -18,7 +18,7 @@

namespace redGrapes::dispatch::thread
{
template<typename TTask, typename Worker>
template<typename Worker>
struct WorkerThread
{
std::thread thread;
Expand Down Expand Up @@ -48,7 +48,7 @@ namespace redGrapes::dispatch::thread
hwloc_obj_t const obj,
WorkerId worker_id,
AtomicBitfield& worker_state,
WorkerPool<TTask, Worker>& worker_pool)
WorkerPool<Worker>& worker_pool)
: alloc(alloc)
, hwloc_ctx(hwloc_ctx)
, obj{obj}
Expand Down
47 changes: 0 additions & 47 deletions redGrapes/dispatch/thread/cpuset.hpp

This file was deleted.

20 changes: 12 additions & 8 deletions redGrapes/dispatch/thread/worker_pool.hpp
Expand Up @@ -7,7 +7,6 @@
#pragma once

#include "redGrapes/TaskFreeCtx.hpp"
#include "redGrapes/dispatch/thread/DefaultWorker.hpp"
#include "redGrapes/memory/hwloc_alloc.hpp"
#include "redGrapes/util/bitfield.hpp"

Expand All @@ -27,12 +26,15 @@ namespace redGrapes
AVAILABLE = 1
};

template<typename TTask, typename Worker>
template<typename Worker>
struct WorkerThread;

template<typename TTask, typename Worker>
template<typename Worker>
struct WorkerPool
{
using task_type = Worker::task_type;
using TTask = task_type;

WorkerPool(HwlocContext& hwloc_ctx, size_t n_workers);
~WorkerPool();

Expand All @@ -53,7 +55,7 @@ namespace redGrapes
*/
void stop();

inline WorkerThread<TTask, Worker>& get_worker_thread(WorkerId local_worker_id)
inline WorkerThread<Worker>& get_worker_thread(WorkerId local_worker_id)
{
assert(local_worker_id < size());
return *workers[local_worker_id];
Expand Down Expand Up @@ -96,7 +98,7 @@ namespace redGrapes
* task-graph in the emplacement queues of other workers
* and removes it from there
*/
TTask* steal_new_task(dispatch::thread::DefaultWorker<TTask>& worker)
TTask* steal_new_task(Worker& worker)
{
std::optional<TTask*> task = probe_worker_by_state<TTask*>(
[&worker, this](unsigned idx) -> std::optional<TTask*>
Expand Down Expand Up @@ -127,7 +129,7 @@ namespace redGrapes
/* tries to find a ready task in any queue of other workers
* and removes it from the queue
*/
TTask* steal_ready_task(dispatch::thread::DefaultWorker<TTask>& worker)
TTask* steal_ready_task(Worker& worker)
{
std::optional<TTask*> task = probe_worker_by_state<TTask*>(
[&worker, this](unsigned idx) -> std::optional<TTask*>
Expand Down Expand Up @@ -157,7 +159,7 @@ namespace redGrapes

// give worker a ready task if available
// @return task if a new task was found, nullptr otherwise
TTask* steal_task(dispatch::thread::DefaultWorker<TTask>& worker)
TTask* steal_task(Worker& worker)
{
unsigned local_worker_id = worker.id - m_base_id;

Expand Down Expand Up @@ -186,7 +188,7 @@ namespace redGrapes


private:
std::vector<std::shared_ptr<dispatch::thread::WorkerThread<TTask, Worker>>> workers;
std::vector<std::shared_ptr<dispatch::thread::WorkerThread<Worker>>> workers;
HwlocContext& hwloc_ctx;
AtomicBitfield worker_state;
unsigned int num_workers;
Expand All @@ -197,3 +199,5 @@ namespace redGrapes
} // namespace thread
} // namespace dispatch
} // namespace redGrapes

#include "redGrapes/dispatch/thread/worker_pool.tpp"

0 comments on commit f158501

Please sign in to comment.