Skip to content

Commit 5049a37

Browse files
authored
add launching dummy kernels in cuda examples (#65)
1 parent 86d7c64 commit 5049a37

13 files changed

Lines changed: 58 additions & 9 deletions

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ endif()
109109
option(BUILD_CUDA "Build with CUDA support" OFF)
110110
if(BUILD_CUDA)
111111
find_package(CUDAToolkit REQUIRED)
112+
enable_language(CUDA)
112113
endif()
113114

114115
## targets

examples/CMakeLists.txt

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -70,26 +70,27 @@ if(BUILD_CAPY)
7070
endif()
7171

7272
if(BUILD_CUDA AND BUILD_TBB)
73+
add_library(nanospin nanospin.cu)
7374
add_executable(alien_reco alien_reco.cpp)
74-
target_link_libraries(alien_reco PRIVATE CoroutineTests CUDA::cudart TBB::tbb)
75+
target_link_libraries(alien_reco PRIVATE CoroutineTests CUDA::cudart TBB::tbb nanospin)
7576
add_executable(alien_delegate alien_delegate.cpp)
76-
target_link_libraries(alien_delegate PRIVATE CoroutineTests CUDA::cudart TBB::tbb)
77+
target_link_libraries(alien_delegate PRIVATE CoroutineTests CUDA::cudart TBB::tbb nanospin)
7778
add_executable(alien_event_poll alien_event_poll.cpp)
78-
target_link_libraries(alien_event_poll PRIVATE CoroutineTests CUDA::cudart TBB::tbb)
79+
target_link_libraries(alien_event_poll PRIVATE CoroutineTests CUDA::cudart TBB::tbb nanospin)
7980
if(BUILD_STDEXEC)
8081
add_executable(exec_reco_stdexec exec_reco.cpp)
81-
target_link_libraries(exec_reco_stdexec PRIVATE CoroutineTests CUDA::cudart TBB::tbb STDEXEC::stdexec)
82+
target_link_libraries(exec_reco_stdexec PRIVATE CoroutineTests CUDA::cudart TBB::tbb STDEXEC::stdexec nanospin)
8283
add_executable(exec_delegate_stdexec exec_delegate.cpp)
83-
target_link_libraries(exec_delegate_stdexec PRIVATE CoroutineTests CUDA::cudart TBB::tbb STDEXEC::stdexec)
84+
target_link_libraries(exec_delegate_stdexec PRIVATE CoroutineTests CUDA::cudart TBB::tbb STDEXEC::stdexec nanospin)
8485
add_executable(exec_event_poll_stdexec exec_event_poll.cpp)
85-
target_link_libraries(exec_event_poll_stdexec PRIVATE CoroutineTests CUDA::cudart TBB::tbb STDEXEC::stdexec)
86+
target_link_libraries(exec_event_poll_stdexec PRIVATE CoroutineTests CUDA::cudart TBB::tbb STDEXEC::stdexec nanospin)
8687
endif()
8788
if(BUILD_CAPY)
8889
add_executable(capy_reco capy_reco.cpp)
89-
target_link_libraries(capy_reco PRIVATE CoroutineTests CUDA::cudart TBB::tbb Boost::capy)
90+
target_link_libraries(capy_reco PRIVATE CoroutineTests CUDA::cudart TBB::tbb Boost::capy nanospin)
9091
add_executable(capy_delegate capy_delegate.cpp)
91-
target_link_libraries(capy_delegate PRIVATE CoroutineTests CUDA::cudart TBB::tbb Boost::capy)
92+
target_link_libraries(capy_delegate PRIVATE CoroutineTests CUDA::cudart TBB::tbb Boost::capy nanospin)
9293
add_executable(capy_event_poll capy_event_poll.cpp)
93-
target_link_libraries(capy_event_poll PRIVATE CoroutineTests CUDA::cudart TBB::tbb Boost::capy)
94+
target_link_libraries(capy_event_poll PRIVATE CoroutineTests CUDA::cudart TBB::tbb Boost::capy nanospin)
9495
endif()
9596
endif()

examples/alien_delegate.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "CoroutineTests/threadpool.hpp"
1717
#include "alien_stream_await.hpp" // StreamAwaitable
1818
#include "logging_utils.hpp" // log, format_name
19+
#include "nanospin.hpp" // launch_nanospin
1920

2021
#define ERROR_CHECK_CUDA(EXP) \
2122
do { \
@@ -88,6 +89,7 @@ subtool::Task<DeviceBuffer<int>> clusterization(
8889
nClusters * sizeof(int), stream));
8990
ERROR_CHECK_CUDA(cudaMemsetAsync(
9091
d_clusters, 1, nClusters / 2 * sizeof(int), stream));
92+
launch_nanospin(1'000'000, stream);
9193
}));
9294

