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

Frei/device memory support #508

Open
wants to merge 50 commits into
base: devel
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
02997c6
fix wrong assert about maxTimeSegments.
freibold Sep 9, 2024
a503f23
fix missing sign-extension when using device memory for BVH data.
freibold Sep 18, 2024
cd6846e
BVH buffer in explicitly managed host/device memory on systems
freibold Sep 13, 2024
f5a4b9c
triangle geometry is now host/device, scene next
freibold Sep 26, 2024
539d966
All geom types work, spilling bug?
freibold Oct 16, 2024
b7a041f
compile fixes
freibold Oct 24, 2024
5c163b5
geometry data works
freibold Oct 28, 2024
160b9ca
add debug tutorial and restore state of other tutorials
freibold Oct 29, 2024
1b0ac5c
scene is now in device memory, too. USM shared memory is now only
freibold Nov 6, 2024
49ef39f
introduced read only handle RTCTraversable which is accessible on
freibold Nov 11, 2024
ef99300
memory passing interface
freibold Nov 18, 2024
bce7d2a
rework buffer interface
freibold Nov 22, 2024
6290555
test address sanitizer issue
freibold Nov 25, 2024
fe5839c
cleanups
freibold Nov 26, 2024
f6b5bb1
do not use ALIGNED_STRUCT_ macro for Scene and Geometry
freibold Nov 26, 2024
475f7f1
port of multi_instanced_geometry tutorial to RTCTraversable
freibold Nov 26, 2024
9d14cd8
port forest tutorial to new host/device memory support
freibold Nov 27, 2024
094b4b7
change API naming for buffers form 'Ex' to 'HostDevice'
freibold Nov 27, 2024
e65098d
add ISPC API using RTCTraversable
freibold Nov 29, 2024
3cd3f2f
create CPP from ISPC tutorials
freibold Nov 29, 2024
92c5f4d
add padding to tree vertex and color data buffers for safe SIMD
freibold Dec 2, 2024
0611461
small fix for validation API
freibold Dec 2, 2024
8c32f18
less alloc/free when creating device representation of scenen/geometry
freibold Dec 4, 2024
ac3d1c3
add sycl events for sychronization
freibold Dec 5, 2024
a5b7df0
add cmake option for explicit host/device BVH data
freibold Dec 5, 2024
b868759
clear host scratch space for static scenes
freibold Dec 5, 2024
94aa2e6
rename host_device_memory tutorial and add CI tests
freibold Dec 5, 2024
381e713
refactor alloc. remove global (tls) SYCL context and device.
freibold Dec 9, 2024
fd6a57a
add nightly Windows multilevel test.
freibold Dec 9, 2024
6261729
update documentation for RTCBuffer
freibold Dec 9, 2024
365d71a
fix wrong deallocation in multi_instance_geometry tutorial.
freibold Dec 9, 2024
0b0626d
update rtcSet(New|Shared)GeometryBuffer(|HostDevice) documentation
freibold Dec 10, 2024
5064047
update rtcCommitScene(|WithQueue) documentation
freibold Dec 10, 2024
3f6f6b5
rename memory types and account for host unified memory in buffer con…
freibold Dec 11, 2024
f97e8c5
revert accidental changes in ray flag settings
freibold Dec 11, 2024
54157fa
docu fixes
freibold Dec 11, 2024
ae21235
change rtcCommit???WithQueue interface to return sycl::event
freibold Dec 11, 2024
26771b1
make rtcCommitSceneWithQueue work with out-of-order SYCL queues, too
freibold Dec 11, 2024
9219fa3
updating general intro documentation
freibold Dec 11, 2024
6482924
documentation for ray queries using RTCTraversable
freibold Dec 11, 2024
e40bef0
more general documentation
freibold Dec 11, 2024
0e25353
add export filters for commit with queue API functions
freibold Dec 11, 2024
8dac949
add CI test for BVH data in host device memory
freibold Dec 11, 2024
a56ac13
test new ICX version
freibold Dec 11, 2024
cdf70a7
changelog, typos
freibold Dec 11, 2024
0e2e3a5
update internal Linux and Window driver in CI
freibold Dec 11, 2024
9950968
remove timing output from dynamic scene tutorial
freibold Dec 13, 2024
76f8c1f
fix issues with host/device memory API on iGPU
freibold Dec 13, 2024
13c62b6
fix blender segfault with geometry == NULL inside geometries array
dopitz Dec 16, 2024
2b5ddc2
preparations for merge
dopitz Jan 17, 2025
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
Prev Previous commit
Next Next commit
refactor alloc. remove global (tls) SYCL context and device.
freibold committed Dec 11, 2024
commit 381e713459eb01b6cc83597bcd4ede7157de7527
88 changes: 0 additions & 88 deletions common/sys/alloc.cpp
Original file line number Diff line number Diff line change
@@ -12,50 +12,6 @@

namespace embree
{
size_t total_allocations = 0;

#if defined(EMBREE_SYCL_SUPPORT)

__thread sycl::context* tls_context_tutorial = nullptr;
__thread sycl::device* tls_device_tutorial = nullptr;

__thread sycl::context* tls_context_embree = nullptr;
__thread sycl::device* tls_device_embree = nullptr;

void enableUSMAllocEmbree(sycl::context* context, sycl::device* device)
{
if (tls_context_embree != nullptr) throw std::runtime_error("USM allocation already enabled");
if (tls_device_embree != nullptr) throw std::runtime_error("USM allocation already enabled");
tls_context_embree = context;
tls_device_embree = device;
}

void disableUSMAllocEmbree()
{
if (tls_context_embree == nullptr) throw std::runtime_error("USM allocation not enabled");
if (tls_device_embree == nullptr) throw std::runtime_error("USM allocation not enabled");
tls_context_embree = nullptr;
tls_device_embree = nullptr;
}

void enableUSMAllocTutorial(sycl::context* context, sycl::device* device)
{
//if (tls_context_tutorial != nullptr) throw std::runtime_error("USM allocation already enabled");
//if (tls_device_tutorial != nullptr) throw std::runtime_error("USM allocation already enabled");
tls_context_tutorial = context;
tls_device_tutorial = device;
}

void disableUSMAllocTutorial()
{
//if (tls_context_tutorial == nullptr) throw std::runtime_error("USM allocation not enabled");
//if (tls_device_tutorial == nullptr) throw std::runtime_error("USM allocation not enabled");
tls_context_tutorial = nullptr;
tls_device_tutorial = nullptr;
}

#endif

void* alignedMalloc(size_t size, size_t align)
{
if (size == 0)
@@ -86,7 +42,6 @@ namespace embree
return nullptr;

assert((align & (align-1)) == 0);
total_allocations++;

void* ptr = nullptr;
if (mode == EMBREE_USM_SHARED_DEVICE_READ_ONLY)
@@ -109,7 +64,6 @@ namespace embree
return nullptr;

assert((align & (align-1)) == 0);
total_allocations++;

void* ptr = nullptr;
if (type == EmbreeMemoryType::SHARED) {
@@ -134,22 +88,6 @@ namespace embree
return ptr;
}

static MutexSys g_alloc_mutex;

void* alignedSYCLMalloc(size_t size, size_t align, EmbreeUSMMode mode)
{
if (tls_context_tutorial) return alignedSYCLMalloc(tls_context_tutorial, tls_device_tutorial, size, align, mode);
if (tls_context_embree ) return alignedSYCLMalloc(tls_context_embree, tls_device_embree, size, align, mode);
return nullptr;
}

void* alignedSYCLMalloc(size_t size, size_t align, EmbreeUSMMode mode, EmbreeMemoryType type)
{
if (tls_context_tutorial) return alignedSYCLMalloc(tls_context_tutorial, tls_device_tutorial, size, align, mode, type);
if (tls_context_embree ) return alignedSYCLMalloc(tls_context_embree, tls_device_embree, size, align, mode, type);
return nullptr;
}

void alignedSYCLFree(sycl::context* context, void* ptr)
{
assert(context);
@@ -163,33 +101,7 @@ namespace embree
}
}

void alignedSYCLFree(void* ptr)
{
if (tls_context_tutorial) return alignedSYCLFree(tls_context_tutorial, ptr);
if (tls_context_embree ) return alignedSYCLFree(tls_context_embree, ptr);
}

#endif

void* alignedUSMMalloc(size_t size, size_t align, EmbreeUSMMode mode)
{
#if defined(EMBREE_SYCL_SUPPORT)
if (tls_context_embree || tls_context_tutorial)
return alignedSYCLMalloc(size,align,mode);
else
#endif
return alignedMalloc(size,align);
}

void alignedUSMFree(void* ptr)
{
#if defined(EMBREE_SYCL_SUPPORT)
if (tls_context_embree || tls_context_tutorial)
return alignedSYCLFree(ptr);
else
#endif
return alignedFree(ptr);
}

static bool huge_pages_enabled = false;
static MutexSys os_init_mutex;
44 changes: 6 additions & 38 deletions common/sys/alloc.h
Original file line number Diff line number Diff line change
@@ -9,35 +9,22 @@

namespace embree
{
#if defined(EMBREE_SYCL_SUPPORT)

/* enables SYCL USM allocation */
void enableUSMAllocEmbree(sycl::context* context, sycl::device* device);
void enableUSMAllocTutorial(sycl::context* context, sycl::device* device);

/* disables SYCL USM allocation */
void disableUSMAllocEmbree();
void disableUSMAllocTutorial();

#endif

#define ALIGNED_STRUCT_(align) \
void* operator new(size_t size) { return alignedMalloc(size,align); } \
void operator delete(void* ptr) { alignedFree(ptr); } \
void* operator new[](size_t size) { return alignedMalloc(size,align); } \
void operator delete[](void* ptr) { alignedFree(ptr); }

#define ALIGNED_STRUCT_USM_(align) \
void* operator new(size_t size) { return alignedUSMMalloc(size,align); } \
void operator delete(void* ptr) { alignedUSMFree(ptr); } \
void* operator new[](size_t size) { return alignedUSMMalloc(size,align); } \
void operator delete[](void* ptr) { alignedUSMFree(ptr); }

#define ALIGNED_CLASS_(align) \
public: \
ALIGNED_STRUCT_(align) \
private:

/*! aligned allocation */
void* alignedMalloc(size_t size, size_t align);
void alignedFree(void* ptr);


enum EmbreeUSMMode {
EMBREE_USM_SHARED = 0,
EMBREE_USM_SHARED_DEVICE_READ_WRITE = 0,
@@ -50,33 +37,14 @@ namespace embree
SHARED = 2,
UNKNOWN = 3
};

/*! aligned allocation */
void* alignedMalloc(size_t size, size_t align);
void alignedFree(void* ptr);

/*! aligned allocation using SYCL USM */
void* alignedUSMMalloc(size_t size, size_t align = 16, EmbreeUSMMode mode = EMBREE_USM_SHARED_DEVICE_READ_ONLY);
void alignedUSMFree(void* ptr);

#if defined(EMBREE_SYCL_SUPPORT)

/*! aligned allocation using SYCL USM */
void* alignedSYCLMalloc(sycl::context* context, sycl::device* device, size_t size, size_t align, EmbreeUSMMode mode);
void* alignedSYCLMalloc(sycl::context* context, sycl::device* device, size_t size, size_t align, EmbreeUSMMode mode, EmbreeMemoryType type);
void alignedSYCLFree(sycl::context* context, void* ptr);

// deleter functor to use as deleter in std unique or shared pointers that
// capture raw pointers created by sycl::malloc and it's variants
template<typename T>
struct sycl_deleter
{
void operator()(T const* ptr)
{
alignedUSMFree((void*)ptr);
}
};

#endif

/*! allocator that performs aligned allocations */
2 changes: 0 additions & 2 deletions kernels/common/device.cpp
Original file line number Diff line number Diff line change
@@ -720,11 +720,9 @@ namespace embree
}

void DeviceGPU::enter() {
enableUSMAllocEmbree(&gpu_context,&gpu_device);
}

void DeviceGPU::leave() {
disableUSMAllocEmbree();
}

void* DeviceGPU::malloc(size_t size, size_t align) {
1 change: 1 addition & 0 deletions tutorials/common/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -5,6 +5,7 @@ IF (EMBREE_TUTORIALS_GLFW)
ADD_SUBDIRECTORY(imgui)
ENDIF()

ADD_SUBDIRECTORY(alloc)
ADD_SUBDIRECTORY(tutorial)
ADD_SUBDIRECTORY(scenegraph)
ADD_SUBDIRECTORY(lights)
15 changes: 15 additions & 0 deletions tutorials/common/alloc/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
## Copyright 2009-2021 Intel Corporation
## SPDX-License-Identifier: Apache-2.0

ADD_LIBRARY(alloc_tutorial STATIC alloc.cpp)
TARGET_LINK_LIBRARIES(alloc_tutorial sys)
SET_PROPERTY(TARGET alloc_tutorial PROPERTY FOLDER tutorials/common)
SET_PROPERTY(TARGET alloc_tutorial APPEND PROPERTY COMPILE_FLAGS " ${FLAGS_LOWEST}")

IF (EMBREE_SYCL_SUPPORT)
ADD_LIBRARY(alloc_tutorial_sycl STATIC alloc.cpp)
TARGET_LINK_LIBRARIES(alloc_tutorial_sycl sys)
SET_PROPERTY(TARGET alloc_tutorial_sycl PROPERTY FOLDER tutorials/common)
SET_PROPERTY(TARGET alloc_tutorial_sycl APPEND PROPERTY COMPILE_FLAGS " ${FLAGS_LOWEST} ${CMAKE_CXX_FLAGS_SYCL}")
TARGET_COMPILE_DEFINITIONS(alloc_tutorial_sycl PUBLIC EMBREE_SYCL_TUTORIAL)
ENDIF()
51 changes: 51 additions & 0 deletions tutorials/common/alloc/alloc.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// Copyright 2009-2021 Intel Corporation
// SPDX-License-Identifier: Apache-2.0

#include "alloc.h"

////////////////////////////////////////////////////////////////////////////////
/// All Platforms
////////////////////////////////////////////////////////////////////////////////

namespace embree
{
#if defined(EMBREE_SYCL_SUPPORT)

__thread sycl::context* tls_context = nullptr;
__thread sycl::device* tls_device = nullptr;

void enableUSMAllocTutorial(sycl::context* context, sycl::device* device)
{
tls_context = context;
tls_device = device;
}

void disableUSMAllocTutorial()
{
tls_context = nullptr;
tls_device = nullptr;
}

#endif

void* alignedUSMMalloc(size_t size, size_t align, EmbreeUSMMode mode)
{
#if defined(EMBREE_SYCL_SUPPORT)
if (tls_context)
return alignedSYCLMalloc(tls_context,tls_device,size,align,mode);
else
#endif
return alignedMalloc(size,align);
}

void alignedUSMFree(void* ptr)
{
#if defined(EMBREE_SYCL_SUPPORT)
if (tls_context)
return alignedSYCLFree(tls_context,ptr);
else
#endif
return alignedFree(ptr);
}

}
34 changes: 34 additions & 0 deletions tutorials/common/alloc/alloc.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Copyright 2009-2021 Intel Corporation
// SPDX-License-Identifier: Apache-2.0

#pragma once

#include "../../../common/sys/alloc.h"

#if defined(EMBREE_SYCL_SUPPORT)
#include <sycl/sycl.hpp>
#endif

namespace embree
{
#if defined(EMBREE_SYCL_SUPPORT)

/* enables SYCL USM allocation */
void enableUSMAllocTutorial(sycl::context* context, sycl::device* device);

/* disables SYCL USM allocation */
void disableUSMAllocTutorial();

#endif

#define ALIGNED_STRUCT_USM_(align) \
void* operator new(size_t size) { return alignedUSMMalloc(size,align); } \
void operator delete(void* ptr) { alignedUSMFree(ptr); } \
void* operator new[](size_t size) { return alignedUSMMalloc(size,align); } \
void operator delete[](void* ptr) { alignedUSMFree(ptr); }

/*! aligned allocation using SYCL USM */
void* alignedUSMMalloc(size_t size, size_t align = 16, EmbreeUSMMode mode = EMBREE_USM_SHARED_DEVICE_READ_ONLY);
void alignedUSMFree(void* ptr);

}
1 change: 1 addition & 0 deletions tutorials/common/default.h
Original file line number Diff line number Diff line change
@@ -3,6 +3,7 @@

#pragma once

#include "alloc/alloc.h"
#include "../../kernels/config.h"
#include "../../common/sys/platform.h"
#include "../../common/sys/sysinfo.h"
2 changes: 2 additions & 0 deletions tutorials/common/device_default.h
Original file line number Diff line number Diff line change
@@ -29,6 +29,8 @@
RTC_NAMESPACE_USE
#include "../../kernels/config.h"

#include "alloc/alloc.h"

namespace embree
{
#if defined(EMBREE_SYCL_TUTORIAL) && defined(EMBREE_SYCL_SUPPORT)
2 changes: 1 addition & 1 deletion tutorials/common/scenegraph/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -12,6 +12,6 @@ ADD_LIBRARY(scenegraph STATIC
scenegraph.cpp
geometry_creation.cpp)

TARGET_LINK_LIBRARIES(scenegraph sys math lexers image embree)
TARGET_LINK_LIBRARIES(scenegraph alloc_tutorial sys math lexers image embree)
SET_PROPERTY(TARGET scenegraph PROPERTY FOLDER tutorials/common)
SET_PROPERTY(TARGET scenegraph APPEND PROPERTY COMPILE_FLAGS " ${FLAGS_LOWEST}")
2 changes: 2 additions & 0 deletions tutorials/common/texture/texture2d.cpp
Original file line number Diff line number Diff line change
@@ -3,6 +3,8 @@

#include "texture2d.h"

#include "../alloc/alloc.h"

namespace embree {


4 changes: 2 additions & 2 deletions tutorials/common/tutorial/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -6,13 +6,13 @@ IF (EMBREE_TUTORIALS_GLFW)
ENDIF()

ADD_LIBRARY(tutorial STATIC tutorial.cpp application.cpp scene.cpp tutorial_device.cpp scene_device.cpp)
TARGET_LINK_LIBRARIES(tutorial sys math lexers scenegraph lights embree tasking ${GUI_LIBRARIES})
TARGET_LINK_LIBRARIES(tutorial alloc_tutorial sys math lexers scenegraph lights embree tasking ${GUI_LIBRARIES})
SET_PROPERTY(TARGET tutorial PROPERTY FOLDER tutorials/common)
SET_PROPERTY(TARGET tutorial APPEND PROPERTY COMPILE_FLAGS " ${FLAGS_LOWEST}")

IF (EMBREE_SYCL_SUPPORT)
ADD_LIBRARY(tutorial_sycl STATIC tutorial.cpp application.cpp scene.cpp tutorial_device.cpp scene_device.cpp)
TARGET_LINK_LIBRARIES(tutorial_sycl sys math lexers scenegraph lights_sycl embree tasking ze_wrapper ${GUI_LIBRARIES})
TARGET_LINK_LIBRARIES(tutorial_sycl alloc_tutorial_sycl sys math lexers scenegraph lights_sycl embree tasking ze_wrapper ${GUI_LIBRARIES})
SET_PROPERTY(TARGET tutorial_sycl PROPERTY FOLDER tutorials/common)
SET_PROPERTY(TARGET tutorial_sycl APPEND PROPERTY COMPILE_FLAGS " ${FLAGS_LOWEST} ${CMAKE_CXX_FLAGS_SYCL}")
TARGET_COMPILE_DEFINITIONS(tutorial_sycl PUBLIC EMBREE_SYCL_TUTORIAL)