Skip to content

Commit

Permalink
replaced devsamp/main by devsamp/helloworld + added README files for …
Browse files Browse the repository at this point in the history
…each devsamp example
  • Loading branch information
evaleev committed Jun 9, 2024
1 parent e7ba5a6 commit 73c9949
Show file tree
Hide file tree
Showing 13 changed files with 73 additions and 137 deletions.
7 changes: 5 additions & 2 deletions .github/workflows/cmake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,13 @@ jobs:
working-directory: ${{github.workspace}}/build
shell: bash
run: |
cmake -S $GITHUB_WORKSPACE/doc/dox/dev/devsamp/main -B test_install_devsamp_main -DCMAKE_PREFIX_PATH=${{github.workspace}}/install || (cat test_install_devsamp_main/CMakeFiles/CMakeOutput.log && cat test_install_devsamp_main/CMakeFiles/CMakeError.log)
cmake --build test_install_devsamp_main
cmake -S $GITHUB_WORKSPACE/doc/dox/dev/devsamp/helloworld -B test_install_devsamp_helloworld -DCMAKE_PREFIX_PATH=${{github.workspace}}/install || (cat test_install_devsamp_helloworld/CMakeFiles/CMakeOutput.log && cat test_install_devsamp_helloworld/CMakeFiles/CMakeError.log)
cmake --build test_install_devsamp_helloworld
test_install_devsamp_helloworld/helloworld-parsec
test_install_devsamp_helloworld/helloworld-mad
cmake -S $GITHUB_WORKSPACE/doc/dox/dev/devsamp/fibonacci -B test_install_devsamp_fibonacci -DCMAKE_PREFIX_PATH=${{github.workspace}}/install || (cat test_install_devsamp_fibonacci/CMakeFiles/CMakeOutput.log && cat test_install_devsamp_fibonacci/CMakeFiles/CMakeError.log)
cmake --build test_install_devsamp_fibonacci
test_install_devsamp_fibonacci/fibonacci-parsec
cmake -E make_directory test_install_userexamples
cat > test_install_userexamples/CMakeLists.txt <<EOF
cmake_minimum_required(VERSION 3.14)
Expand Down
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,17 +55,19 @@ if (NOT TARGET ttg-parsec) # else build from source
FetchContent_MakeAvailable( ttg )
endif()
add_executable(hw-parsec helloworld.cpp)
add_executable(helloworld-parsec helloworld.cpp)
target_link_libraries(hw-parsec PRIVATE ttg-parsec)
target_compile_definitions(hw-parsec PRIVATE TTG_USE_PARSEC=1)
```

Configure + build:

```sh
> cmake -S . -B build && cmake --build build --target hw-parsec
> cmake -S . -B build && cmake --build build --target helloworld-parsec
```

The complete example, including the CMake build harness using a slightly easier way to build the executable (using `add_ttg_executable` CMake macro), can be found in [dox examples](https://github.com/TESSEorg/ttg/tree/master/doc/dox/dev/devsamp/helloworld).

## "Hello, World!" Walkthrough

Although it does not involve any useful flow of computation and/or data, the above "Hello, World!" TTG program introduces several key TTG concepts and illustrates what you need to do to write a complete TTG program. So let's walk through it.
Expand Down Expand Up @@ -95,7 +97,7 @@ Every TTG program must:
- make TTG executable and kickstart the execution by sending a control or data message to the TTG,
- shut down the runtime

Let's go over each of these steps using the "Hello, World!" example.
Let's go over each of these steps using the "Hello, World!" example. The complete example, including the CMake build harness, can be found in [dox examples](https://github.com/TESSEorg/ttg/tree/master/doc/dox/dev/devsamp/fibonacci).

### Select the TTG Backend

Expand Down Expand Up @@ -243,6 +245,7 @@ $F_{n-1},F_{n-2} \to F_{n}$).
To illustrate the real power of TTG let's tweak the problem slightly: instead of computing first $N$ Fibonacci numbers let's find the largest Fibonacci number smaller than some $N$. The key difference in the latter case is that, unlike the former, the number of tasks is NOT known a priori; furthermore, to make a decision whether we need to compute next Fibonacci number we must examine the value returned by the previous task. This is an example of data-dependent tasking, where the decision which (if any) task to execute next depends on the values produced by previous tasks. The ability to compose regular as well as data-dependent task graphs is a distinguishing strength of TTG.
To make things even more interesting, we will demonstrate how to implement such program both for execution on CPUs as well as on accelerators (GPUs).
The complete examples, including the CMake build harness, can be found in [dox examples](https://github.com/TESSEorg/ttg/tree/master/doc/dox/dev/devsamp/fibonacci).
### The CPU Version
Expand Down Expand Up @@ -450,8 +453,6 @@ Here's the CUDA version of the device kernel and its host-side wrapper; ROCm and

`cu_next_value` is the device kernel that evaluates $F_{n+1}$ from $F_{n}$ and $F_{n-1}$. `next_value` is a host function that launches `cu_next_value`; this is the function called in the `fib` task.

The complete example, including the CMake build harness, can be found in [dox examples](https://github.com/TESSEorg/ttg/tree/master/doc/dox/dev/devsamp/fibonacci).

## Debugging TTG Programs

### TTG Visualization
Expand Down
7 changes: 6 additions & 1 deletion doc/dox/dev/devsamp/fibonacci/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ cmake_minimum_required(VERSION 3.14)
project(ttg-devsample-fibonacci)

find_package(ttg REQUIRED)
if (NOT TARGET ttg-parsec) # else build from source
include(FetchContent)
FetchContent_Declare(ttg GIT_REPOSITORY https://github.com/TESSEorg/ttg.git)
FetchContent_MakeAvailable( ttg )
endif()

add_ttg_executable(fibonacci fibonacci.cc NOT_EXCLUDE_FROM_ALL)
# Fib device test
Expand All @@ -11,4 +16,4 @@ if (TTG_HAVE_CUDA)
fibonacci_cuda_kernel.h
fibonacci_cuda_kernel.cu
LINK_LIBRARIES std::coroutine RUNTIMES "parsec" NOT_EXCLUDE_FROM_ALL)
endif()
endif()
17 changes: 17 additions & 0 deletions doc/dox/dev/devsamp/fibonacci/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Largest Fibonacci number

This directory contains TTG programs computing the largest Fibonacci number smaller than $N$:

- CPU version: `fibonacci.cc`
- Device version: `fibonacci_device.cc`
- CUDA kernel: `fibonacci_cuda_kernel.{cu,h}`

## Build

After TTG has been installed to `/path/to/ttg`, do this:

- configure: `cmake -S . -B build -DCMAKE_PREFIX_PATH="/path/to/ttg"`
- build:
- CPU version: `cmake --build build --target fibonacci`
- CUDA version (TTG must have been configured with CUDA support): `cmake --build build --target fibonacci_cuda`
- run: `./build/fibonacci N` or `./build/fibonacci_cuda N`
11 changes: 11 additions & 0 deletions doc/dox/dev/devsamp/helloworld/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
cmake_minimum_required(VERSION 3.14)
project(ttg-devsample-helloworld)

find_package(ttg REQUIRED)
if (NOT TARGET ttg-parsec) # else build from source
include(FetchContent)
FetchContent_Declare(ttg GIT_REPOSITORY https://github.com/TESSEorg/ttg.git)
FetchContent_MakeAvailable( ttg )
endif()

add_ttg_executable(helloworld helloworld.cpp NOT_EXCLUDE_FROM_ALL)
11 changes: 11 additions & 0 deletions doc/dox/dev/devsamp/helloworld/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# TTG "Hello World"

This directory contains the TTG "Hello World" program

## Build

After TTG has been installed to `/path/to/ttg`, do this:

- configure: `cmake -S . -B build -DCMAKE_PREFIX_PATH="/path/to/ttg"`
- build: `cmake --build build`
- run: `./build/helloworld-parsec` or `./build/helloworld-mad`
17 changes: 17 additions & 0 deletions doc/dox/dev/devsamp/helloworld/helloworld.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#include <ttg.h>

using namespace ttg;

int main(int argc, char *argv[]) {
ttg::initialize(argc, argv);

auto tt = ttg::make_tt([]() { std::cout << "Hello, World!"; });

ttg::make_graph_executable(tt);
ttg::execute();
if (ttg::get_default_world().rank() == 0) tt->invoke();
ttg::fence();

ttg::finalize();
return 0;
}
6 changes: 0 additions & 6 deletions doc/dox/dev/devsamp/main/CMakeLists.txt

This file was deleted.

8 changes: 0 additions & 8 deletions doc/dox/dev/devsamp/main/test.cpp

This file was deleted.

8 changes: 0 additions & 8 deletions tests/unit/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,6 @@ add_ttg_executable(serialization serialization.cc unit_main.cpp
add_ttg_executable(serialization_boost serialization_boost.cc
LINK_LIBRARIES ttg-serialization-boost RUNTIMES "parsec")

# Fib device test
if (TTG_HAVE_CUDA)
add_ttg_executable(fibonacci_device fibonacci_device.cc
fibonacci_cuda_kernel.h
fibonacci_cuda_kernel.cu
LINK_LIBRARIES std::coroutine RUNTIMES "parsec")
endif()

# TODO: convert into unit test
#if (TARGET MADworld)
#add_executable(splitmd_serialization splitmd_serialization.cc unit_main.cpp)
Expand Down
15 changes: 0 additions & 15 deletions tests/unit/fibonacci_cuda_kernel.cu

This file was deleted.

4 changes: 0 additions & 4 deletions tests/unit/fibonacci_cuda_kernel.h

This file was deleted.

88 changes: 0 additions & 88 deletions tests/unit/fibonacci_device.cc

This file was deleted.

0 comments on commit 73c9949

Please sign in to comment.