9395
co_return DeviceBuffer<int>{d_clusters,
@@ -138,6 +140,7 @@ subtool::Task<DeviceBuffer<int>> seeding(
138140
cudaMemsetAsync(d_seeds, 0, nSeeds * sizeof(int), stream));
139141
ERROR_CHECK_CUDA(
140142
cudaMemsetAsync(d_seeds, 1, nSeeds / 2 * sizeof(int), stream));
143+
launch_nanospin(1'000'000, stream);
141144
}));
142145

143146
co_return DeviceBuffer<int>{d_seeds, static_cast<std::size_t>(nSeeds)};

examples/alien_event_poll.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "CoroutineTests/alien/tool.hpp"
1717
#include "CoroutineTests/threadpool.hpp"
1818
#include "logging_utils.hpp" // log, format_name
19+
#include "nanospin.hpp" // launch_nanospin
1920

2021
#define ERROR_CHECK_CUDA(EXP) \
2122
do { \
@@ -109,6 +110,7 @@ subtool::Task<DeviceBuffer<int>> clusterization(
109110
nClusters * sizeof(int), stream));
110111
ERROR_CHECK_CUDA(cudaMemsetAsync(
111112
d_clusters, 1, nClusters / 2 * sizeof(int), stream));
113+
launch_nanospin(1'000'000, stream);
112114
}));
113115

114116
co_return DeviceBuffer<int>{d_clusters,
@@ -160,6 +162,7 @@ subtool::Task<DeviceBuffer<int>> seeding(
160162
cudaMemsetAsync(d_seeds, 0, nSeeds * sizeof(int), stream));
161163
ERROR_CHECK_CUDA(
162164
cudaMemsetAsync(d_seeds, 1, nSeeds / 2 * sizeof(int), stream));
165+
launch_nanospin(1'000'000, stream);
163166
}));
164167

165168
co_return DeviceBuffer<int>{d_seeds, static_cast<std::size_t>(nSeeds)};

examples/alien_reco.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include "CoroutineTests/alien/tool.hpp"
1111
#include "alien_stream_await.hpp" // StreamAwaitable
1212
#include "logging_utils.hpp" // log, format_name
13+
#include "nanospin.hpp" // launch_nanospin
1314

