Skip to content

Commit aae08f6

Browse files
committed
add option sciplot to idx_map doc example
- sciplot allows to plot data to svg files
1 parent e0e960b commit aae08f6

File tree

3 files changed

+86
-5
lines changed

3 files changed

+86
-5
lines changed

docs/snippets/idxMap/CMakeLists.txt

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,29 @@
33
# SPDX-License-Identifier: ISC
44
#
55

6-
add_executable(idx_map plot_idx_map.cpp)
7-
target_include_directories(idx_map PRIVATE include)
8-
target_link_libraries(idx_map PRIVATE alpaka::alpaka)
9-
alpaka_finalize(idx_map)
6+
option(alpaka_DOCS_PLOT_DATA "enable plotting data with sciplot (requires gnuplot)" OFF)
7+
8+
set(_TARGET_DOC_IDX_MAP idx_map)
9+
add_executable(${_TARGET_DOC_IDX_MAP} plot_idx_map.cpp)
10+
target_include_directories(${_TARGET_DOC_IDX_MAP} PRIVATE include)
11+
target_link_libraries(${_TARGET_DOC_IDX_MAP} PRIVATE alpaka::alpaka)
12+
13+
if (alpaka_DOCS_PLOT_DATA)
14+
include(FetchContent)
15+
16+
option(SCIPLOT_BUILD_EXAMPLES OFF)
17+
option(SCIPLOT_BUILD_TESTS OFF)
18+
option(SCIPLOT_BUILD_DOCS OFF)
19+
20+
FetchContent_Declare(sciplot_content
21+
GIT_REPOSITORY https://github.com/sciplot/sciplot.git
22+
GIT_TAG master)
23+
24+
FetchContent_MakeAvailable(sciplot_content)
25+
26+
target_include_directories(${_TARGET_DOC_IDX_MAP} PRIVATE ${sciplot_content_SOURCE_DIR})
27+
28+
target_compile_options(${_TARGET_DOC_IDX_MAP} PRIVATE "-DALPAKA_DOC_PLOT_DATA")
29+
endif ()
30+
31+
alpaka_finalize(${_TARGET_DOC_IDX_MAP})
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#pragma once
2+
3+
#include "idx_map_data.hpp"
4+
5+
#include <alpaka/alpaka.hpp>
6+
7+
#include <sciplot/sciplot.hpp>
8+
9+
#include <string>
10+
11+
void drawGraphPNG(alpaka::concepts::IDataSource<AccessData> auto data, std::string const filename)
12+
{
13+
static_assert(data.dim() == 1);
14+
15+
sciplot::Plot2D plot;
16+
plot.xlabel("data ID");
17+
plot.ylabel("processing IDs");
18+
plot.xrange(0.0, static_cast<double>(data.getExtents().product()));
19+
plot.legend().atOutsideTopRight();
20+
21+
sciplot::Vec const x = sciplot::range(0, data.getExtents().product());
22+
23+
sciplot::Vec frame_elem(data.getExtents().product());
24+
sciplot::Vec thread_id(data.getExtents().product());
25+
sciplot::Vec block_id(data.getExtents().product());
26+
27+
for(auto i = 0; i < data.getExtents()[0]; ++i)
28+
{
29+
thread_id[i] = data[i].thread_id.product();
30+
block_id[i] = data[i].block_id.product();
31+
}
32+
33+
auto frame_elem_offset = thread_id.max();
34+
35+
for(auto i = 0; i < data.getExtents()[0]; ++i)
36+
{
37+
frame_elem[i] = data[i].frame_elem.product() + frame_elem_offset + 10.0;
38+
}
39+
40+
plot.drawCurve(x, frame_elem).label("Frame Element");
41+
plot.drawBoxes(x, thread_id).label("Thread Index");
42+
plot.drawBoxes(x, block_id).label("Block Index");
43+
44+
sciplot::Figure fig = {{plot}};
45+
sciplot::Canvas canvas = {{fig}};
46+
47+
constexpr auto scale = 100;
48+
canvas.size(scale * 81, scale * 50);
49+
50+
canvas.save(filename + ".svg");
51+
}

docs/snippets/idxMap/plot_idx_map.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88

99
#include <iostream>
1010

11+
#ifdef ALPAKA_DOC_PLOT_DATA
12+
# include "plot_data.hpp"
13+
#endif
14+
1115
struct Kernel
1216
{
1317
ALPAKA_FN_ACC void operator()(alpaka::onAcc::concepts::Acc auto const& acc, alpaka::concepts::IMdSpan auto out)
@@ -77,11 +81,15 @@ int example(auto const deviceSpec, auto const exec)
7781
alpaka::onHost::memcpy(acc_queue, host_out, acc_out);
7882
alpaka::onHost::wait(acc_queue);
7983

84+
#ifdef ALPAKA_DOC_PLOT_DATA
85+
drawGraphPNG(host_out, alpaka::onHost::getName(exec));
86+
#endif
87+
8088
std::cout << "\n";
8189
return 0;
8290
}
8391

84-
int main(int argc, char** argv)
92+
int main()
8593
{
8694
return alpaka::onHost::executeForEachIfHasDevice(
8795
[=](auto const& backend)

0 commit comments

Comments
 (0)