diff --git a/repos/hello_gpgpu/src/hello_gpgpu/CL/cl_genode.cc b/repos/hello_gpgpu/src/hello_gpgpu/CL/cl_genode.cc index 2debd9fb08..6a8bf339fd 100644 --- a/repos/hello_gpgpu/src/hello_gpgpu/CL/cl_genode.cc +++ b/repos/hello_gpgpu/src/hello_gpgpu/CL/cl_genode.cc @@ -1,6 +1,12 @@ #include "cl_genode.h" -cl_genode::cl_genode(Genode::Env& env, unsigned long size) : env(env), heap{ env.ram(), env.rm() }, allocator(&heap), mapped_base(0), backend_driver(env) +cl_genode::cl_genode(Genode::Env& env, unsigned long size) : env(env), +#ifdef USE_STUPID_ALLOCATOR +allocator(), +#else // USE_STUPID_ALLOCATOR + heap{ env.ram(), env.rm() }, allocator(&heap), +#endif // USE_STUPID_ALLOCATOR + mapped_base(0), backend_driver(env) { // get shared memory with driver Genode::Ram_dataspace_capability ram_cap; @@ -20,6 +26,9 @@ cl_genode::~cl_genode() void* cl_genode::aligned_alloc(Genode::uint32_t alignment, Genode::uint32_t size) { +#ifdef USE_STUPID_ALLOCATOR + return allocator.alloc_aligned(alignment, size); +#else // USE_STUPID_ALLOCATOR if(alignment == 0x1000) { alignment = 12; @@ -39,6 +48,7 @@ void* cl_genode::aligned_alloc(Genode::uint32_t alignment, Genode::uint32_t size return nullptr; } ); +#endif // USE_STUPID_ALLOCATOR } void* cl_genode::alloc(Genode::uint32_t size) diff --git a/repos/hello_gpgpu/src/hello_gpgpu/CL/cl_genode.h b/repos/hello_gpgpu/src/hello_gpgpu/CL/cl_genode.h index 285340cedf..f961fb9ed2 100644 --- a/repos/hello_gpgpu/src/hello_gpgpu/CL/cl_genode.h +++ b/repos/hello_gpgpu/src/hello_gpgpu/CL/cl_genode.h @@ -5,8 +5,13 @@ #include // allocator +#define USE_STUPID_ALLOCATOR +#ifdef USE_STUPID_ALLOCATOR +#include "../allocator_stupid.h" +#else // USE_STUPID_ALLOCATOR #include #include +#endif // USE_STUPID_ALLOCATOR #include // pci @@ -25,8 +30,12 @@ private: Genode::Env& env; // allocator +#ifdef USE_STUPID_ALLOCATOR + Genode::Allocator_stupid allocator; +#else // USE_STUPID_ALLOCATOR Genode::Heap heap; Genode::Allocator_avl allocator; +#endif // USE_STUPID_ALLOCATOR Genode::addr_t mapped_base; // rpc @@ -79,9 +88,15 @@ public: * * @return Genode::Allocator_avl& */ +#ifdef USE_STUPID_ALLOCATOR + Genode::Allocator_stupid& getAlloc() { + return allocator; + } +#else // USE_STUPID_ALLOCATOR Genode::Allocator_avl& getAlloc() { return allocator; } +#endif // USE_STUPID_ALLOCATOR /** * @brief @@ -104,6 +119,10 @@ public: */ void wait(struct kernel_config* kconf); +#ifdef USE_STUPID_ALLOCATOR + void reset() { allocator.reset(); } +#endif // USE_STUPID_ALLOCATOR + /** * @brief print bench results */ void print_vgpu_bench(unsigned long i); diff --git a/repos/hello_gpgpu/src/hello_gpgpu/allocator_stupid.cc b/repos/hello_gpgpu/src/hello_gpgpu/allocator_stupid.cc new file mode 100644 index 0000000000..f10dc5a4c5 --- /dev/null +++ b/repos/hello_gpgpu/src/hello_gpgpu/allocator_stupid.cc @@ -0,0 +1,35 @@ +#include "allocator_stupid.h" + +using namespace Genode; + +void* Allocator_stupid::alloc(size_t size) +{ + if(m_curr + size > m_end) + return nullptr; + + const addr_t naddr = m_curr; + m_curr += size; + + return (void*)naddr; +} + +void* Allocator_stupid::alloc_aligned(uint32_t alignment, size_t size) +{ + m_curr = (m_curr + alignment - 1) & ~(alignment - 1); + return alloc(size); +} + +void Allocator_stupid::free(void* addr) +{ + (void)addr; +} + +void Allocator_stupid::reset() +{ + m_curr = m_start; +} + +void *operator new (__SIZE_TYPE__ s, Genode::Allocator_stupid *a) { return a->alloc(s); } +void *operator new [] (__SIZE_TYPE__ s, Genode::Allocator_stupid *a) { return a->alloc(s); } +void *operator new (__SIZE_TYPE__ s, Genode::Allocator_stupid &a) { return a.alloc(s); } +void *operator new [] (__SIZE_TYPE__ s, Genode::Allocator_stupid &a) { return a.alloc(s); } diff --git a/repos/hello_gpgpu/src/hello_gpgpu/allocator_stupid.h b/repos/hello_gpgpu/src/hello_gpgpu/allocator_stupid.h new file mode 100644 index 0000000000..1b6da38322 --- /dev/null +++ b/repos/hello_gpgpu/src/hello_gpgpu/allocator_stupid.h @@ -0,0 +1,85 @@ +#ifndef ALLOCATOR_STUPID +#define ALLOCATOR_STUPID + +#include + +namespace Genode { + class Allocator_stupid; +} + +class Genode::Allocator_stupid +{ +private: + /* + * Noncopyable + */ + Allocator_stupid(Allocator_stupid const &); + Allocator_stupid &operator = (Allocator_stupid const &); + + /// @brief starting address + Genode::addr_t m_start; + + /// @brief current allocation addr + Genode::addr_t m_curr; + + /// @brief last address + Genode::size_t m_end; + +public: + /** + * @brief Construct a new Allocator_stupid object + */ + Allocator_stupid() : + m_start(0), m_curr(0), m_end(0) { } + + /** + * @brief Destroy the Allocator_stupid object + * + */ + ~Allocator_stupid() { } + + /** + * @brief allocate memory + * + * @param size + * @return void* + */ + void* alloc(size_t size); + + /** + * @brief allocate aligned memory + * + * @param alignment + * @param size + * @return void* + */ + void* alloc_aligned(Genode::uint32_t alignment, Genode::size_t size); + + /** + * @brief free memory + * + * @param addr + */ + void free(void* addr); + + /** + * @brief free any unfreed memory + * + */ + void reset(); + + /** + * @brief set address range to allocate from + * + * @param start + * @param size + */ + void add_range(Genode::addr_t start, Genode::size_t size) { m_start = start; m_curr = start; m_end = m_start + size; }; +}; + +void *operator new (__SIZE_TYPE__ s, Genode::Allocator_stupid *a); +void *operator new [] (__SIZE_TYPE__ s, Genode::Allocator_stupid *a); +void *operator new (__SIZE_TYPE__ s, Genode::Allocator_stupid &a); +void *operator new [] (__SIZE_TYPE__ s, Genode::Allocator_stupid &a); + +#endif /* ALLOCATOR_STUPID */ diff --git a/repos/hello_gpgpu/src/hello_gpgpu/main.cc b/repos/hello_gpgpu/src/hello_gpgpu/main.cc index 423014521e..aedb1cc8f9 100644 --- a/repos/hello_gpgpu/src/hello_gpgpu/main.cc +++ b/repos/hello_gpgpu/src/hello_gpgpu/main.cc @@ -1,5 +1,7 @@ #include #include +#include +#include #include @@ -43,49 +45,112 @@ void testvm_construct(Genode::Env &env) Libc::with_libc([&] { Genode::log("===Run 2mm==="); ns_2mm::main(0, 0); +#ifdef USE_STUPID_ALLOCATOR + clg.reset(); +#endif // USE_STUPID_ALLOCATOR Genode::log("===Run 3mm==="); ns_3mm::main(0, 0); +#ifdef USE_STUPID_ALLOCATOR + clg.reset(); +#endif // USE_STUPID_ALLOCATOR Genode::log("===Run atax==="); ns_atax::main(0, 0); +#ifdef USE_STUPID_ALLOCATOR + clg.reset(); +#endif // USE_STUPID_ALLOCATOR Genode::log("===Run bicg==="); ns_bicg::main(0, 0); +#ifdef USE_STUPID_ALLOCATOR + clg.reset(); +#endif // USE_STUPID_ALLOCATOR Genode::log("===Run doitgen==="); ns_doitgen::main(0, 0); +#ifdef USE_STUPID_ALLOCATOR + clg.reset(); +#endif // USE_STUPID_ALLOCATOR Genode::log("===Run gemm==="); ns_gemm::main(0, 0); +#ifdef USE_STUPID_ALLOCATOR + clg.reset(); +#endif // USE_STUPID_ALLOCATOR Genode::log("===Run gemver==="); ns_gemver::main(0, 0); +#ifdef USE_STUPID_ALLOCATOR + clg.reset(); +#endif // USE_STUPID_ALLOCATOR Genode::log("===Run gesummv==="); ns_gesummv::main(0, 0); +#ifdef USE_STUPID_ALLOCATOR + clg.reset(); +#endif // USE_STUPID_ALLOCATOR Genode::log("===Run mvt==="); ns_mvt::main(0, 0); +#ifdef USE_STUPID_ALLOCATOR + clg.reset(); +#endif // USE_STUPID_ALLOCATOR Genode::log("===Run syr2k==="); ns_syr2k::main(0, 0); +#ifdef USE_STUPID_ALLOCATOR + clg.reset(); +#endif // USE_STUPID_ALLOCATOR Genode::log("===Run syrk==="); ns_syrk::main(0, 0); +#ifdef USE_STUPID_ALLOCATOR + clg.reset(); +#endif // USE_STUPID_ALLOCATOR - //Genode::log("===Run gramschmidt==="); - //ns_gramschmidt::main(0, 0); // this one is broken (div by 0 and unsolvable input instance) (official Linux version is broken too!) + /*Genode::log("===Run gramschmidt==="); + ns_gramschmidt::main(0, 0); // this one is broken (div by 0 and unsolvable input instance) (official Linux version is broken too!) +#ifdef USE_STUPID_ALLOCATOR + clg.reset(); +#endif // USE_STUPID_ALLOCATOR*/ Genode::log("===Run lu==="); - ns_lu::main(0, 0); // Non-Matching CPU-GPU Outputs Beyond Error Threshold of 0.05 Percent: 516 + ns_lu::main(0, 0); +#ifdef USE_STUPID_ALLOCATOR + clg.reset(); +#endif // USE_STUPID_ALLOCATOR Genode::log("===Run correlation==="); ns_correlation::main(0, 0); +#ifdef USE_STUPID_ALLOCATOR + clg.reset(); +#endif // USE_STUPID_ALLOCATOR Genode::log("===Run covariance==="); ns_covariance::main(0, 0); +#ifdef USE_STUPID_ALLOCATOR + clg.reset(); +#endif // USE_STUPID_ALLOCATOR Genode::log("===Run adi==="); - ns_adi::main(0, 0); // CPU-GPU Outputs Beyond Error Threshold of 10.05 Percent: 455 + ns_adi::main(0, 0); +#ifdef USE_STUPID_ALLOCATOR + clg.reset(); +#endif // USE_STUPID_ALLOCATOR Genode::log("===Run convolution_2d==="); ns_convolution_2d::main(0, 0); +#ifdef USE_STUPID_ALLOCATOR + clg.reset(); +#endif // USE_STUPID_ALLOCATOR Genode::log("===Run convolution_3d==="); ns_convolution_3d::main(0, 0); +#ifdef USE_STUPID_ALLOCATOR + clg.reset(); +#endif // USE_STUPID_ALLOCATOR Genode::log("===Run fdtd_2d==="); - ns_fdtd_2d::main(0, 0); // Non-Matching CPU-GPU Outputs Beyond Error Threshold of 1.05 Percent: 1 + ns_fdtd_2d::main(0, 0); +#ifdef USE_STUPID_ALLOCATOR + clg.reset(); +#endif // USE_STUPID_ALLOCATOR Genode::log("===Run jacobi_1d_imper==="); - ns_jacobi_1d_imper::main(0, 0); // Non-Matching CPU-GPU Outputs Beyond Error Threshold of 10.05 Percent: 1109 + ns_jacobi_1d_imper::main(0, 0); +#ifdef USE_STUPID_ALLOCATOR + clg.reset(); +#endif // USE_STUPID_ALLOCATOR Genode::log("===Run jacobi_2d_imper==="); ns_jacobi_2d_imper::main(0, 0); +#ifdef USE_STUPID_ALLOCATOR + clg.reset(); +#endif // USE_STUPID_ALLOCATOR }); Genode::log("===End==="); diff --git a/repos/hello_gpgpu/src/hello_gpgpu/target.mk b/repos/hello_gpgpu/src/hello_gpgpu/target.mk index 3856d1a828..cac40a853e 100644 --- a/repos/hello_gpgpu/src/hello_gpgpu/target.mk +++ b/repos/hello_gpgpu/src/hello_gpgpu/target.mk @@ -1,5 +1,6 @@ TARGET = hello_gpgpu SRC_CC = main.cc \ + allocator_stupid.cc \ test.cc polybench.cc \ CL/cl.cc CL/cl_genode.cc \ benchmark/2mm/2mm.cc \