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 22, 2024
1 parent 9f4af5f commit bc0926d
Show file tree
Hide file tree
Showing 90 changed files with 2,625 additions and 2,266 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ DartConfiguration.tcl
Testing

build/
.build/
.cache/

*.swp
*.png
Expand Down
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
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")

if(redGrapes_BUILD_EXAMPLES)
add_subdirectory("examples/")
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
30 changes: 15 additions & 15 deletions examples/1_resources.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,31 @@
*/

#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;
using TTask = redGrapes::Task<>;

auto rg = redGrapes::init(1);
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;
}
9 changes: 2 additions & 7 deletions examples/2_functors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@
*/

#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;
}
17 changes: 8 additions & 9 deletions examples/3_functors_with_resources.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
71 changes: 37 additions & 34 deletions examples/4_refinements.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/

#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(
[&]
{
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(
[&]
{
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;
}
18 changes: 8 additions & 10 deletions examples/5_access_demotion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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(
rg.emplace_task(
[](auto a)
{
std::cout << "f2 reads A" << std::endl;
std::cout << "f2 done" << std::endl;
},
a.read());

rg::finalize();

return 0;
}
40 changes: 18 additions & 22 deletions examples/6_resource_scope.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,35 +7,31 @@

#include <redGrapes/redGrapes.hpp>
#include <redGrapes/resource/ioresource.hpp>
#include <redGrapes/task/property/inherit.hpp>
#include <redGrapes/task/property/resource.hpp>

namespace rg = redGrapes;

int main()
{
rg::init(1);
rg::IOResource<int> a; // scope-level=0
auto rg = rg::init(1);
auto a = rg.createIOResource<int>(); // scope-level=0

rg::emplace_task(
[](auto a)
{
std::cout << "scope = " << rg::scope_depth() << std::endl;
rg::IOResource<int> b; // scope-level=1
rg.emplace_task(
[&](auto a)
{
std::cout << "scope = " << rg.scope_depth() << std::endl;
auto b = rg.createIOResource<int>(); // scope-level=1

rg::emplace_task(
[](auto b)
{
*b = 1;
std::cout << "scope = " << rg::scope_depth() << std::endl;
},
b.write())
.get();
rg.emplace_task(
[&](auto b)
{
*b = 1;
std::cout << "scope = " << rg.scope_depth() << std::endl;
},
b.write())
.get();

std::cout << "scope = " << rg::scope_depth() << std::endl;
},
a.read())
std::cout << "scope = " << rg.scope_depth() << std::endl;
},
a.read())
.enable_stack_switching();

rg::finalize();
}
Loading

0 comments on commit bc0926d

Please sign in to comment.