Skip to content

Commit bd24d74

Browse files
committed
Code
1 parent 77f0793 commit bd24d74

File tree

2 files changed

+164
-0
lines changed

2 files changed

+164
-0
lines changed

02-repo-structure/02-repo-structure.tex

Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,169 @@ \section{How to submit your work}
193193
\end{tikzpicture}
194194
\end{frame}
195195

196+
\section{API of the course's repository}
197+
198+
\begin{frame}[fragile]{Task's prototype}
199+
\lstset{style=CStyle, caption=include/ops\_seq.hpp}
200+
\begin{lstlisting}
201+
class TestTaskSequential : public ppc::core::Task {
202+
public:
203+
explicit TestTaskSequential(std::shared_ptr<ppc::core::TaskData> taskData_) : Task(std::move(taskData_)) {}
204+
bool pre_processing() override;
205+
bool validation() override;
206+
bool run() override;
207+
bool post_processing() override;
208+
209+
private:
210+
int input_{}, res{};
211+
};
212+
\end{lstlisting}
213+
\end{frame}
214+
215+
\begin{frame}[fragile]{Task's source code}
216+
\lstset{style=CStyle, caption=src/ops\_seq.cpp | pre\_processing}
217+
\begin{lstlisting}
218+
bool nesterov_a_test_task_seq::TestTaskSequential::pre_processing() {
219+
internal_order_test();
220+
// Init value for input and output
221+
input_ = reinterpret_cast<int*>(taskData->inputs[0])[0];
222+
res = 0;
223+
return true;
224+
}
225+
\end{lstlisting}
226+
227+
\lstset{style=CStyle, caption=src/ops\_seq.cpp | validation}
228+
\begin{lstlisting}
229+
bool nesterov_a_test_task_seq::TestTaskSequential::validation() {
230+
internal_order_test();
231+
// Check count elements of output
232+
return taskData->inputs_count[0] == 1 && taskData->outputs_count[0] == 1;
233+
}
234+
\end{lstlisting}
235+
\end{frame}
236+
237+
\begin{frame}[fragile]{Task's source code}
238+
\lstset{style=CStyle, caption=src/ops\_seq.cpp | run}
239+
\begin{lstlisting}
240+
bool nesterov_a_test_task_seq::TestTaskSequential::run() {
241+
internal_order_test();
242+
for (int i = 0; i < input_; i++) {
243+
res++;
244+
}
245+
return true;
246+
}
247+
\end{lstlisting}
248+
249+
\lstset{style=CStyle, caption=src/ops\_seq.cpp | post\_processing}
250+
\begin{lstlisting}
251+
bool nesterov_a_test_task_seq::TestTaskSequential::post_processing() {
252+
internal_order_test();
253+
reinterpret_cast<int*>(taskData->outputs[0])[0] = res;
254+
return true;
255+
}
256+
\end{lstlisting}
257+
\end{frame}
258+
259+
\begin{frame}[fragile]{Task's functional tests}
260+
\lstset{style=CStyle, caption=func\_tests/main.cpp}
261+
\begin{lstlisting}
262+
TEST(Sequential, Test_Sum_10) {
263+
const int count = 10;
264+
265+
// Create data
266+
std::vector<int> in(1, count);
267+
std::vector<int> out(1, 0);
268+
269+
// Create TaskData
270+
std::shared_ptr<ppc::core::TaskData> taskDataSeq = std::make_shared<ppc::core::TaskData>();
271+
taskDataSeq->inputs.emplace_back(reinterpret_cast<uint8_t *>(in.data()));
272+
taskDataSeq->inputs_count.emplace_back(in.size());
273+
taskDataSeq->outputs.emplace_back(reinterpret_cast<uint8_t *>(out.data()));
274+
taskDataSeq->outputs_count.emplace_back(out.size());
275+
276+
// Create Task
277+
nesterov_a_test_task_seq::TestTaskSequential testTaskSequential(taskDataSeq);
278+
ASSERT_EQ(testTaskSequential.validation(), true);
279+
testTaskSequential.pre_processing();
280+
testTaskSequential.run();
281+
testTaskSequential.post_processing();
282+
ASSERT_EQ(count, out[0]);
283+
}
284+
\end{lstlisting}
285+
\end{frame}
286+
287+
\begin{frame}[fragile]{TaskData structure}
288+
\lstset{style=CStyle, caption=TaskData}
289+
\begin{lstlisting}
290+
struct TaskData {
291+
std::vector<uint8_t *> inputs;
292+
std::vector<std::uint32_t> inputs_count;
293+
std::vector<uint8_t *> outputs;
294+
std::vector<std::uint32_t> outputs_count;
295+
enum StateOfTesting { FUNC, PERF } state_of_testing;
296+
};
297+
\end{lstlisting}
298+
\lstset{style=CStyle, caption=Functions order}
299+
\begin{lstlisting}
300+
std::vector<std::string> right_functions_order =
301+
{"validation",
302+
"pre_processing",
303+
"run",
304+
"post_processing"};
305+
\end{lstlisting}
306+
\end{frame}
307+
308+
\begin{frame}[fragile]{Task's performance tests - part 1}
309+
\lstset{style=CStyle, caption=perf\_tests/main.cpp}
310+
\begin{lstlisting}
311+
TEST(sequential_example_perf_test, test_pipeline_run) {
312+
const int count = 100;
313+
314+
// Create data
315+
std::vector<int> in(1, count);
316+
std::vector<int> out(1, 0);
317+
318+
// Create TaskData
319+
std::shared_ptr<ppc::core::TaskData> taskDataSeq = std::make_shared<ppc::core::TaskData>();
320+
taskDataSeq->inputs.emplace_back(reinterpret_cast<uint8_t *>(in.data()));
321+
taskDataSeq->inputs_count.emplace_back(in.size());
322+
taskDataSeq->outputs.emplace_back(reinterpret_cast<uint8_t *>(out.data()));
323+
taskDataSeq->outputs_count.emplace_back(out.size());
324+
325+
// Create Task
326+
auto testTaskSequential = std::make_shared<nesterov_a_test_task_seq::TestTaskSequential>(taskDataSeq);
327+
\end{lstlisting}
328+
\end{frame}
329+
330+
\begin{frame}[fragile]{Task's performance tests - part 2}
331+
\lstset{style=CStyle, caption=perf\_tests/main.cpp}
332+
\begin{lstlisting}
333+
// Create Perf attributes
334+
auto perfAttr = std::make_shared<ppc::core::PerfAttr>();
335+
perfAttr->num_running = 10;
336+
const auto t0 = std::chrono::high_resolution_clock::now();
337+
perfAttr->current_timer = [&] {
338+
auto current_time_point = std::chrono::high_resolution_clock::now();
339+
auto duration = std::chrono::duration_cast<std::chrono::nanoseconds>(current_time_point - t0).count();
340+
return static_cast<double>(duration) * 1e-9;
341+
};
342+
343+
// Create and init perf results
344+
auto perfResults = std::make_shared<ppc::core::PerfResults>();
345+
346+
// Create Perf analyzer
347+
auto perfAnalyzer = std::make_shared<ppc::core::Perf>(testTaskSequential);
348+
perfAnalyzer->pipeline_run(perfAttr, perfResults);
349+
ppc::core::Perf::print_perf_statistic(perfResults);
350+
ASSERT_EQ(count, out[0]);
351+
}
352+
\end{lstlisting}
353+
\end{frame}
354+
355+
\begin{frame}[fragile]{Practice}
356+
Practice
357+
\end{frame}
358+
196359
\begin{frame}{References}
197360
\begin{itemize}
198361
\item PPC Repository \href{https://github.com/learning-process/parallel\_programming\_course}{https://github.com/learning-process/parallel\_programming\_course}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
\beamer@sectionintoc {1}{The introduction to the repository}{3}{0}{1}
22
\beamer@sectionintoc {2}{How to submit your work}{7}{0}{2}
3+
\beamer@sectionintoc {3}{API of the course's repository}{9}{0}{3}

0 commit comments

Comments
 (0)