Skip to content

Commit

Permalink
change rtcCommit???WithQueue interface to return sycl::event
Browse files Browse the repository at this point in the history
  • Loading branch information
freibold committed Dec 11, 2024
1 parent d819ae0 commit f9ec90b
Show file tree
Hide file tree
Showing 10 changed files with 45 additions and 26 deletions.
2 changes: 1 addition & 1 deletion include/embree4/rtcore_buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ RTC_API void rtcCommitBuffer(RTCBuffer buffer);

#if defined(EMBREE_SYCL_SUPPORT) && defined(SYCL_LANGUAGE_VERSION)

RTC_API void rtcCommitBufferWithQueue(RTCBuffer buffer, sycl::queue queue, sycl::event* event);
RTC_API_CPP sycl::event rtcCommitBufferWithQueue(RTCBuffer buffer, sycl::queue queue);

#endif

Expand Down
2 changes: 1 addition & 1 deletion include/embree4/rtcore_device.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ RTC_API void rtcSetDeviceSYCLDevice(RTCDevice device, const sycl::device sycl_de

/* rtcCommitSceneWithQueue is asynchronous, user has to call queue.wait()
for synchronization. rtcCommitScene is blocking. */
RTC_API void rtcCommitSceneWithQueue(RTCScene scene, sycl::queue queue, sycl::event* event);
RTC_API_CPP sycl::event rtcCommitSceneWithQueue(RTCScene scene, sycl::queue queue);

#endif

Expand Down
11 changes: 4 additions & 7 deletions kernels/common/buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -170,21 +170,18 @@ namespace embree
DeviceGPU* gpu_device = dynamic_cast<DeviceGPU*>(device);
if (gpu_device) {
sycl::queue queue(gpu_device->getGPUDevice());
commit(queue, nullptr);
commit(queue);
queue.wait_and_throw();
}
#endif
}

#if defined(EMBREE_SYCL_SUPPORT)
__forceinline void commit(sycl::queue queue, sycl::event* event) {
__forceinline sycl::event commit(sycl::queue queue) {
if (dptr == ptr)
return;
return sycl::event();

sycl::event last_event = queue.memcpy(dptr, ptr, numBytes);

if (event)
*event = last_event;
return queue.memcpy(dptr, ptr, numBytes);
}
#endif

Expand Down
10 changes: 6 additions & 4 deletions kernels/common/rtcore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,25 +83,27 @@ RTC_NAMESPACE_BEGIN;
RTC_CATCH_END(nullptr);
}

RTC_API void rtcCommitSceneWithQueue (RTCScene hscene, sycl::queue queue, sycl::event* event)
RTC_API_CPP sycl::event rtcCommitSceneWithQueue (RTCScene hscene, sycl::queue queue)
{
Scene* scene = (Scene*) hscene;
RTC_CATCH_BEGIN;
RTC_TRACE(rtcCommitSceneWithQueue);
RTC_VERIFY_HANDLE(hscene);
RTC_ENTER_DEVICE(hscene);
scene->commit(false, queue, event);
return scene->commit(false, queue);
RTC_CATCH_END2(scene);
return sycl::event();
}

RTC_API void rtcCommitBufferWithQueue(RTCBuffer hbuffer, sycl::queue queue, sycl::event* event) {
RTC_API_CPP sycl::event rtcCommitBufferWithQueue(RTCBuffer hbuffer, sycl::queue queue) {
Buffer* buffer = (Buffer*)hbuffer;
RTC_CATCH_BEGIN;
RTC_TRACE(rtcCommitBufferWithQueue);
RTC_VERIFY_HANDLE(hbuffer);
RTC_ENTER_DEVICE(hbuffer);
buffer->commit(queue, event);
return buffer->commit(queue);
RTC_CATCH_END2(buffer);
return sycl::event();
}

#endif
Expand Down
4 changes: 2 additions & 2 deletions kernels/common/scene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -909,10 +909,10 @@ namespace embree
}

#if defined(EMBREE_SYCL_SUPPORT)
void Scene::commit (bool join, sycl::queue queue, sycl::event* event)
sycl::event Scene::commit (bool join, sycl::queue queue)
{
commit_internal(join);
syncWithDevice(queue, event);
return syncWithDevice(queue);
}
#endif

Expand Down
4 changes: 2 additions & 2 deletions kernels/common/scene.h
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ namespace embree
void build_gpu_accels();
void commit_internal (bool join);
#if defined(EMBREE_SYCL_SUPPORT)
void commit (bool join, sycl::queue queue, sycl::event* event);
sycl::event commit (bool join, sycl::queue queue);
#endif
void commit (bool join);
void commit_task ();
Expand Down Expand Up @@ -319,7 +319,7 @@ namespace embree
#if defined(EMBREE_SYCL_SUPPORT)
private:
void syncWithDevice();
void syncWithDevice(sycl::queue queue, sycl::event* event);
sycl::event syncWithDevice(sycl::queue queue);
#endif

