Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds C++ version of most examples and cleans up deprecated examples #142

Merged
merged 10 commits into from
Nov 4, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions runtime/examples/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
#
# Copyright (C) 2014 Jens Korinth, TU Darmstadt
#
# This file is part of Tapasco (TPC).
#
# Tapasco is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
Expand All @@ -26,3 +21,4 @@ add_subdirectory(arrayupdate)
add_subdirectory(memcheck)
add_subdirectory(tapasco-benchmark)
add_subdirectory(tapasco-debug)
add_subdirectory(bandwidth)
6 changes: 5 additions & 1 deletion runtime/examples/arrayinit/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ add_executable(arrayinit arrayinit-example.c)
set_tapasco_defaults(arrayinit)
target_link_libraries(arrayinit tapasco pthread platform tlkm)

install(TARGETS arrayinit
add_executable(arrayinit-cpp arrayinit-example.cpp)
set_tapasco_defaults(arrayinit-cpp)
target_link_libraries(arrayinit-cpp tapasco pthread platform tlkm)

install(TARGETS arrayinit arrayinit-cpp
ARCHIVE DESTINATION share/Tapasco/bin/
LIBRARY DESTINATION share/Tapasco/bin/
RUNTIME DESTINATION share/Tapasco/bin/)
Expand Down
81 changes: 81 additions & 0 deletions runtime/examples/arrayinit/arrayinit-example.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
// Tapasco is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Tapasco is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with Tapasco. If not, see <http://www.gnu.org/licenses/>.
//
#include <array>
#include <iostream>
#include <tapasco.hpp>

#define SZ 256
#define RUNS 25

typedef int32_t element_type;
constexpr int ARRAYINIT_ID = 11;

static uint64_t check_array(std::array<element_type, SZ> &arr) {
unsigned int errs = 0;
for (size_t i = 0; i < arr.size(); ++i) {
if (arr[i] != (element_type)i) {
std::cerr << "ERROR: Value at " << i << " is " << arr[i] << std::endl;
++errs;
}
}
return errs;
}

int main(int argc, char **argv) {
// initialize TaPaSCo
tapasco::Tapasco tapasco;

uint64_t errs = 0;

// check arrayinit instance count
uint64_t instances =
tapasco_device_kernel_pe_count(tapasco.device(), ARRAYINIT_ID);
std::cout << "Got " << instances << " arrayinit instances.";
if (!instances) {
std::cout << "Need at least one arrayinit instance to run.";
exit(1);
}

for (int run = 0; run < RUNS; ++run) {
// Generate array for arrayinit output
std::array<element_type, SZ> result;
result.fill(-1);
// Wrap the array to be TaPaSCo compatible
auto result_buffer_pointer = tapasco::makeWrappedPointer(
result.data(), result.size() * sizeof(element_type));
// Data will be copied back from the device only, no data will be moved to
// the device
auto result_buffer_out = tapasco::makeOutOnly(result_buffer_pointer);

// Launch the job
// Arrayinit takes only one parameter: The location of the array. It will
// always initialize 256 Int`s.
auto job = tapasco.launch(ARRAYINIT_ID, result_buffer_out);

// Wait for job completion. Will block execution until the job is done.
job();

int iter_errs = check_array(result);
errs += iter_errs;
std::cout << "RUN " << run << " " << (iter_errs == 0 ? "OK" : "NOT OK")
<< std::endl;
}

if (!errs)
std::cout << "Arrayinit finished without errors." << std::endl;
else
std::cerr << "Arrayinit finished wit errors." << std::endl;

return errs;
}
6 changes: 5 additions & 1 deletion runtime/examples/arraysum/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ add_executable(arraysum arraysum-example.c)
set_tapasco_defaults(arraysum)
target_link_libraries(arraysum tapasco pthread platform tlkm)

install(TARGETS arraysum
add_executable(arraysum-cpp arraysum-example.cpp)
set_tapasco_defaults(arraysum-cpp)
target_link_libraries(arraysum-cpp tapasco pthread platform tlkm)

install(TARGETS arraysum arraysum-cpp
ARCHIVE DESTINATION share/Tapasco/bin/
LIBRARY DESTINATION share/Tapasco/bin/
RUNTIME DESTINATION share/Tapasco/bin/)
Expand Down
91 changes: 91 additions & 0 deletions runtime/examples/arraysum/arraysum-example.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
// Tapasco is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Tapasco is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with Tapasco. If not, see <http://www.gnu.org/licenses/>.
//
#include <array>
#include <iostream>
#include <tapasco.hpp>

#define SZ 256
#define RUNS 25

typedef int32_t element_type;
constexpr int PE_ID = 10;

static void init_array(std::array<element_type, SZ> &arr) {
for (size_t i = 0; i < arr.size(); ++i)
arr[i] = (element_type)i;
}

static int arraysum(std::array<element_type, SZ> &arr) {
int sum = 0;
for (size_t i = 0; i < arr.size(); i++) {
sum += arr[i];
}
return sum;
}

int main(int argc, char **argv) {
// initialize TaPaSCo
tapasco::Tapasco tapasco;

uint64_t errs = 0;

// check arraysum instance count
uint64_t instances = tapasco_device_kernel_pe_count(tapasco.device(), PE_ID);
std::cout << "Got " << instances << " arraysum instances.";
if (!instances) {
std::cout << "Need at least one arraysum instance to run.";
exit(1);
}

for (int run = 0; run < RUNS; ++run) {
// Generate array for arraysum output
std::array<element_type, SZ> input;
init_array(input);

int cpu_sum = arraysum(input);

// Wrap the array to be TaPaSCo compatible
auto input_buffer_pointer = tapasco::makeWrappedPointer(
input.data(), input.size() * sizeof(element_type));
// Data will be copied back from the device only, no data will be moved to
// the device
auto input_buffer_in = tapasco::makeInOnly(input_buffer_pointer);

int fpga_sum = -1;
tapasco::RetVal<int> ret_val(fpga_sum);

// Launch the job
// Arraysum takes only one parameter: The location of the array. It will
// always summarize 256 Int`s.
auto job = tapasco.launch(PE_ID, ret_val, input_buffer_in);

// Wait for job completion. Will block execution until the job is done.
job();

if (cpu_sum == fpga_sum) {
std::cout << "RUN " << run << "OK" << std::endl;
} else {
std::cerr << "RUN" << run << " FAILED FPGA: " << fpga_sum
<< " CPU: " << cpu_sum << std::endl;
++errs;
}
}

if (!errs)
std::cout << "Arraysum finished without errors." << std::endl;
else
std::cerr << "Arraysum finished wit errors." << std::endl;

return errs;
}
6 changes: 5 additions & 1 deletion runtime/examples/arrayupdate/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ add_executable(arrayupdate arrayupdate-example.c)
set_tapasco_defaults(arrayupdate)
target_link_libraries(arrayupdate tapasco pthread platform tlkm)

install(TARGETS arrayupdate
add_executable(arrayupdate-cpp arrayupdate-example.cpp)
set_tapasco_defaults(arrayupdate-cpp)
target_link_libraries(arrayupdate-cpp tapasco pthread platform tlkm)

install(TARGETS arrayupdate arrayupdate-cpp
ARCHIVE DESTINATION share/Tapasco/bin/
LIBRARY DESTINATION share/Tapasco/bin/
RUNTIME DESTINATION share/Tapasco/bin/)
Expand Down
86 changes: 86 additions & 0 deletions runtime/examples/arrayupdate/arrayupdate-example.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
// Tapasco is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Tapasco is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with Tapasco. If not, see <http://www.gnu.org/licenses/>.
//
#include <array>
#include <iostream>
#include <tapasco.hpp>

#define SZ 256
#define RUNS 25

typedef int32_t element_type;
constexpr int PE_ID = 9;

static void init_array(std::array<element_type, SZ> &arr) {
for (size_t i = 0; i < arr.size(); ++i)
arr[i] = (element_type)i;
}

static int arraycheck(std::array<element_type, SZ> &arr) {
int errs = 0;
for (size_t i = 0; i < arr.size(); i++) {
if (arr[i] != ((element_type)i) + 42) {
std::cerr << "ERROR: Value at " << i << " is " << arr[i] << std::endl;
++errs;
}
}
return errs;
}

int main(int argc, char **argv) {
// initialize TaPaSCo
tapasco::Tapasco tapasco;

uint64_t errs = 0;

// check arrayupdate instance count
uint64_t instances = tapasco_device_kernel_pe_count(tapasco.device(), PE_ID);
std::cout << "Got " << instances << " arrayupdate instances.";
if (!instances) {
std::cout << "Need at least one arrayupdate instance to run.";
exit(1);
}

for (int run = 0; run < RUNS; ++run) {
// Generate array for arrayupdate output
std::array<element_type, SZ> input;
init_array(input);

// Wrap the array to be TaPaSCo compatible
auto input_buffer_pointer = tapasco::makeWrappedPointer(
input.data(), input.size() * sizeof(element_type));

// Launch the job
// Arrayupdate takes only one parameter: The location of the array. It will
// always update 256 Int`s.
auto job = tapasco.launch(PE_ID, input_buffer_pointer);

// Wait for job completion. Will block execution until the job is done.
job();

int iter_errs = arraycheck(input);
errs += iter_errs;
if (!iter_errs) {
std::cout << "RUN " << run << "OK" << std::endl;
} else {
std::cerr << "RUN" << run << " FAILED" << std::endl;
}
}

if (!errs)
std::cout << "Arrayupdate finished without errors." << std::endl;
else
std::cerr << "Arrayupdate finished wit errors." << std::endl;

return errs;
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
cmake_minimum_required(VERSION 3.5.1 FATAL_ERROR)
include($ENV{TAPASCO_HOME_RUNTIME}/cmake/Tapasco.cmake NO_POLICY_SCOPE)
project (basic_test)
project (bandwidth)

if(NOT TARGET tapasco)
find_package(TapascoTLKM REQUIRED)
find_package(TapascoCommon REQUIRED)
find_package(TapascoPlatform REQUIRED)
find_package(Tapasco REQUIRED)
endif(NOT TARGET tapasco)

add_executable(basic_test basic_test.cpp)
set_tapasco_defaults(basic_test)
target_link_libraries(basic_test rt pthread tapasco platform atomic)
add_executable(bandwidth bandwidth.cpp)
set_tapasco_defaults(bandwidth)
target_link_libraries(bandwidth PRIVATE tapasco tlkm platform tapasco-common)

install(TARGETS basic_test
install(TARGETS bandwidth
ARCHIVE DESTINATION share/Tapasco/bin/
LIBRARY DESTINATION share/Tapasco/bin/
RUNTIME DESTINATION share/Tapasco/bin/)

Loading