removed old allocator and improved mem management

This commit is contained in:
Marcel Lütke Dreimann
2023-01-04 16:15:33 +01:00
parent dcd4dba272
commit 3b05673cfe
4 changed files with 17 additions and 159 deletions

View File

@@ -12,7 +12,6 @@ struct _cl_mem
{
struct buffer_config bc;
void* virt_vm; // virt addr that can be used by vm
bool ocl_allocated;
};
struct _cl_command_queue
{
@@ -263,6 +262,7 @@ clRetainContext(cl_context context)
CL_API_ENTRY cl_int CL_API_CALL
clReleaseContext(cl_context context)
{
g_cl_genode->reset();
return CL_SUCCESS;
}
@@ -317,22 +317,6 @@ clRetainCommandQueue(cl_command_queue command_queue)
CL_API_ENTRY cl_int CL_API_CALL
clReleaseCommandQueue(cl_command_queue command_queue)
{
cl_command_queue cmd = command_queue;
while(cmd != NULL)
{
cl_command_queue next = cmd->next;
for(int i = 0; i < cmd->kc->buffCount; i++)
{
if(cmd->kc->buffConfigs[i].non_pointer_type)
{
g_cl_genode->free(cmd->kc->buffConfigs[i].buffer);
}
}
g_cl_genode->free(cmd->kc->buffConfigs);
g_cl_genode->free(cmd->kc);
g_cl_genode->free(cmd);
cmd = next;
}
return CL_SUCCESS;
}
@@ -359,11 +343,9 @@ clCreateBuffer(cl_context context,
if(host_ptr == NULL)
{
host_ptr = g_cl_genode->aligned_alloc(0x1000, size);
clmem->ocl_allocated = true;
}
else
{
clmem->ocl_allocated = false;
Genode::error("[OCL] Memory mapping is currently unsupported!");
}
@@ -462,11 +444,6 @@ clRetainMemObject(cl_mem memobj)
CL_API_ENTRY cl_int CL_API_CALL
clReleaseMemObject(cl_mem memobj)
{
if(memobj->ocl_allocated && !memobj->bc.non_pointer_type)
{
g_cl_genode->free(memobj->virt_vm);
}
g_cl_genode->free(memobj);
return CL_SUCCESS;
}
@@ -670,7 +647,6 @@ clRetainProgram(cl_program program)
CL_API_ENTRY cl_int CL_API_CALL
clReleaseProgram(cl_program program)
{
g_cl_genode->free(program);
return CL_SUCCESS;
}
@@ -846,18 +822,6 @@ clRetainKernel(cl_kernel kernel)
CL_API_ENTRY cl_int CL_API_CALL
clReleaseKernel(cl_kernel kernel)
{
struct kernel_config* kc = (struct kernel_config*)kernel;
g_cl_genode->free(kc->binary);
for(int i = 0; i < kc->buffCount; i++)
{
if(kc->buffConfigs[i].non_pointer_type)
{
g_cl_genode->free(kc->buffConfigs[i].buffer);
}
}
g_cl_genode->free(kc->buffConfigs);
g_cl_genode->free(kc->kernelName);
g_cl_genode->free(kc);
return CL_SUCCESS;
}

View File

@@ -1,12 +1,6 @@
#include "cl_genode.h"
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)
cl_genode::cl_genode(Genode::Env& env, unsigned long size) : env(env), allocator(), mapped_base(0), backend_driver(env)
{
// get shared memory with driver
Genode::Ram_dataspace_capability ram_cap;
@@ -26,29 +20,7 @@ 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;
}
else if(alignment != 0x0)
{
Genode::error("[OCL] Unsupported alignment: ", alignment);
return nullptr;
}
return allocator.alloc_aligned(size, alignment).convert<void *>(
[&] (void *ptr) { return ptr; },
[&] (Genode::Range_allocator::Alloc_error e) -> void * {
Genode::error("[OCL] Error in driver allocation: ", e);
return nullptr;
}
);
#endif // USE_STUPID_ALLOCATOR
}
void* cl_genode::alloc(Genode::uint32_t size)

