Skip to content

Commit

Permalink
Templated Task Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
ikbuibui committed Mar 26, 2024
1 parent 9f4af5f commit 43e6370
Show file tree
Hide file tree
Showing 92 changed files with 2,978 additions and 2,690 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Expand Up @@ -12,6 +12,8 @@ DartConfiguration.tcl
Testing

build/
.build/
.cache/

*.swp
*.png
Expand Down
1 change: 1 addition & 0 deletions CMakeLists.txt
Expand Up @@ -7,6 +7,7 @@ project(redGrapesExamplesAndTests VERSION 0.1.0)
# Examples & Tests
########################################################
option(redGrapes_BUILD_EXAMPLES "Build the examples" ON)
option(BUILD_TESTING "Build the tests" OFF)

if(redGrapes_BUILD_EXAMPLES)
add_subdirectory("examples/")
Expand Down
8 changes: 4 additions & 4 deletions README.md
Expand Up @@ -2,13 +2,13 @@
**Re**source-based, **D**eclarative task-**Gra**phs for **P**arallel, **E**vent-driven **S**cheduling

[![GitHub commits](https://img.shields.io/github/commits-since/ComputationalRadiationPhysics/redGrapes/v0.1.0/dev.svg)](https://GitHub.com/ComputationalRadiationPhysics/redGrapes/commit/)
[![Language](https://img.shields.io/badge/language-C%2B%2B14-orange)](https://isocpp.org/)
[![Language](https://img.shields.io/badge/language-C%2B%2B20-orange)](https://isocpp.org/)
[![License](https://img.shields.io/badge/license-MPL--2.0-blue.svg)](https://www.mozilla.org/en-US/MPL/2.0/)
[![Documentation Status](https://readthedocs.org/projects/redgrapes/badge/?version=dev)](https://redgrapes.readthedocs.io/en/dev/?badge=dev)

<hr>

RedGrapes is a C++17 framework for declaratively creating and scheduling task-graphs, based on a high-level resource description.
RedGrapes is a C++20 framework for declaratively creating and scheduling task-graphs, based on a high-level resource description.

### Motivation

Expand Down Expand Up @@ -103,7 +103,7 @@ However since we want to achieve **declarative task dependencies**, for which th
**compile time checked memory access**: The automatic creation of a task graph is often done via annotations, e.g., a pragma in OpenMP, but that does not guarantee the correctness of the access specifications. RedGrapes leverages the type system to write relatively safe code in that regard.
**native C++**: PaRSEC has a complicated toolchain using additional compilers, OpenMP makes use of pragmas that require compiler support. RedGrapes only requires the C++14 standard.
**native C++**: PaRSEC has a complicated toolchain using additional compilers, OpenMP makes use of pragmas that require compiler support. RedGrapes only requires the C++20 standard.
**typesafe**: Some libraries like Legion or StarPU use an untyped ``argc``/``argv`` interface to pass parameters to tasks, which is error-prone. Both libraries in general also require a lot of C-style boilerplate.
Expand Down Expand Up @@ -154,7 +154,7 @@ Its conceptual design is based on a [whitepaper by A. Huebl, R. Widera, and A. M
### Dependencies
RedGrapes requires a compiler supporting the C++17 standard.
RedGrapes requires a compiler supporting the C++20 standard.
RedGrapes further depends on the following libraries:
* [ConcurrentQueue](https://github.com/cameron314/concurrentqueue) by [Cameron Desrochers](https://moodycamel.com)
Expand Down
6 changes: 3 additions & 3 deletions docs/source/install.rst
Expand Up @@ -26,12 +26,12 @@ In order to build the examples and tests, do the typical cmake procedure:

Enable Tests with
::
cmake .. BUILD_TESTING=ON
cmake .. -DBUILD_TESTING=ON
Set Loglevel
::
cmake .. CMAKE_CXX_FLAGS="-DSPDLOG_ACTIVE_LEVEL=SPDLOG_LEVEL_OFF"
cmake .. -DCMAKE_CXX_FLAGS="-DSPDLOG_ACTIVE_LEVEL=SPDLOG_LEVEL_OFF"

Enable Tracing with Perfetto
::
cmake .. redGrapes_ENABLE_PERFETTO=ON
cmake .. -DredGrapes_ENABLE_PERFETTO=ON
32 changes: 16 additions & 16 deletions examples/1_resources.cpp
@@ -1,36 +1,36 @@
/* Copyright 2019 Michael Sippel
/* Copyright 2019-2024 Michael Sippel, Tapish Narwal
*
* This Source Code Form is subject to the terms of the Mozilla Public
* 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/.
*/

#include <redGrapes/redGrapes.hpp>
#include <redGrapes/resource/fieldresource.hpp>
#include <redGrapes/resource/ioresource.hpp>
#include <redGrapes/resource/resource_user.hpp>

#include <iostream>

int main(int, char*[])
{
redGrapes::init(1);
redGrapes::FieldResource<std::vector<int>> a;
redGrapes::IOResource<int> b;
redGrapes::IOResource<int> c;
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 user1(
redGrapes::ResourceUser<TTask> user1(
{a.read(), // complete resource
a.write().area({0}, {10}), // write only indices 0 to 10
b.write()});

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

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

std::cout << "is_serial(user1,user1) = " << redGrapes::ResourceUser::is_serial(user1, user1) << std::endl;
std::cout << "is_serial(user1,user2) = " << redGrapes::ResourceUser::is_serial(user1, user2) << std::endl;
std::cout << "is_serial(user1,user3) = " << redGrapes::ResourceUser::is_serial(user1, user3) << std::endl;
std::cout << "is_serial(user2,user3) = " << redGrapes::ResourceUser::is_serial(user2, user3) << std::endl;
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;

redGrapes::finalize();
return 0;
}
11 changes: 3 additions & 8 deletions examples/2_functors.cpp
@@ -1,15 +1,11 @@
/* Copyright 2019 Michael Sippel
/* Copyright 2019-2024 Michael Sippel, Tapish Narwal
*
* This Source Code Form is subject to the terms of the Mozilla Public
* 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/.
*/

#include <redGrapes/redGrapes.hpp>
#include <redGrapes/task/property/id.hpp>
#include <redGrapes/task/property/resource.hpp>

#include <iostream>

int square(int x)
{
Expand All @@ -19,10 +15,9 @@ int square(int x)
int main()
{
spdlog::set_level(spdlog::level::trace);
redGrapes::init(1);
auto rg = redGrapes::init(1);

fmt::print("square(2) = {}\n", redGrapes::emplace_task(square, 2).get());
fmt::print("square(2) = {}\n", rg.emplace_task(square, 2).get());

redGrapes::finalize();
return 0;
}
19 changes: 9 additions & 10 deletions examples/3_functors_with_resources.cpp
@@ -1,4 +1,4 @@
/* Copyright 2019 Michael Sippel
/* Copyright 2019-2024 Michael Sippel, Tapish Narwal
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
Expand All @@ -15,13 +15,14 @@
int main(void)
{
spdlog::set_level(spdlog::level::trace);
redGrapes::init();
auto rg = redGrapes::init();

redGrapes::IOResource<int> a, b;
auto a = rg.createIOResource<int>();
auto b = rg.createIOResource<int>();

for(int i = 0; i < 1; ++i)
{
redGrapes::emplace_task(
rg.emplace_task(
[](auto a)
{
std::cout << "Write to A" << std::endl;
Expand All @@ -31,25 +32,25 @@ int main(void)
},
a.write());

redGrapes::emplace_task(
rg.emplace_task(
[](auto a)
{
std::cout << "Read A: " << *a << std::endl;
std::this_thread::sleep_for(std::chrono::seconds(1));
},
a.read());

redGrapes::emplace_task(
rg.emplace_task(
[](auto b)
{
std::cout << "Write to B" << std::endl;
std::this_thread::sleep_for(std::chrono::seconds(2));
std::this_thread::sleep_for(std::chrono::seconds(3));
*b = 7;
std::cout << "Write B done" << std::endl;
},
b.write());

redGrapes::emplace_task(
rg.emplace_task(
[](auto a, auto b)
{
std::cout << "Read A & B: " << *a << ", " << *b << std::endl;
Expand All @@ -59,7 +60,5 @@ int main(void)
b.read());
}

redGrapes::finalize();

return 0;
}
73 changes: 38 additions & 35 deletions examples/4_refinements.cpp
@@ -1,11 +1,12 @@
/* Copyright 2019 Michael Sippel
/* Copyright 2019-2024 Michael Sippel, Tapish Narwal
*
* This Source Code Form is subject to the terms of the Mozilla Public
* 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/.
*/

#include <redGrapes/redGrapes.hpp>
#include <redGrapes/task/property/label.hpp>

#include <chrono>
#include <iostream>
Expand All @@ -16,43 +17,45 @@ int main(int, char*[])
spdlog::set_level(spdlog::level::trace);
spdlog::set_pattern("[thread %t] %^[%l]%$ %v");

redGrapes::init(4);

redGrapes::emplace_task(
[]
{
std::cout << "f1"
<< "..." << std::endl;

int i = 0;
for(auto t : redGrapes::backtrace())
fmt::print("refinement 1 backtrace [{}]: {}\n", i++, t.get().label);

redGrapes::emplace_task(
[]
{
fmt::print("Refinement 1\n");
std::this_thread::sleep_for(std::chrono::seconds(1));
});

SPDLOG_TRACE("EX: create next task task");

redGrapes::emplace_task(
[]
{
fmt::print("Refinement 2\n");
std::this_thread::sleep_for(std::chrono::seconds(1));

int i = 0;
for(auto t : redGrapes::backtrace())
fmt::print("refinement 2 backtrace [{}]: {}\n", i++, (redGrapes::TaskProperties const&) t);
})
.label("Child Task 2");
})
auto rg = redGrapes::init<redGrapes::LabelProperty>(4);

rg.emplace_task(
[&rg]
{
std::cout << "f1"
<< "..." << std::endl;

int i = 0;
for(auto t : rg.backtrace())
fmt::print("refinement 1 backtrace [{}]: {}\n", i++, t.get().label);

rg.emplace_task(
[]
{
fmt::print("Refinement 1\n");
std::this_thread::sleep_for(std::chrono::seconds(1));
});

SPDLOG_TRACE("EX: create next task task");

rg.emplace_task(
[&rg]
{
fmt::print("Refinement 2\n");
std::this_thread::sleep_for(std::chrono::seconds(1));

int i = 0;
for(auto t : rg.backtrace())
fmt::print(
"refinement 2 backtrace [{}]: {}\n",
i++,
(decltype(rg)::RGTask::TaskProperties const&) t); // TODO cleaner way to do this
})
.label("Child Task 2");
})
.label("Parent Task")
.submit();

redGrapes::finalize();

return 0;
}
22 changes: 10 additions & 12 deletions examples/5_access_demotion.cpp
@@ -1,4 +1,4 @@
/* Copyright 2019 Michael Sippel
/* Copyright 2019-2024 Michael Sippel, Tapish Narwal
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
Expand All @@ -7,7 +7,6 @@

#include <redGrapes/redGrapes.hpp>
#include <redGrapes/resource/ioresource.hpp>
#include <redGrapes/scheduler/default_scheduler.hpp>

#include <chrono>
#include <iostream>
Expand All @@ -18,33 +17,32 @@ namespace rg = redGrapes;
int main(int, char*[])
{
spdlog::set_level(spdlog::level::trace);
rg::init();
rg::IOResource<int> a;
auto rg = rg::init();
auto a = rg.createIOResource<int>();

rg::emplace_task(
[](auto a)
rg.emplace_task(
[&](auto a)
{
std::cout << "f1 writes A" << std::endl;
std::this_thread::sleep_for(std::chrono::seconds(1));

std::cout << "f1 now only reads A" << std::endl;
rg::update_properties(
rg::TaskProperties::Patch::Builder().remove_resources({a.write()}).add_resources({a.read()}));
rg.update_properties(decltype(rg)::RGTask::TaskProperties::Patch::Builder()
.remove_resources({a.write()})
.add_resources({a.read()}));
std::this_thread::sleep_for(std::chrono::seconds(1));

std::cout << "f1 done" << std::endl;
},
a.write());

rg::emplace_task(
[](auto a)
rg.emplace_task(
[]([[maybe_unused]] auto a)
{
std::cout << "f2 reads A" << std::endl;
std::cout << "f2 done" << std::endl;
},
a.read());

rg::finalize();

return 0;
}

0 comments on commit 43e6370

Please sign in to comment.