1415
#define ERROR_CHECK_CUDA(EXP) \
1516
do { \
@@ -64,6 +65,7 @@ subtool::Task<DeviceBuffer<int>> clusterization(DeviceBuffer<int> cells,
6465
cudaMemsetAsync(d_clusters, 0, nClusters * sizeof(int), stream));
6566
ERROR_CHECK_CUDA(
6667
cudaMemsetAsync(d_clusters, 1, nClusters / 2 * sizeof(int), stream));
68+
launch_nanospin(1'000'000, stream);
6769

6870
co_return DeviceBuffer<int>{d_clusters,
6971
static_cast<std::size_t>(nClusters)};
@@ -103,6 +105,7 @@ subtool::Task<DeviceBuffer<int>> seeding(DeviceBuffer<int> clusters,
103105
ERROR_CHECK_CUDA(cudaMemsetAsync(d_seeds, 0, nSeeds * sizeof(int), stream));
104106
ERROR_CHECK_CUDA(
105107
cudaMemsetAsync(d_seeds, 1, nSeeds / 2 * sizeof(int), stream));
108+
launch_nanospin(1'000'000, stream);
106109

107110
co_return DeviceBuffer<int>{d_seeds, static_cast<std::size_t>(nSeeds)};
108111
}

examples/capy_delegate.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "capy_stream_await.hpp" // StreamIoAwaitable
1313
#include "capy_task_arena_executor.hpp" // TaskArenaExecutor
1414
#include "logging_utils.hpp" // log, format_name
15+
#include "nanospin.hpp" // launch_nanospin
1516
#include "statuscode.hpp" // StatusCodeImpl
1617

1718
namespace tools {
@@ -84,6 +85,7 @@ boost::capy::task<DeviceBuffer<int>> clusterization(
8485
cudaMemsetAsync(d_clusters, 0, nClusters * sizeof(int), stream));
8586
ERROR_CHECK_CUDA(cudaMemsetAsync(d_clusters, 1,
8687
nClusters / 2 * sizeof(int), stream));
88+
launch_nanospin(1'000'000, stream);
8789
}));
8890

8991
co_return DeviceBuffer<int>{d_clusters,
@@ -131,6 +133,7 @@ boost::capy::task<DeviceBuffer<int>> seeding(
131133
cudaMemsetAsync(d_seeds, 0, nSeeds * sizeof(int), stream));
132134
ERROR_CHECK_CUDA(
133135
cudaMemsetAsync(d_seeds, 1, nSeeds / 2 * sizeof(int), stream));
136+
launch_nanospin(1'000'000, stream);
134137
}));
135138

136139
co_return DeviceBuffer<int>{d_seeds, static_cast<std::size_t>(nSeeds)};

examples/capy_event_poll.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
#include "capy_task_arena_executor.hpp" // TaskArenaExecutor
1313
#include "logging_utils.hpp" // log, format_name
14+
#include "nanospin.hpp" // launch_nanospin
1415
#include "statuscode.hpp" // StatusCodeImpl
1516

1617
namespace tools {
@@ -105,6 +106,7 @@ boost::capy::task<DeviceBuffer<int>> clusterization(
105106
cudaMemsetAsync(d_clusters, 0, nClusters * sizeof(int), stream));
106107
ERROR_CHECK_CUDA(cudaMemsetAsync(d_clusters, 1,
107108
nClusters / 2 * sizeof(int), stream));
109+
launch_nanospin(1'000'000, stream);
108110
}));
109111

110112
co_return DeviceBuffer<int>{d_clusters,
@@ -154,6 +156,7 @@ boost::capy::task<DeviceBuffer<int>> seeding(
154156
cudaMemsetAsync(d_seeds, 0, nSeeds * sizeof(int), stream));
155157
ERROR_CHECK_CUDA(
156158
cudaMemsetAsync(d_seeds, 1, nSeeds / 2 * sizeof(int), stream));
159+
launch_nanospin(1'000'000, stream);
157160
}));
158161

159162
co_return DeviceBuffer<int>{d_seeds, static_cast<std::size_t>(nSeeds)};

examples/capy_reco.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include "capy_stream_await.hpp" // StreamIoAwaitable
1111
#include "capy_task_arena_executor.hpp" // TaskArenaExecutor
1212
#include "logging_utils.hpp" // log, format_name
13+
#include "nanospin.hpp" // launch_nanospin
1314
#include "statuscode.hpp" // StatusCodeImpl
1415