View File

@@ -5,13 +5,7 @@
#include <base/env.h>
// allocator
#define USE_STUPID_ALLOCATOR
#ifdef USE_STUPID_ALLOCATOR
#include "../allocator_stupid.h"
#else // USE_STUPID_ALLOCATOR
#include <base/heap.h>
#include <base/allocator_avl.h>
#endif // USE_STUPID_ALLOCATOR
#include <dataspace/client.h>
// pci
@@ -30,12 +24,7 @@ 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
@@ -88,15 +77,9 @@ 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
@@ -118,9 +101,11 @@ public:
*/
void wait(struct kernel_config* kconf);
#ifdef USE_STUPID_ALLOCATOR
/**
* @brief
*
*/
void reset() { allocator.reset(); }
#endif // USE_STUPID_ALLOCATOR
/**
* @brief print bench results */

View File

@@ -42,7 +42,7 @@ struct hello_gpgpu
{
// init CL env
Genode::log("===Init VM===");
const unsigned long size = 0x10000 * 0x1000;
const unsigned long size = 0x10000000;
cl_genode clg(env, size);
clInitGenode(clg);
@@ -52,16 +52,16 @@ struct hello_gpgpu
// run the test and hope the best
Genode::log("===Test GPU===");
Genode::Heap heap(env.ram(), env.rm());
Genode::Allocator_avl alloc(&heap);
//const unsigned int size = 0x10000 * 0x1000;
Genode::Ram_dataspace_capability ram_cap = env.ram().alloc(size);
Genode::addr_t mapped_base = env.rm().attach(ram_cap);
alloc.add_range(mapped_base, size);
run_gpgpu_test(alloc);
#ifdef USE_STUPID_ALLOCATOR
clg.reset();
#endif // USE_STUPID_ALLOCATOR
{
Genode::Heap heap(env.ram(), env.rm());
Genode::Allocator_avl alloc(&heap);
const unsigned long size = 0x10000;
Genode::Ram_dataspace_capability ram_cap = env.ram().alloc(size);
Genode::addr_t mapped_base = env.rm().attach(ram_cap);
alloc.add_range(mapped_base, size);
run_gpgpu_test(alloc);
env.ram().free(ram_cap);
}
// run selected benchmarks
Genode::log("===Run PolyBench===");
@@ -70,172 +70,109 @@ struct hello_gpgpu
{
Genode::log("===Run 2mm===");
ns_2mm::main(0, 0);
#ifdef USE_STUPID_ALLOCATOR
clg.reset();
#endif // USE_STUPID_ALLOCATOR
}
if(benchConfig & (0x1 << 1))
{
Genode::log("===Run 3mm===");
ns_3mm::main(0, 0);
#ifdef USE_STUPID_ALLOCATOR
clg.reset();
#endif // USE_STUPID_ALLOCATOR
}
if(benchConfig & (0x1 << 2))
{
Genode::log("===Run atax===");
ns_atax::main(0, 0);
#ifdef USE_STUPID_ALLOCATOR
clg.reset();
#endif // USE_STUPID_ALLOCATOR
}
if(benchConfig & (0x1 << 3))
{
Genode::log("===Run bicg===");
ns_bicg::main(0, 0);
#ifdef USE_STUPID_ALLOCATOR
clg.reset();
#endif // USE_STUPID_ALLOCATOR
}
if(benchConfig & (0x1 << 4))
{
Genode::log("===Run doitgen===");
ns_doitgen::main(0, 0);
#ifdef USE_STUPID_ALLOCATOR
clg.reset();
#endif // USE_STUPID_ALLOCATOR
}
if(benchConfig & (0x1 << 5))
{
Genode::log("===Run gemm===");
ns_gemm::main(0, 0);
#ifdef USE_STUPID_ALLOCATOR
clg.reset();
#endif // USE_STUPID_ALLOCATOR
}
if(benchConfig & (0x1 << 6))
{
Genode::log("===Run gemver===");
ns_gemver::main(0, 0);
#ifdef USE_STUPID_ALLOCATOR
clg.reset();
#endif // USE_STUPID_ALLOCATOR
}
if(benchConfig & (0x1 << 7))
{
Genode::log("===Run gesummv===");
ns_gesummv::main(0, 0);
#ifdef USE_STUPID_ALLOCATOR
clg.reset();
#endif // USE_STUPID_ALLOCATOR
}
if(benchConfig & (0x1 << 8))
{
Genode::log("===Run mvt===");
ns_mvt::main(0, 0);
#ifdef USE_STUPID_ALLOCATOR
clg.reset();
#endif // USE_STUPID_ALLOCATOR
}
if(benchConfig & (0x1 << 9))
{
Genode::log("===Run syr2k===");
ns_syr2k::main(0, 0);
#ifdef USE_STUPID_ALLOCATOR
clg.reset();
#endif // USE_STUPID_ALLOCATOR
}
if(benchConfig & (0x1 << 10))
{
Genode::log("===Run syrk===");
ns_syrk::main(0, 0);
#ifdef USE_STUPID_ALLOCATOR
clg.reset();
#endif // USE_STUPID_ALLOCATOR
}
if(benchConfig & (0x1 << 11))
{
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
}
if(benchConfig & (0x1 << 12))
{
Genode::log("===Run lu===");
ns_lu::main(0, 0);
#ifdef USE_STUPID_ALLOCATOR
clg.reset();
#endif // USE_STUPID_ALLOCATOR
}
if(benchConfig & (0x1 << 13))
{
Genode::log("===Run correlation===");
ns_correlation::main(0, 0);
#ifdef USE_STUPID_ALLOCATOR
clg.reset();
#endif // USE_STUPID_ALLOCATOR
}
if(benchConfig & (0x1 << 14))
{
Genode::log("===Run covariance===");
ns_covariance::main(0, 0);
#ifdef USE_STUPID_ALLOCATOR
clg.reset();
#endif // USE_STUPID_ALLOCATOR
}
if(benchConfig & (0x1 << 15))
{
Genode::log("===Run adi===");
ns_adi::main(0, 0);
#ifdef USE_STUPID_ALLOCATOR
clg.reset();
#endif // USE_STUPID_ALLOCATOR
}
if(benchConfig & (0x1 << 16))
{
Genode::log("===Run convolution_2d===");
ns_convolution_2d::main(0, 0);
#ifdef USE_STUPID_ALLOCATOR
clg.reset();
#endif // USE_STUPID_ALLOCATOR
}
if(benchConfig & (0x1 << 17))
{
Genode::log("===Run convolution_3d===");
ns_convolution_3d::main(0, 0);
#ifdef USE_STUPID_ALLOCATOR
clg.reset();
#endif // USE_STUPID_ALLOCATOR
}
if(benchConfig & (0x1 << 18))
{
Genode::log("===Run fdtd_2d===");
ns_fdtd_2d::main(0, 0);
#ifdef USE_STUPID_ALLOCATOR
clg.reset();
#endif // USE_STUPID_ALLOCATOR
}
if(benchConfig & (0x1 << 19))
{
Genode::log("===Run jacobi_1d_imper===");
ns_jacobi_1d_imper::main(0, 0);
#ifdef USE_STUPID_ALLOCATOR
clg.reset();
#endif // USE_STUPID_ALLOCATOR
}
if(benchConfig & (0x1 << 20))
{
Genode::log("===Run jacobi_2d_imper===");
ns_jacobi_2d_imper::main(0, 0);
#ifdef USE_STUPID_ALLOCATOR
clg.reset();
#endif // USE_STUPID_ALLOCATOR
}
});