public:
Expand Down
22 changes: 22 additions & 0 deletions kernels/rtcore_config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,15 @@
# define RTC_NAMESPACE_END }
# define RTC_NAMESPACE_USE using namespace @EMBREE_API_NAMESPACE@;
# define RTC_API_EXTERN_C
# define RTC_API_EXTERN_CPP
# undef EMBREE_API_NAMESPACE
#else
# define RTC_NAMESPACE_BEGIN
# define RTC_NAMESPACE_END
# define RTC_NAMESPACE_USE
# if defined(__cplusplus)
# define RTC_API_EXTERN_C extern "C"
# define RTC_API_EXTERN_CPP extern "C++"
# else
# define RTC_API_EXTERN_C
# endif
Expand All @@ -62,12 +64,32 @@
# define RTC_API_EXPORT RTC_API_EXTERN_C __attribute__ ((visibility ("default")))
#endif

#if defined(ISPC)
# define RTC_API_IMPORT_CPP extern "C++" unmasked
# define RTC_API_EXPORT_CPP extern "C++" unmasked
#elif defined(EMBREE_STATIC_LIB)
# define RTC_API_IMPORT_CPP RTC_API_EXTERN_CPP
# define RTC_API_EXPORT_CPP RTC_API_EXTERN_CPP
#elif defined(_WIN32)
# define RTC_API_IMPORT_CPP RTC_API_EXTERN_CPP __declspec(dllimport)
# define RTC_API_EXPORT_CPP RTC_API_EXTERN_CPP __declspec(dllexport)
#else
# define RTC_API_IMPORT_CPP RTC_API_EXTERN_CPP
# define RTC_API_EXPORT_CPP RTC_API_EXTERN_CPP __attribute__ ((visibility ("default")))
#endif

#if defined(RTC_EXPORT_API)
# define RTC_API RTC_API_EXPORT
#else
# define RTC_API RTC_API_IMPORT
#endif

#if defined(RTC_EXPORT_API)
# define RTC_API_CPP RTC_API_EXPORT_CPP
#else
# define RTC_API_CPP RTC_API_IMPORT_CPP
#endif

#if defined(ISPC)
# define RTC_SYCL_INDIRECTLY_CALLABLE
#elif defined(__SYCL_DEVICE_ONLY__)
Expand Down
12 changes: 5 additions & 7 deletions kernels/sycl/scene_sycl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,21 +132,21 @@ void Scene::syncWithDevice()
}

sycl::queue queue = sycl::queue(gpu_device->getGPUDevice());
syncWithDevice(queue, nullptr);
syncWithDevice(queue);
queue.wait_and_throw();
}

void Scene::syncWithDevice(sycl::queue queue, sycl::event* event)
sycl::event Scene::syncWithDevice(sycl::queue queue)
{
if(!device->is_gpu()) {
return;
return sycl::event();
}

// TODO: why is this compiled for __SYCL_DEVICE_ONLY__ ???
#if !defined(__SYCL_DEVICE_ONLY__)
accelBuffer.commit(queue);
#endif

const bool dynamic_scene = getSceneFlags() & RTC_SCENE_FLAG_DYNAMIC;

const bool num_geometries_changed = num_geometries != geometries.size();
Expand Down Expand Up @@ -225,9 +225,7 @@ void Scene::syncWithDevice(sycl::queue queue, sycl::event* event)
scene_device = (Scene*) device->malloc(sizeof(Scene), 16, EmbreeMemoryType::USM_DEVICE);
}

sycl::event last_event = queue.memcpy(scene_device, (void*)this, sizeof(Scene));
if (event)
*event = last_event;
return queue.memcpy(scene_device, (void*)this, sizeof(Scene));
}

#endif
Expand Down
2 changes: 1 addition & 1 deletion tutorials/dynamic_scene/dynamic_scene_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ extern "C" void device_render (int* pixels,
/* commit changes to scene */
auto start_commit = std::chrono::high_resolution_clock::now();
#if defined(EMBREE_SYCL_TUTORIAL)
rtcCommitSceneWithQueue (data.g_scene, *global_gpu_queue, nullptr);
rtcCommitSceneWithQueue (data.g_scene, *global_gpu_queue);
#else
rtcCommitScene (data.g_scene);
#endif
Expand Down
2 changes: 1 addition & 1 deletion tutorials/host_device_memory/host_device_memory_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ extern "C" void device_init (char* cfg)

/* commit changes to scene */
#if defined(EMBREE_SYCL_SUPPORT) && defined(EMBREE_SYCL_TUTORIAL)
rtcCommitSceneWithQueue (data.g_scene, *global_gpu_queue, nullptr);
rtcCommitSceneWithQueue (data.g_scene, *global_gpu_queue);
#else
rtcCommitScene (data.g_scene);
#endif
Expand Down

0 comments on commit f9ec90b

Please sign in to comment.