Skip to content

Commit

Permalink
use aligned buffer under Linux
Browse files Browse the repository at this point in the history
  • Loading branch information
Steven Scholz committed Sep 11, 2024
1 parent e39ede2 commit 7e7c14f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
10 changes: 8 additions & 2 deletions ext/pylon/gstpylondsnvmmbufferfactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@

#include "gstpylondsnvmmbufferfactory.h"

#include <stdlib.h>
#include <unistd.h>

#include <cuda_runtime.h>
#include <gst/video/video.h>

Expand Down Expand Up @@ -82,10 +85,13 @@ void GstPylonDsNvmmBufferFactory::AllocateBuffer(size_t buffer_size,
intptr_t &buffer_context) {
void *buffer_mem = nullptr;

const size_t PAGE_SIZE = 4096;
const size_t PAGE_SIZE = getpagesize();
const size_t aligned_buffer_size = RoundUp(buffer_size, PAGE_SIZE);

buffer_mem = aligned_alloc(PAGE_SIZE, aligned_buffer_size);
int ret = posix_memalign(&buffer_mem, PAGE_SIZE, aligned_buffer_size);
if (ret)
buffer_mem = nullptr;

create_params.params.size = aligned_buffer_size;

/*
Expand Down
9 changes: 7 additions & 2 deletions ext/pylon/gstpylonsysmembufferfactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,19 @@

#include "gstpylonsysmembufferfactory.h"

#include <stdlib.h>
#include <unistd.h>

void GstPylonSysMemBufferFactory::AllocateBuffer(
size_t buffer_size, void **p_created_buffer,
intptr_t & /*buffer_context*/) {

#if defined(__GNUC__)
const size_t PAGE_SIZE = 4096;
const size_t PAGE_SIZE = getpagesize();
const size_t aligned_buffer_size = RoundUp(buffer_size, PAGE_SIZE);
*p_created_buffer = aligned_alloc(PAGE_SIZE, aligned_buffer_size);
int ret = posix_memalign(p_created_buffer, PAGE_SIZE, aligned_buffer_size);
if (ret)
*p_created_buffer = nullptr;
#else
*p_created_buffer = malloc(buffer_size);
#endif
Expand Down

0 comments on commit 7e7c14f

Please sign in to comment.