1516
namespace tools {
@@ -70,6 +71,7 @@ boost::capy::task<DeviceBuffer<int>> clusterization(DeviceBuffer<int> cells,
7071
cudaMemsetAsync(d_clusters, 0, nClusters * sizeof(int), stream));
7172
ERROR_CHECK_CUDA(
7273
cudaMemsetAsync(d_clusters, 1, nClusters / 2 * sizeof(int), stream));
74+
launch_nanospin(1'000'000, stream);
7375

7476
co_return DeviceBuffer<int>{d_clusters,
7577
static_cast<std::size_t>(nClusters)};
@@ -109,6 +111,7 @@ boost::capy::task<DeviceBuffer<int>> seeding(DeviceBuffer<int> clusters,
109111
ERROR_CHECK_CUDA(cudaMemsetAsync(d_seeds, 0, nSeeds * sizeof(int), stream));
110112
ERROR_CHECK_CUDA(
111113
cudaMemsetAsync(d_seeds, 1, nSeeds / 2 * sizeof(int), stream));
114+
launch_nanospin(1'000'000, stream);
112115

113116
co_return DeviceBuffer<int>{d_seeds, static_cast<std::size_t>(nSeeds)};
114117
}

examples/exec_delegate.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "exec_stream_await_sender.hpp" // stream_await_sender
1212
#include "exec_task_arena_scheduler.hpp" // TaskArenaScheduler
1313
#include "logging_utils.hpp" // log, format_name
14+
#include "nanospin.hpp" // launch_nanospin
1415
#include "statuscode.hpp" // StatusCodeImpl
1516

1617
namespace tools {
@@ -83,6 +84,7 @@ exec::task<DeviceBuffer<int>> clusterization(
8384
nClusters * sizeof(int), stream));
8485
ERROR_CHECK_CUDA(cudaMemsetAsync(
8586
d_clusters, 1, nClusters / 2 * sizeof(int), stream));
87+
launch_nanospin(1'000'000, stream);
8688
});
8789
co_await stdexec::on(delegation_ctx.get_scheduler(),
8890
std::move(allocate_clusters));
@@ -137,6 +139,7 @@ exec::task<DeviceBuffer<int>> seeding(
137139
cudaMemsetAsync(d_seeds, 0, nSeeds * sizeof(int), stream));
138140
ERROR_CHECK_CUDA(
139141
cudaMemsetAsync(d_seeds, 1, nSeeds / 2 * sizeof(int), stream));
142+
launch_nanospin(1'000'000, stream);
140143
});
141144
co_await stdexec::on(delegation_ctx.get_scheduler(),
142145
std::move(allocate_seeds));

examples/exec_event_poll.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
#include "exec_task_arena_scheduler.hpp" // TaskArenaScheduler
1414
#include "logging_utils.hpp" // log, format_name
15+
#include "nanospin.hpp" // launch_nanospin
1516
#include "statuscode.hpp" // StatusCodeImpl
1617

1718
namespace tools {
@@ -107,6 +108,7 @@ exec::task<DeviceBuffer<int>> clusterization(
107108
nClusters * sizeof(int), stream));
108109
ERROR_CHECK_CUDA(cudaMemsetAsync(
109110
d_clusters, 1, nClusters / 2 * sizeof(int), stream));
111+
launch_nanospin(1'000'000, stream);
110112
});
111113
co_await stdexec::on(delegation_ctx.get_scheduler(),
112114
std::move(allocate_clusters));
@@ -162,6 +164,7 @@ exec::task<DeviceBuffer<int>> seeding(
162164
cudaMemsetAsync(d_seeds, 0, nSeeds * sizeof(int), stream));
163165
ERROR_CHECK_CUDA(
164166
cudaMemsetAsync(d_seeds, 1, nSeeds / 2 * sizeof(int), stream));
167+
launch_nanospin(1'000'000, stream);
165168
});
166169
co_await stdexec::on(delegation_ctx.get_scheduler(),
167170
std::move(allocate_seeds));

0 commit comments

Comments
 (0)