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

Remove task type from resources #79

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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: 4 additions & 4 deletions examples/1_resources.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,21 @@
int main(int, char*[])
{
auto rg = redGrapes::init(1);
using TTask = decltype(rg)::RGTask;

auto a = rg.createFieldResource<std::vector<int>>();
auto b = rg.createIOResource<int>();
auto c = rg.createIOResource<int>();

redGrapes::ResourceUser<TTask> user1(
redGrapes::ResourceUser user1(
{a.read(), // complete resource
a.write().area({0}, {10}), // write only indices 0 to 10
b.write()},
0,
0);

redGrapes::ResourceUser<TTask> user2({b.read()}, 0);
redGrapes::ResourceUser user2({b.read()}, 0, 0);

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

std::cout << "is_serial(user1,user1) = " << is_serial(user1, user1) << std::endl;
std::cout << "is_serial(user1,user2) = " << is_serial(user1, user2) << std::endl;
Expand Down
5 changes: 2 additions & 3 deletions examples/cholesky.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@

#include <iostream>

template<typename TTask>
void print_matrix(std::vector<redGrapes::IOResource<double*, TTask>> A, int nblks, int blocksize)
void print_matrix(std::vector<redGrapes::IOResource<double*>> A, int nblks, int blocksize)
{
for(int ia = 0; ia < nblks; ++ia)
{
Expand Down Expand Up @@ -71,7 +70,7 @@ int main(int argc, char* argv[])
Alin[i * N + i] += N;

// initialize tiled matrix in column-major layout
std::vector<redGrapes::IOResource<double*, RGTask>> A(nblks * nblks);
std::vector<redGrapes::IOResource<double*>> A(nblks * nblks);

// allocate each tile (also in column-major layout)
for(size_t j = 0; j < nblks; ++j)
Expand Down
4 changes: 2 additions & 2 deletions examples/cuda_mandelbrot.cu
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ int main()
size_t height = 4096;
size_t area = width * height;

redGrapes::IOResource<Color*, RGTask> host_buffer;
redGrapes::IOResource<Color*, RGTask> device_buffer;
redGrapes::IOResource<Color*> host_buffer;
redGrapes::IOResource<Color*> device_buffer;

rg.emplace_task(
[area](auto host_buffer)
Expand Down
3 changes: 1 addition & 2 deletions examples/game_of_life.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,7 @@ int main(int, char*[])

using Buffer = std::array<std::array<Cell, size.x + 2>, size.y + 2>;

using TaskType = decltype(rg)::RGTask;
std::vector<redGrapes::FieldResource<Buffer, TaskType>> buffers;
std::vector<redGrapes::FieldResource<Buffer>> buffers;

for(size_t i = 0; i < 4; ++i)
buffers.emplace_back();
Expand Down
8 changes: 4 additions & 4 deletions examples/mpi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ int main()
});

// initialize MPI config
redGrapes::IOResource<MPIConfig, RGTask> mpi_config;
redGrapes::IOResource<MPIConfig> mpi_config;
rg.emplace_task<MPITag>(
[](auto config)
{
Expand All @@ -103,9 +103,9 @@ int main()
mpi_config.write());

// main loop
std::array<redGrapes::FieldResource<std::array<int, 4>, RGTask>, 2> field = {
redGrapes::FieldResource<std::array<int, 4>, RGTask>(),
redGrapes::FieldResource<std::array<int, 4>, RGTask>(),
std::array<redGrapes::FieldResource<std::array<int, 4>>, 2> field = {
redGrapes::FieldResource<std::array<int, 4>>(),
redGrapes::FieldResource<std::array<int, 4>>(),
};

int current = 0;
Expand Down
87 changes: 0 additions & 87 deletions redGrapes/TaskCtx.hpp

This file was deleted.

8 changes: 4 additions & 4 deletions redGrapes/dispatch/cuda/cuda_worker.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@

#pragma once

#include "redGrapes/TaskCtx.hpp"
#include "redGrapes/dispatch/cuda/cuda_task_properties.hpp"
#include "redGrapes/dispatch/cuda/event_pool.hpp"
#include "redGrapes/globalSpace.hpp"
#include "redGrapes/scheduler/event.hpp"
#include "redGrapes/sync/cv.hpp"
#include "redGrapes/task/queue.hpp"
Expand Down Expand Up @@ -108,15 +108,15 @@ namespace redGrapes::dispatch::cuda
assert(task.is_ready());
std::lock_guard<std::recursive_mutex> lock(mutex);

TaskCtx<TTask>::current_task = &task;
current_task = &task;

// run the code that calls the CUDA API and submits work to *task->m_cuda_stream_idx
auto event = task();

cudaEvent_t cuda_event = event_pool.alloc();
// works even if the m_cuda_stream index optional is nullopt, because it gets casted to 0
cudaEventRecord(cuda_event, streams[*(task->m_cuda_stream_idx)].cuda_stream);
auto my_event = TaskCtx<TTask>::create_event();
auto my_event = create_event_impl<TTask>();
events.push(std::make_pair(cuda_event, *my_event));
SPDLOG_TRACE(
"CudaStreamDispatcher {}: recorded event {}",
Expand All @@ -137,7 +137,7 @@ namespace redGrapes::dispatch::cuda
else
task.get_post_event().notify();

TaskCtx<TTask>::current_task = nullptr;
current_task = nullptr;
}

/* repeatedly try to find and execute tasks
Expand Down
5 changes: 3 additions & 2 deletions redGrapes/dispatch/mpi/mpiWorker.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#pragma once
#include "redGrapes/TaskFreeCtx.hpp"
#include "redGrapes/dispatch/mpi/request_pool.hpp"
#include "redGrapes/globalSpace.hpp"
#include "redGrapes/sync/cv.hpp"
#include "redGrapes/task/queue.hpp"

Expand Down Expand Up @@ -75,7 +76,7 @@ namespace redGrapes
assert(task.is_ready());

task.get_pre_event().notify();
TaskCtx<TTask>::current_task = &task;
current_task = &task;

auto event = task();

Expand All @@ -90,7 +91,7 @@ namespace redGrapes
else
task.get_post_event().notify();

TaskCtx<TTask>::current_task = nullptr;
current_task = nullptr;
}

/* find a task that shall be executed next
Expand Down
8 changes: 4 additions & 4 deletions redGrapes/dispatch/mpi/request_pool.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

#pragma once

#include "redGrapes/TaskCtx.hpp"
#include "redGrapes/globalSpace.hpp"
#include "redGrapes/scheduler/event.hpp"

#include <mpi.h>
Expand Down Expand Up @@ -83,8 +83,8 @@ namespace redGrapes
*/
MPI_Status get_status(MPI_Request request)
{
auto status = memory::alloc_shared_bind<MPI_Status>((*TaskCtx<TTask>::current_task)->worker_id);
auto event = *TaskCtx<TTask>::create_event();
auto status = memory::alloc_shared_bind<MPI_Status>(static_cast<TTask*>(current_task)->worker_id);
auto event = *create_event_impl<TTask>();

// SPDLOG_TRACE("MPI RequestPool: status event = {}", (void*)event.get());

Expand All @@ -95,7 +95,7 @@ namespace redGrapes
statuses.push_back(status);
}

TaskCtx<TTask>::yield(event);
yield_impl<TTask>(event);

return *status;
}
Expand Down
6 changes: 3 additions & 3 deletions redGrapes/dispatch/thread/DefaultWorker.tpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
*/
#pragma once

#include "redGrapes/TaskCtx.hpp"
#include "redGrapes/dispatch/thread/DefaultWorker.hpp"
#include "redGrapes/dispatch/thread/worker_pool.hpp"
#include "redGrapes/globalSpace.hpp"
#include "redGrapes/util/bitfield.hpp"
#include "redGrapes/util/trace.hpp"

Expand Down Expand Up @@ -58,7 +58,7 @@ namespace redGrapes
assert(task.is_ready());

task.get_pre_event().notify();
TaskCtx<TTask>::current_task = &task;
current_task = &task;

auto event = task();

Expand All @@ -73,7 +73,7 @@ namespace redGrapes
else
task.get_post_event().notify();

TaskCtx<TTask>::current_task = nullptr;
current_task = nullptr;
}

template<typename TTask>
Expand Down
4 changes: 2 additions & 2 deletions redGrapes/dispatch/thread/WorkerThread.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
#include "redGrapes/TaskFreeCtx.hpp"
#include "redGrapes/memory/hwloc_alloc.hpp"

#include <memory>
#include <optional>
#include <thread>

Expand All @@ -26,7 +25,8 @@ namespace redGrapes::dispatch::thread
Worker worker;

template<typename... Args>
WorkerThread(hwloc_obj_t const obj, Args&&... args) : obj{obj}, worker{std::forward<Args>(args)...}
WorkerThread(hwloc_obj_t const obj, Args&&... args) : obj{obj}
, worker{std::forward<Args>(args)...}
{
}

Expand Down
Loading
Loading