-
Notifications
You must be signed in to change notification settings - Fork 389
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor alloc. remove global (tls) SYCL context and device.
- Loading branch information
Showing
12 changed files
with
115 additions
and
120 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,8 @@ | |
|
||
#include "texture2d.h" | ||
|
||
#include "../alloc/alloc.h" | ||
|
||
namespace embree { | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters