Skip to content

Commit

Permalink
Added allocator example
Browse files Browse the repository at this point in the history
  • Loading branch information
G-071 committed Feb 14, 2020
1 parent 25939bc commit 565f5cf
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 22 deletions.
10 changes: 9 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ project(hpx_kokkos_example)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
set(SKIP_HPX_KOKKOS_BUILD False)
set(SKIP_HPX_KOKKOS_BUILD TRUE)

#================================================================================================================================================
# Setup HPX
Expand Down Expand Up @@ -128,5 +128,13 @@ link_libraries(kokkos hpx dl boost_system boost_program_options boost_thread boo

add_hpx_executable(hello SOURCES ${SOURCES})

add_hpx_executable(
allocator_test
SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/src/allocator_test.cpp
HEADERS
${CMAKE_CURRENT_SOURCE_DIR}/include/buffer_manager.hpp
)

add_compile_options(-I${CMAKE_CURRENT_SOURCE_DIR}/external_dependencies/kokkos-hpx-interop/include)
add_hpx_executable(interop SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/external_dependencies/kokkos-hpx-interop/src/kokkos_hpx.cpp)
55 changes: 55 additions & 0 deletions include/buffer_manager.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// TODO Insert Allocator

// TODO Insert singleton memory mananger -> Wird der überhaupt benötigt?
// Vermutlich hauptsächlich um callbacks zu verwalten und die Synchronisierung zu machen
#include <iostream>


class buffer_recycler {
public:
template <class T>
static void get(size_t number_elements) {
if (!instance)
instance = new buffer_recycler();
buffer_manager<T>::get(number_elements);
}
static void clean(void) {
if (instance)
delete instance;
}
private:
static buffer_recycler *instance;
buffer_recycler(void) {
std::cout << "Buffer recycler constructor!" << std::endl;
}
~buffer_recycler(void) {
std::cout << "Buffer recycler destructor!" << std::endl;
}

private:
template<class T>
class buffer_manager {
public:
static void get(size_t number_elements) {
if (!instance)
instance = new buffer_manager();
}

private:
std::list<T*> buffer_list;
static buffer_manager<T> *instance; // requires C++17

buffer_manager(void) {
std::cout << "Buffer mananger constructor for " << typeid(T).name() << std::endl;
}
~buffer_manager(void) {
std::cout << "Buffer mananger destructor for " << typeid(T).name() << std::endl;
}
};
};

// Instance defintions
buffer_recycler* buffer_recycler::instance = nullptr;

template<class T>
buffer_recycler::buffer_manager<T>* buffer_recycler::buffer_manager<T>::instance = nullptr;
24 changes: 24 additions & 0 deletions src/allocator_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#include <hpx/hpx_main.hpp> // we don't need an hpx_main that way?
#include <hpx/include/async.hpp>
#include <hpx/include/lcos.hpp>

#include "../include/buffer_manager.hpp"
#include <cstdio>
#include <typeinfo>


// TODO Insert templated singleton submanager -> Eine Bufferliste pro Submanager. Ein Buffer is
// Do it is as subclass

// #pragma nv_exec_check_disable
int main(int argc, char *argv[])
{
buffer_recycler::get<double>(1000);
buffer_recycler::get<double>(1000);
buffer_recycler::get<int>(1000);
buffer_recycler::get<int>(1000);
std::cout << std::endl;
// Create Vectors with the new allocator

buffer_recycler::clean();
}
21 changes: 0 additions & 21 deletions src/hello.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -275,25 +275,4 @@ int main(int argc, char *argv[])
auto when = hpx::when_all(f, g, h, i, j, k, l);
when.wait();
}

// // Kokkos hello world example
// {
// std::size_t worker_id = hpx::get_worker_thread_num();
// std::size_t locality_id = hpx::get_locality_id();

// printf("HPX Thread %i on Locality %i\n\n", worker_id, locality_id);

// Kokkos::parallel_for("HelloWorld", Kokkos::RangePolicy<Kokkos::Cuda>(0, 14), hello_world());
// Kokkos::fence();

// printf("Hello World on Kokkos execution space %s\n",
// typeid(Kokkos::Experimental::HPX).name());
// Kokkos::parallel_for("HelloWorld", Kokkos::RangePolicy<Kokkos::Experimental::HPX>(0, 14), hello_world());
// Kokkos::fence();

// printf("Hello World on Kokkos execution space %s\n",
// typeid(Kokkos::Serial).name());
// Kokkos::parallel_for("HelloWorld", Kokkos::RangePolicy<Kokkos::Serial>(0, 14), hello_world());
// Kokkos::fence();
// }
}

0 comments on commit 565f5cf

Please sign in to comment.