From 9cc3231f4de9f5140261fda3d77eb54529b50df4 Mon Sep 17 00:00:00 2001 From: PENGUINLIONG Date: Tue, 20 Dec 2022 17:40:01 +0800 Subject: [PATCH 01/12] Removed event --- c_api/docs/taichi/taichi_core.h.md | 8 -- c_api/include/taichi/cpp/taichi.hpp | 54 ------------- c_api/include/taichi/taichi_core.h | 38 --------- c_api/include/taichi/taichi_vulkan.h | 24 ------ c_api/src/taichi_core_impl.cpp | 59 -------------- c_api/src/taichi_gfx_impl.cpp | 9 --- c_api/src/taichi_vulkan_impl.cpp | 38 --------- c_api/taichi.json | 111 --------------------------- taichi/rhi/device.h | 2 - taichi/rhi/vulkan/vulkan_api.cpp | 22 ------ taichi/rhi/vulkan/vulkan_api.h | 11 --- taichi/rhi/vulkan/vulkan_device.cpp | 23 ------ taichi/rhi/vulkan/vulkan_device.h | 11 --- taichi/runtime/gfx/runtime.cpp | 16 ---- 14 files changed, 426 deletions(-) diff --git a/c_api/docs/taichi/taichi_core.h.md b/c_api/docs/taichi/taichi_core.h.md index 0ac8fb4d0f55c..5ece6c3cf0e67 100644 --- a/c_api/docs/taichi/taichi_core.h.md +++ b/c_api/docs/taichi/taichi_core.h.md @@ -502,14 +502,6 @@ Allocates a device image with provided parameters. Frees an image allocation. -`function.create_event` - -Creates an event primitive. - -`function.destroy_event` - -Destroys an event primitive. - `function.copy_memory_device_to_device` Copies the data in a contiguous subsection of the device memory to another subsection. The two subsections *must not* overlap. diff --git a/c_api/include/taichi/cpp/taichi.hpp b/c_api/include/taichi/cpp/taichi.hpp index b88323e709aea..1ba71b651fd78 100644 --- a/c_api/include/taichi/cpp/taichi.hpp +++ b/c_api/include/taichi/cpp/taichi.hpp @@ -685,60 +685,6 @@ class AotModule { } }; -class Event { - TiRuntime runtime_{TI_NULL_HANDLE}; - TiEvent event_{TI_NULL_HANDLE}; - bool should_destroy_{false}; - - public: - constexpr bool is_valid() const { - return event_ != nullptr; - } - inline void destroy() { - if (should_destroy_) { - ti_destroy_event(event_); - event_ = TI_NULL_HANDLE; - should_destroy_ = false; - } - } - - Event() { - } - Event(const Event &) = delete; - Event(Event &&b) : event_(b.event_), should_destroy_(b.should_destroy_) { - } - Event(TiRuntime runtime, TiEvent event, bool should_destroy) - : runtime_(runtime), event_(event), should_destroy_(should_destroy) { - } - ~Event() { - destroy(); - } - - Event &operator=(const Event &) = delete; - Event &operator=(Event &&b) { - event_ = detail::move_handle(b.event_); - should_destroy_ = std::exchange(b.should_destroy_, false); - return *this; - } - - void reset(TiEvent event_) { - ti_reset_event(runtime_, event_); - } - void signal(TiEvent event_) { - ti_signal_event(runtime_, event_); - } - void wait(TiEvent event_) { - ti_wait_event(runtime_, event_); - } - - constexpr TiEvent event() const { - return event_; - } - constexpr operator TiEvent() const { - return event_; - } -}; - class CapabilityLevelConfigBuilder; class CapabilityLevelConfig { public: diff --git a/c_api/include/taichi/taichi_core.h b/c_api/include/taichi/taichi_core.h index d8f7c7febe9da..767b116107ef3 100644 --- a/c_api/include/taichi/taichi_core.h +++ b/c_api/include/taichi/taichi_core.h @@ -281,12 +281,6 @@ typedef struct TiRuntime_t *TiRuntime; // kernels and compute graphs. typedef struct TiAotModule_t *TiAotModule; -// Handle `TiEvent` -// -// A synchronization primitive to manage device execution flows in multiple -// queues. -typedef struct TiEvent_t *TiEvent; - // Handle `TiMemory` // // A contiguous allocation of device memory. @@ -915,16 +909,6 @@ ti_create_sampler(TiRuntime runtime, const TiSamplerCreateInfo *create_info); TI_DLL_EXPORT void TI_API_CALL ti_destroy_sampler(TiRuntime runtime, TiSampler sampler); -// Function `ti_create_event` -// -// Creates an event primitive. -TI_DLL_EXPORT TiEvent TI_API_CALL ti_create_event(TiRuntime runtime); - -// Function `ti_destroy_event` -// -// Destroys an event primitive. -TI_DLL_EXPORT void TI_API_CALL ti_destroy_event(TiEvent event); - // Function `ti_copy_memory_device_to_device` (Device Command) // // Copies the data in a contiguous subsection of the device memory to another @@ -980,28 +964,6 @@ ti_launch_compute_graph(TiRuntime runtime, uint32_t arg_count, const TiNamedArgument *args); -// Function `ti_signal_event` (Device Command) -// -// Sets an event primitive to a signaled state so that the queues waiting for it -// can go on execution. If the event has been signaled, you *must* call -// [`ti_reset_event`](#function-ti_reset_event-device-command) to reset it; -// otherwise, an undefined behavior would occur. -TI_DLL_EXPORT void TI_API_CALL ti_signal_event(TiRuntime runtime, - TiEvent event); - -// Function `ti_reset_event` (Device Command) -// -// Sets a signaled event primitive back to an unsignaled state. -TI_DLL_EXPORT void TI_API_CALL ti_reset_event(TiRuntime runtime, TiEvent event); - -// Function `ti_wait_event` (Device Command) -// -// Waits until an event primitive transitions to a signaled state. The awaited -// event *must* be signaled by an external procedure or a previous invocation to -// [`ti_reset_event`](#function-ti_reset_event-device-command); otherwise, an -// undefined behavior would occur. -TI_DLL_EXPORT void TI_API_CALL ti_wait_event(TiRuntime runtime, TiEvent event); - // Function `ti_submit` // // Submits all previously invoked device commands to the offload device for diff --git a/c_api/include/taichi/taichi_vulkan.h b/c_api/include/taichi/taichi_vulkan.h index 2a440092013fb..205980dc2e057 100644 --- a/c_api/include/taichi/taichi_vulkan.h +++ b/c_api/include/taichi/taichi_vulkan.h @@ -89,15 +89,6 @@ typedef struct TiVulkanImageInteropInfo { VkImageUsageFlags usage; } TiVulkanImageInteropInfo; -// Structure `TiVulkanEventInteropInfo` -// -// Necessary detail to share the same Vulkan event synchronization primitive -// between Taichi and the user application. -typedef struct TiVulkanEventInteropInfo { - // Vulkan event handle. - VkEvent event; -} TiVulkanEventInteropInfo; - // Function `ti_create_vulkan_runtime_ext` // // Creates a Vulkan Taichi runtime with user-controlled capability settings. @@ -153,21 +144,6 @@ ti_export_vulkan_image(TiRuntime runtime, TiImage image, TiVulkanImageInteropInfo *interop_info); -// Function `ti_import_vulkan_event` -// -// Imports the Vulkan event owned by Taichi to external procedures. -TI_DLL_EXPORT TiEvent TI_API_CALL -ti_import_vulkan_event(TiRuntime runtime, - const TiVulkanEventInteropInfo *interop_info); - -// Function `ti_export_vulkan_event` -// -// Exports a Vulkan event from external procedures to Taichi. -TI_DLL_EXPORT void TI_API_CALL -ti_export_vulkan_event(TiRuntime runtime, - TiEvent event, - TiVulkanEventInteropInfo *interop_info); - #ifdef __cplusplus } // extern "C" #endif // __cplusplus diff --git a/c_api/src/taichi_core_impl.cpp b/c_api/src/taichi_core_impl.cpp index 6589ebef706e3..091a5b7768caa 100644 --- a/c_api/src/taichi_core_impl.cpp +++ b/c_api/src/taichi_core_impl.cpp @@ -138,17 +138,6 @@ Runtime &AotModule::runtime() { return *runtime_; } -Event::Event(Runtime &runtime, std::unique_ptr event) - : runtime_(&runtime), event_(std::move(event)) { -} - -taichi::lang::DeviceEvent &Event::get() { - return *event_; -} -Runtime &Event::runtime() { - return *runtime_; -} - // ----------------------------------------------------------------------------- void ti_get_available_archs(uint32_t *arch_count, TiArch *archs) { @@ -470,27 +459,6 @@ void ti_destroy_sampler(TiRuntime runtime, TiSampler sampler) { TI_CAPI_TRY_CATCH_END(); } -TiEvent ti_create_event(TiRuntime runtime) { - TiEvent out = TI_NULL_HANDLE; - TI_CAPI_TRY_CATCH_BEGIN(); - TI_CAPI_ARGUMENT_NULL_RV(runtime); - - Runtime *runtime2 = (Runtime *)runtime; - std::unique_ptr event = - runtime2->get().create_event(); - Event *event2 = new Event(*runtime2, std::move(event)); - out = (TiEvent)event2; - TI_CAPI_TRY_CATCH_END(); - return out; -} -void ti_destroy_event(TiEvent event) { - TI_CAPI_TRY_CATCH_BEGIN(); - TI_CAPI_ARGUMENT_NULL(event); - - delete (Event *)event; - TI_CAPI_TRY_CATCH_END(); -} - void ti_copy_memory_device_to_device(TiRuntime runtime, const TiMemorySlice *dst_memory, const TiMemorySlice *src_memory) { @@ -874,33 +842,6 @@ void ti_launch_compute_graph(TiRuntime runtime, TI_CAPI_TRY_CATCH_END(); } -void ti_signal_event(TiRuntime runtime, TiEvent event) { - TI_CAPI_TRY_CATCH_BEGIN(); - TI_CAPI_ARGUMENT_NULL(runtime); - TI_CAPI_ARGUMENT_NULL(event); - - ((Runtime *)runtime)->signal_event(&((Event *)event)->get()); - TI_CAPI_TRY_CATCH_END(); -} - -void ti_reset_event(TiRuntime runtime, TiEvent event) { - TI_CAPI_TRY_CATCH_BEGIN(); - TI_CAPI_ARGUMENT_NULL(runtime); - TI_CAPI_ARGUMENT_NULL(event); - - ((Runtime *)runtime)->reset_event(&((Event *)event)->get()); - TI_CAPI_TRY_CATCH_END(); -} - -void ti_wait_event(TiRuntime runtime, TiEvent event) { - TI_CAPI_TRY_CATCH_BEGIN(); - TI_CAPI_ARGUMENT_NULL(runtime); - TI_CAPI_ARGUMENT_NULL(event); - - ((Runtime *)runtime)->wait_event(&((Event *)event)->get()); - TI_CAPI_TRY_CATCH_END(); -} - void ti_submit(TiRuntime runtime) { TI_CAPI_TRY_CATCH_BEGIN(); TI_CAPI_ARGUMENT_NULL(runtime); diff --git a/c_api/src/taichi_gfx_impl.cpp b/c_api/src/taichi_gfx_impl.cpp index ea36cced3b961..46b6cfd10741b 100644 --- a/c_api/src/taichi_gfx_impl.cpp +++ b/c_api/src/taichi_gfx_impl.cpp @@ -57,15 +57,6 @@ void GfxRuntime::transition_image(const taichi::lang::DeviceAllocation &image, void GfxRuntime::submit() { get_gfx_runtime().flush(); } -void GfxRuntime::signal_event(taichi::lang::DeviceEvent *event) { - get_gfx_runtime().signal_event(event); -} -void GfxRuntime::reset_event(taichi::lang::DeviceEvent *event) { - get_gfx_runtime().reset_event(event); -} -void GfxRuntime::wait_event(taichi::lang::DeviceEvent *event) { - get_gfx_runtime().wait_event(event); -} void GfxRuntime::wait() { // (penguinliong) It's currently waiting for the entire runtime to stop. // Should be simply waiting for its fence to finish. diff --git a/c_api/src/taichi_vulkan_impl.cpp b/c_api/src/taichi_vulkan_impl.cpp index 992b563ec08f9..426d0ab35145a 100644 --- a/c_api/src/taichi_vulkan_impl.cpp +++ b/c_api/src/taichi_vulkan_impl.cpp @@ -335,42 +335,4 @@ void ti_export_vulkan_image(TiRuntime runtime, TI_CAPI_TRY_CATCH_END(); } -TiEvent ti_import_vulkan_event(TiRuntime runtime, - const TiVulkanEventInteropInfo *interop_info) { - TiEvent out = TI_NULL_HANDLE; - TI_CAPI_TRY_CATCH_BEGIN(); - TI_CAPI_ARGUMENT_NULL_RV(runtime); - TI_CAPI_ARGUMENT_NULL_RV(interop_info); - TI_CAPI_ARGUMENT_NULL_RV(interop_info->event); - TI_CAPI_INVALID_INTEROP_ARCH_RV(((Runtime *)runtime)->arch, vulkan); - - Runtime *runtime2 = (Runtime *)runtime; - - vkapi::IVkEvent event = std::make_unique(); - event->device = runtime2->as_vk()->get_vk().vk_device(); - event->event = interop_info->event; - event->external = true; - - std::unique_ptr event2( - new taichi::lang::vulkan::VulkanDeviceEvent(std::move(event))); - - out = (TiEvent) new Event(*runtime2, std::move(event2)); - TI_CAPI_TRY_CATCH_END(); - return out; -} -void ti_export_vulkan_event(TiRuntime runtime, - TiEvent event, - TiVulkanEventInteropInfo *interop_info) { - TI_CAPI_TRY_CATCH_BEGIN(); - TI_CAPI_ARGUMENT_NULL(runtime); - TI_CAPI_ARGUMENT_NULL(event); - TI_CAPI_ARGUMENT_NULL(interop_info); - TI_CAPI_INVALID_INTEROP_ARCH(((Runtime *)runtime)->arch, vulkan); - - auto event2 = - (taichi::lang::vulkan::VulkanDeviceEvent *)(&((Event *)event)->get()); - interop_info->event = event2->vkapi_ref->event; - TI_CAPI_TRY_CATCH_END(); -} - #endif // TI_WITH_VULKAN diff --git a/c_api/taichi.json b/c_api/taichi.json index 1f080b31a7035..d23e4197266f6 100644 --- a/c_api/taichi.json +++ b/c_api/taichi.json @@ -52,11 +52,6 @@ "type": "handle", "is_dispatchable": true }, - { - "name": "event", - "type": "handle", - "is_dispatchable": true - }, { "name": "memory", "type": "handle", @@ -689,28 +684,6 @@ } ] }, - { - "name": "create_event", - "type": "function", - "parameters": [ - { - "name": "@return", - "type": "handle.event" - }, - { - "type": "handle.runtime" - } - ] - }, - { - "name": "destroy_event", - "type": "function", - "parameters": [ - { - "type": "handle.event" - } - ] - }, { "name": "copy_memory_device_to_device", "type": "function", @@ -829,45 +802,6 @@ } ] }, - { - "name": "signal_event", - "type": "function", - "is_device_command": true, - "parameters": [ - { - "type": "handle.runtime" - }, - { - "type": "handle.event" - } - ] - }, - { - "name": "reset_event", - "type": "function", - "is_device_command": true, - "parameters": [ - { - "type": "handle.runtime" - }, - { - "type": "handle.event" - } - ] - }, - { - "name": "wait_event", - "type": "function", - "is_device_command": true, - "parameters": [ - { - "type": "handle.runtime" - }, - { - "type": "handle.event" - } - ] - }, { "name": "submit", "type": "function", @@ -1164,16 +1098,6 @@ } ] }, - { - "name": "vulkan_event_interop_info", - "type": "structure", - "fields": [ - { - "name": "event", - "type": "VkEvent" - } - ] - }, { "name": "create_vulkan_runtime", "type": "function", @@ -1311,41 +1235,6 @@ "by_mut": true } ] - }, - { - "name": "import_vulkan_event", - "type": "function", - "parameters": [ - { - "name": "@return", - "type": "handle.event" - }, - { - "type": "handle.runtime" - }, - { - "name": "interop_info", - "type": "structure.vulkan_event_interop_info", - "by_ref": true - } - ] - }, - { - "name": "export_vulkan_event", - "type": "function", - "parameters": [ - { - "type": "handle.runtime" - }, - { - "type": "handle.event" - }, - { - "name": "interop_info", - "type": "structure.vulkan_event_interop_info", - "by_mut": true - } - ] } ] }, diff --git a/taichi/rhi/device.h b/taichi/rhi/device.h index 2bbb75ff9a8db..05da052f1ea89 100644 --- a/taichi/rhi/device.h +++ b/taichi/rhi/device.h @@ -422,8 +422,6 @@ class Device { const PipelineSourceDesc &src, std::string name = "Pipeline") = 0; - virtual std::unique_ptr create_event(){TI_NOT_IMPLEMENTED} - std::unique_ptr allocate_memory_unique( const AllocParams ¶ms) { return std::make_unique( diff --git a/taichi/rhi/vulkan/vulkan_api.cpp b/taichi/rhi/vulkan/vulkan_api.cpp index fde2670d83e16..949fd0618100d 100644 --- a/taichi/rhi/vulkan/vulkan_api.cpp +++ b/taichi/rhi/vulkan/vulkan_api.cpp @@ -56,12 +56,6 @@ DeviceObjVkFramebuffer::~DeviceObjVkFramebuffer() { vkDestroyFramebuffer(device, framebuffer, nullptr); } -DeviceObjVkEvent::~DeviceObjVkEvent() { - if (!external) { - vkDestroyEvent(device, event, nullptr); - } -} - DeviceObjVkSemaphore::~DeviceObjVkSemaphore() { vkDestroySemaphore(device, semaphore, nullptr); } @@ -102,22 +96,6 @@ IDeviceObj create_device_obj(VkDevice device) { return obj; } -IVkEvent create_event(VkDevice device, - VkSemaphoreCreateFlags flags, - void *pnext) { - IVkEvent obj = std::make_shared(); - obj->device = device; - - VkEventCreateInfo info{}; - info.sType = VK_STRUCTURE_TYPE_EVENT_CREATE_INFO; - info.pNext = pnext; - info.flags = flags; - - VkResult res = vkCreateEvent(device, &info, nullptr, &obj->event); - BAIL_ON_VK_BAD_RESULT_NO_RETURN(res, "failed to create event"); - return obj; -} - IVkSemaphore create_semaphore(VkDevice device, VkSemaphoreCreateFlags flags, void *pnext) { diff --git a/taichi/rhi/vulkan/vulkan_api.h b/taichi/rhi/vulkan/vulkan_api.h index 840a5b114ba14..a20224aad4e94 100644 --- a/taichi/rhi/vulkan/vulkan_api.h +++ b/taichi/rhi/vulkan/vulkan_api.h @@ -18,17 +18,6 @@ struct DeviceObj { using IDeviceObj = std::shared_ptr; IDeviceObj create_device_obj(VkDevice device); -// VkEvent -struct DeviceObjVkEvent : public DeviceObj { - bool external{false}; - VkEvent event{VK_NULL_HANDLE}; - ~DeviceObjVkEvent() override; -}; -using IVkEvent = std::shared_ptr; -IVkEvent create_event(VkDevice device, - VkEventCreateFlags flags, - void *pnext = nullptr); - // VkSemaphore struct DeviceObjVkSemaphore : public DeviceObj { VkSemaphore semaphore{VK_NULL_HANDLE}; diff --git a/taichi/rhi/vulkan/vulkan_device.cpp b/taichi/rhi/vulkan/vulkan_device.cpp index df9bdb64a4ce3..b080ae1a67457 100644 --- a/taichi/rhi/vulkan/vulkan_device.cpp +++ b/taichi/rhi/vulkan/vulkan_device.cpp @@ -1451,24 +1451,6 @@ void VulkanCommandList::blit_image(DeviceAllocation dst_img, buffer_->refs.push_back(src_vk_image); } -void VulkanCommandList::signal_event(DeviceEvent *event) { - VulkanDeviceEvent *event2 = static_cast(event); - vkCmdSetEvent(buffer_->buffer, event2->vkapi_ref->event, - VK_PIPELINE_STAGE_ALL_COMMANDS_BIT); -} -void VulkanCommandList::reset_event(DeviceEvent *event) { - VulkanDeviceEvent *event2 = static_cast(event); - vkCmdResetEvent(buffer_->buffer, event2->vkapi_ref->event, - VK_PIPELINE_STAGE_ALL_COMMANDS_BIT); -} -void VulkanCommandList::wait_event(DeviceEvent *event) { - VulkanDeviceEvent *event2 = static_cast(event); - vkCmdWaitEvents(buffer_->buffer, 1, &event2->vkapi_ref->event, - VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, - VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, 0, nullptr, 0, nullptr, 0, - nullptr); -} - void VulkanCommandList::set_line_width(float width) { if (ti_device_->vk_caps().wide_line) { vkCmdSetLineWidth(buffer_->buffer, width); @@ -1569,11 +1551,6 @@ std::unique_ptr VulkanDevice::create_pipeline( return std::make_unique(params); } -std::unique_ptr VulkanDevice::create_event() { - return std::unique_ptr( - new VulkanDeviceEvent(vkapi::create_event(device_, 0))); -} - DeviceAllocation VulkanDevice::allocate_memory(const AllocParams ¶ms) { AllocationInternal &alloc = allocations_.acquire(); diff --git a/taichi/rhi/vulkan/vulkan_device.h b/taichi/rhi/vulkan/vulkan_device.h index 6941eb4272c11..d1f133d2002d1 100644 --- a/taichi/rhi/vulkan/vulkan_device.h +++ b/taichi/rhi/vulkan/vulkan_device.h @@ -351,16 +351,6 @@ class VulkanPipeline : public Pipeline { vkapi::IVkPipelineLayout pipeline_layout_{VK_NULL_HANDLE}; }; -class VulkanDeviceEvent : public DeviceEvent { - public: - explicit VulkanDeviceEvent(vkapi::IVkEvent event) : vkapi_ref(event) { - } - ~VulkanDeviceEvent() override { - } - - vkapi::IVkEvent vkapi_ref{nullptr}; -}; - class VulkanCommandList : public CommandList { public: VulkanCommandList(VulkanDevice *ti_device, @@ -597,7 +587,6 @@ class TI_DLL_EXPORT VulkanDevice : public GraphicsDevice { std::unique_ptr create_pipeline( const PipelineSourceDesc &src, std::string name = "Pipeline") override; - std::unique_ptr create_event() override; DeviceAllocation allocate_memory(const AllocParams ¶ms) override; void dealloc_memory(DeviceAllocation handle) override; diff --git a/taichi/runtime/gfx/runtime.cpp b/taichi/runtime/gfx/runtime.cpp index e7170afc29213..525c8ac223d5c 100644 --- a/taichi/runtime/gfx/runtime.cpp +++ b/taichi/runtime/gfx/runtime.cpp @@ -576,22 +576,6 @@ void GfxRuntime::transition_image(DeviceAllocation image, ImageLayout layout) { last_layout = layout; } -void GfxRuntime::signal_event(DeviceEvent *event) { - ensure_current_cmdlist(); - current_cmdlist_->signal_event(event); - submit_current_cmdlist_if_timeout(); -} -void GfxRuntime::reset_event(DeviceEvent *event) { - ensure_current_cmdlist(); - current_cmdlist_->reset_event(event); - submit_current_cmdlist_if_timeout(); -} -void GfxRuntime::wait_event(DeviceEvent *event) { - ensure_current_cmdlist(); - current_cmdlist_->wait_event(event); - submit_current_cmdlist_if_timeout(); -} - void GfxRuntime::synchronize() { flush(); device_->wait_idle(); From 6fc23278cc3bb8d0d2ef3bf24634f665034f97a7 Mon Sep 17 00:00:00 2001 From: PENGUINLIONG Date: Tue, 20 Dec 2022 17:40:09 +0800 Subject: [PATCH 02/12] Remove third party includes --- c_api/include/taichi/taichi.h | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/c_api/include/taichi/taichi.h b/c_api/include/taichi/taichi.h index c02015de0d1b6..6eb5ff4f35ad9 100644 --- a/c_api/include/taichi/taichi.h +++ b/c_api/include/taichi/taichi.h @@ -5,28 +5,14 @@ #include "taichi/taichi_core.h" #ifdef TI_WITH_VULKAN -#ifndef TI_NO_VULKAN_INCLUDES -#include -#endif // TI_NO_VULKAN_INCLUDES - #include "taichi/taichi_vulkan.h" #endif // TI_WITH_VULKAN #ifdef TI_WITH_OPENGL -#ifndef TI_NO_OPENGL_INCLUDES -#include -#endif // TI_NO_OPENGL_INCLUDES - #include "taichi/taichi_opengl.h" #endif // TI_WITH_OPENGL #ifdef TI_WITH_CUDA -#ifndef TI_NO_CUDA_INCLUDES -// Only a few CUDA types is needed, including the entire is overkill -// for this -typedef void *CUdeviceptr; -#endif // TI_NO_CUDA_INCLUDES - #include "taichi/taichi_cuda.h" #endif // TI_WITH_CUDA From bc96ca19bd0479fea9113f7a022c58530a4f6798 Mon Sep 17 00:00:00 2001 From: PENGUINLIONG Date: Tue, 20 Dec 2022 17:45:51 +0800 Subject: [PATCH 03/12] Rename ti_submit to ti_flush --- c_api/docs/taichi/taichi_core.h.md | 8 +-- c_api/include/taichi/cpp/taichi.hpp | 4 +- c_api/include/taichi/taichi_core.h | 15 ++-- c_api/src/taichi_core_impl.cpp | 2 +- c_api/taichi.json | 2 +- c_api/tests/comet.cpp | 2 +- docs/lang/articles/c-api/taichi_core.md | 85 ++--------------------- docs/lang/articles/c-api/taichi_vulkan.md | 40 ----------- 8 files changed, 21 insertions(+), 137 deletions(-) diff --git a/c_api/docs/taichi/taichi_core.h.md b/c_api/docs/taichi/taichi_core.h.md index 5ece6c3cf0e67..9e4513b0920e8 100644 --- a/c_api/docs/taichi/taichi_core.h.md +++ b/c_api/docs/taichi/taichi_core.h.md @@ -116,7 +116,7 @@ TiAotModule aot_module = ti_load_aot_module(runtime, "/path/to/aot/module"); `/path/to/aot/module` should point to the directory that contains a `metadata.tcb`. -You can destroy an unused AOT module, but please ensure that there is no kernel or compute graph related to it pending to [`ti_submit`](#function-ti_submit). +You can destroy an unused AOT module, but please ensure that there is no kernel or compute graph related to it pending to [`ti_flush`](#function-ti_flush). ```cpp ti_destroy_aot_module(aot_module); @@ -177,10 +177,10 @@ named_arg2.argument = args[2]; ti_launch_compute_graph(runtime, compute_graph, named_args.size(), named_args.data()); ``` -When you have launched all kernels and compute graphs for this batch, you should `function.submit` and `function.wait` for the execution to finish. +When you have launched all kernels and compute graphs for this batch, you should `function.flush` and `function.wait` for the execution to finish. ```cpp -ti_submit(runtime); +ti_flush(runtime); ti_wait(runtime); ``` @@ -538,7 +538,7 @@ Sets a signaled event primitive back to an unsignaled state. Waits until an event primitive transitions to a signaled state. The awaited event *must* be signaled by an external procedure or a previous invocation to `function.reset_event`; otherwise, an undefined behavior would occur. -`function.submit` +`function.flush` Submits all previously invoked device commands to the offload device for execution. diff --git a/c_api/include/taichi/cpp/taichi.hpp b/c_api/include/taichi/cpp/taichi.hpp index 1ba71b651fd78..a731b3a87c10d 100644 --- a/c_api/include/taichi/cpp/taichi.hpp +++ b/c_api/include/taichi/cpp/taichi.hpp @@ -1017,8 +1017,8 @@ class Runtime { ti_transition_image(runtime_, image, layout); } - void submit() { - ti_submit(runtime_); + void flush() { + ti_flush(runtime_); } void wait() { ti_wait(runtime_); diff --git a/c_api/include/taichi/taichi_core.h b/c_api/include/taichi/taichi_core.h index 767b116107ef3..6d9104f8f99fc 100644 --- a/c_api/include/taichi/taichi_core.h +++ b/c_api/include/taichi/taichi_core.h @@ -144,7 +144,7 @@ // // You can destroy an unused AOT module, but please ensure that there is no // kernel or compute graph related to it pending to -// [`ti_submit`](#function-ti_submit). +// [`ti_flush`](#function-ti_flush). // // ```cpp // ti_destroy_aot_module(aot_module); @@ -211,11 +211,11 @@ // ``` // // When you have launched all kernels and compute graphs for this batch, you -// should [`ti_submit`](#function-ti_submit) and [`ti_wait`](#function-ti_wait) -// for the execution to finish. +// should `function.flush` and [`ti_wait`](#function-ti_wait) for the execution +// to finish. // // ```cpp -// ti_submit(runtime); +// ti_flush(runtime); // ti_wait(runtime); // ``` // @@ -964,11 +964,8 @@ ti_launch_compute_graph(TiRuntime runtime, uint32_t arg_count, const TiNamedArgument *args); -// Function `ti_submit` -// -// Submits all previously invoked device commands to the offload device for -// execution. -TI_DLL_EXPORT void TI_API_CALL ti_submit(TiRuntime runtime); +// Function `ti_flush` +TI_DLL_EXPORT void TI_API_CALL ti_flush(TiRuntime runtime); // Function `ti_wait` // diff --git a/c_api/src/taichi_core_impl.cpp b/c_api/src/taichi_core_impl.cpp index 091a5b7768caa..36300514bb4c0 100644 --- a/c_api/src/taichi_core_impl.cpp +++ b/c_api/src/taichi_core_impl.cpp @@ -842,7 +842,7 @@ void ti_launch_compute_graph(TiRuntime runtime, TI_CAPI_TRY_CATCH_END(); } -void ti_submit(TiRuntime runtime) { +void ti_flush(TiRuntime runtime) { TI_CAPI_TRY_CATCH_BEGIN(); TI_CAPI_ARGUMENT_NULL(runtime); diff --git a/c_api/taichi.json b/c_api/taichi.json index d23e4197266f6..e1ae5adbfff87 100644 --- a/c_api/taichi.json +++ b/c_api/taichi.json @@ -803,7 +803,7 @@ ] }, { - "name": "submit", + "name": "flush", "type": "function", "parameters": [ { diff --git a/c_api/tests/comet.cpp b/c_api/tests/comet.cpp index 33a390d2f7ac0..a72622486256a 100644 --- a/c_api/tests/comet.cpp +++ b/c_api/tests/comet.cpp @@ -26,7 +26,7 @@ static void comet_run(TiArch arch, const std::string &folder_dir) { g_init["arr"] = arg_array; g_init.launch(); - runtime.submit(); + runtime.flush(); runtime.wait(); for (int i = 0; i < 10000; i++) { g_update["arg"] = arg_array; diff --git a/docs/lang/articles/c-api/taichi_core.md b/docs/lang/articles/c-api/taichi_core.md index 05ec3e6584cee..48d776c5ffe6e 100644 --- a/docs/lang/articles/c-api/taichi_core.md +++ b/docs/lang/articles/c-api/taichi_core.md @@ -116,7 +116,7 @@ TiAotModule aot_module = ti_load_aot_module(runtime, "/path/to/aot/module"); `/path/to/aot/module` should point to the directory that contains a `metadata.tcb`. -You can destroy an unused AOT module, but please ensure that there is no kernel or compute graph related to it pending to [`ti_submit`](#function-ti_submit). +You can destroy an unused AOT module, but please ensure that there is no kernel or compute graph related to it pending to [`ti_flush`](#function-ti_flush). ```cpp ti_destroy_aot_module(aot_module); @@ -177,10 +177,10 @@ named_arg2.argument = args[2]; ti_launch_compute_graph(runtime, compute_graph, named_args.size(), named_args.data()); ``` -When you have launched all kernels and compute graphs for this batch, you should [`ti_submit`](#function-ti_submit) and [`ti_wait`](#function-ti_wait) for the execution to finish. +When you have launched all kernels and compute graphs for this batch, you should [`ti_flush`](#function-ti_flush) and [`ti_wait`](#function-ti_wait) for the execution to finish. ```cpp -ti_submit(runtime); +ti_flush(runtime); ti_wait(runtime); ``` @@ -259,16 +259,6 @@ typedef struct TiAotModule_t* TiAotModule; An ahead-of-time (AOT) compiled Taichi module, which contains a collection of kernels and compute graphs. ---- -### Handle `TiEvent` - -```c -// handle.event -typedef struct TiEvent_t* TiEvent; -``` - -A synchronization primitive to manage device execution flows in multiple queues. - --- ### Handle `TiMemory` @@ -1118,30 +1108,6 @@ TI_DLL_EXPORT void TI_API_CALL ti_destroy_sampler( ); ``` ---- -### Function `ti_create_event` - -```c -// function.create_event -TI_DLL_EXPORT TiEvent TI_API_CALL ti_create_event( - TiRuntime runtime -); -``` - -Creates an event primitive. - ---- -### Function `ti_destroy_event` - -```c -// function.destroy_event -TI_DLL_EXPORT void TI_API_CALL ti_destroy_event( - TiEvent event -); -``` - -Destroys an event primitive. - --- ### Function `ti_copy_memory_device_to_device` (Device Command) @@ -1229,50 +1195,11 @@ TI_DLL_EXPORT void TI_API_CALL ti_launch_compute_graph( Launches a Taichi compute graph with provided named arguments. The named arguments *must* have the same count, names, and types as in the source code. --- -### Function `ti_signal_event` (Device Command) - -```c -// function.signal_event -TI_DLL_EXPORT void TI_API_CALL ti_signal_event( - TiRuntime runtime, - TiEvent event -); -``` - -Sets an event primitive to a signaled state so that the queues waiting for it can go on execution. If the event has been signaled, you *must* call [`ti_reset_event`](#function-ti_reset_event-device-command) to reset it; otherwise, an undefined behavior would occur. - ---- -### Function `ti_reset_event` (Device Command) - -```c -// function.reset_event -TI_DLL_EXPORT void TI_API_CALL ti_reset_event( - TiRuntime runtime, - TiEvent event -); -``` - -Sets a signaled event primitive back to an unsignaled state. - ---- -### Function `ti_wait_event` (Device Command) - -```c -// function.wait_event -TI_DLL_EXPORT void TI_API_CALL ti_wait_event( - TiRuntime runtime, - TiEvent event -); -``` - -Waits until an event primitive transitions to a signaled state. The awaited event *must* be signaled by an external procedure or a previous invocation to [`ti_reset_event`](#function-ti_reset_event-device-command); otherwise, an undefined behavior would occur. - ---- -### Function `ti_submit` +### Function `ti_flush` ```c -// function.submit -TI_DLL_EXPORT void TI_API_CALL ti_submit( +// function.flush +TI_DLL_EXPORT void TI_API_CALL ti_flush( TiRuntime runtime ); ``` diff --git a/docs/lang/articles/c-api/taichi_vulkan.md b/docs/lang/articles/c-api/taichi_vulkan.md index 5ec2bfc36528a..282e4b024b0a4 100644 --- a/docs/lang/articles/c-api/taichi_vulkan.md +++ b/docs/lang/articles/c-api/taichi_vulkan.md @@ -91,20 +91,6 @@ Necessary detail to share the same piece of Vulkan image between Taichi and exte - `tiling`: Image tiling. - `usage`: Vulkan image usage. In most cases, Taichi requires the `VK_IMAGE_USAGE_STORAGE_BIT` and the `VK_IMAGE_USAGE_SAMPLED_BIT`. ---- -### Structure `TiVulkanEventInteropInfo` - -```c -// structure.vulkan_event_interop_info -typedef struct TiVulkanEventInteropInfo { - VkEvent event; -} TiVulkanEventInteropInfo; -``` - -Necessary detail to share the same Vulkan event synchronization primitive between Taichi and the user application. - -- `event`: Vulkan event handle. - --- ### Function `ti_create_vulkan_runtime_ext` @@ -202,29 +188,3 @@ TI_DLL_EXPORT void TI_API_CALL ti_export_vulkan_image( Exports a Vulkan image from external procedures to Taichi. ---- -### Function `ti_import_vulkan_event` - -```c -// function.import_vulkan_event -TI_DLL_EXPORT TiEvent TI_API_CALL ti_import_vulkan_event( - TiRuntime runtime, - const TiVulkanEventInteropInfo* interop_info -); -``` - -Imports the Vulkan event owned by Taichi to external procedures. - ---- -### Function `ti_export_vulkan_event` - -```c -// function.export_vulkan_event -TI_DLL_EXPORT void TI_API_CALL ti_export_vulkan_event( - TiRuntime runtime, - TiEvent event, - TiVulkanEventInteropInfo* interop_info -); -``` - -Exports a Vulkan event from external procedures to Taichi. From c6460789fe8e6c8a5137dc06b03175b1546e1d90 Mon Sep 17 00:00:00 2001 From: PENGUINLIONG Date: Tue, 20 Dec 2022 18:00:44 +0800 Subject: [PATCH 04/12] Redefine ti_create_runtime --- c_api/docs/taichi/taichi_core.h.md | 2 +- c_api/include/taichi/cpp/taichi.hpp | 2 +- c_api/include/taichi/taichi_core.h | 12 ++++++++---- c_api/src/taichi_core_impl.cpp | 4 +++- c_api/taichi.json | 4 ++++ docs/lang/articles/c-api/taichi_core.md | 5 +++-- 6 files changed, 20 insertions(+), 9 deletions(-) diff --git a/c_api/docs/taichi/taichi_core.h.md b/c_api/docs/taichi/taichi_core.h.md index 9e4513b0920e8..a5b9f558c26f8 100644 --- a/c_api/docs/taichi/taichi_core.h.md +++ b/c_api/docs/taichi/taichi_core.h.md @@ -35,7 +35,7 @@ The following section provides a brief introduction to the Taichi C-API. You *must* create a runtime instance before working with Taichi, and *only* one runtime per thread. Currently, we do not officially claim that multiple runtime instances can coexist in a process, but please feel free to [file an issue with us](https://github.com/taichi-dev/taichi/issues) if you run into any problem with runtime instance coexistence. ```cpp -TiRuntime runtime = ti_create_runtime(TI_ARCH_VULKAN); +TiRuntime runtime = ti_create_runtime(TI_ARCH_VULKAN, 0); ``` When your program runs to the end, ensure that: diff --git a/c_api/include/taichi/cpp/taichi.hpp b/c_api/include/taichi/cpp/taichi.hpp index a731b3a87c10d..5db6d133366e8 100644 --- a/c_api/include/taichi/cpp/taichi.hpp +++ b/c_api/include/taichi/cpp/taichi.hpp @@ -884,7 +884,7 @@ class Runtime { should_destroy_(std::exchange(b.should_destroy_, false)) { } Runtime(TiArch arch) - : arch_(arch), runtime_(ti_create_runtime(arch)), should_destroy_(true) { + : arch_(arch), runtime_(ti_create_runtime(arch, 0)), should_destroy_(true) { } Runtime(TiArch arch, TiRuntime runtime, bool should_destroy) : arch_(arch), runtime_(runtime), should_destroy_(should_destroy) { diff --git a/c_api/include/taichi/taichi_core.h b/c_api/include/taichi/taichi_core.h index 6d9104f8f99fc..645309b87ce29 100644 --- a/c_api/include/taichi/taichi_core.h +++ b/c_api/include/taichi/taichi_core.h @@ -48,7 +48,7 @@ // any problem with runtime instance coexistence. // // ```cpp -// TiRuntime runtime = ti_create_runtime(TI_ARCH_VULKAN); +// TiRuntime runtime = ti_create_runtime(TI_ARCH_VULKAN, 0); // ``` // // When your program runs to the end, ensure that: @@ -211,8 +211,8 @@ // ``` // // When you have launched all kernels and compute graphs for this batch, you -// should `function.flush` and [`ti_wait`](#function-ti_wait) for the execution -// to finish. +// should [`ti_flush`](#function-ti_flush) and [`ti_wait`](#function-ti_wait) +// for the execution to finish. // // ```cpp // ti_flush(runtime); @@ -839,7 +839,8 @@ TI_DLL_EXPORT void TI_API_CALL ti_set_last_error( // Function `ti_create_runtime` // // Creates a Taichi Runtime with the specified [`TiArch`](#enumeration-tiarch). -TI_DLL_EXPORT TiRuntime TI_API_CALL ti_create_runtime(TiArch arch); +TI_DLL_EXPORT TiRuntime TI_API_CALL ti_create_runtime(TiArch arch, + uint32_t device_index); // Function `ti_destroy_runtime` // @@ -965,6 +966,9 @@ ti_launch_compute_graph(TiRuntime runtime, const TiNamedArgument *args); // Function `ti_flush` +// +// Submits all previously invoked device commands to the offload device for +// execution. TI_DLL_EXPORT void TI_API_CALL ti_flush(TiRuntime runtime); // Function `ti_wait` diff --git a/c_api/src/taichi_core_impl.cpp b/c_api/src/taichi_core_impl.cpp index 36300514bb4c0..d0523c78159c0 100644 --- a/c_api/src/taichi_core_impl.cpp +++ b/c_api/src/taichi_core_impl.cpp @@ -208,9 +208,11 @@ void ti_set_last_error(TiError error, const char *message) { TI_CAPI_TRY_CATCH_END(); } -TiRuntime ti_create_runtime(TiArch arch) { +TiRuntime ti_create_runtime(TiArch arch, uint32_t device_index) { TiRuntime out = TI_NULL_HANDLE; TI_CAPI_TRY_CATCH_BEGIN(); + // FIXME: (penguinliong) Support device selection. + TI_CAPI_NOT_SUPPORTED_IF_RV(device_index != 0); switch (arch) { #ifdef TI_WITH_VULKAN case TI_ARCH_VULKAN: { diff --git a/c_api/taichi.json b/c_api/taichi.json index e1ae5adbfff87..94d7ea041afa2 100644 --- a/c_api/taichi.json +++ b/c_api/taichi.json @@ -515,6 +515,10 @@ }, { "type": "enumeration.arch" + }, + { + "name": "device_index", + "type": "uint32_t" } ] }, diff --git a/docs/lang/articles/c-api/taichi_core.md b/docs/lang/articles/c-api/taichi_core.md index 48d776c5ffe6e..259f068b387eb 100644 --- a/docs/lang/articles/c-api/taichi_core.md +++ b/docs/lang/articles/c-api/taichi_core.md @@ -35,7 +35,7 @@ The following section provides a brief introduction to the Taichi C-API. You *must* create a runtime instance before working with Taichi, and *only* one runtime per thread. Currently, we do not officially claim that multiple runtime instances can coexist in a process, but please feel free to [file an issue with us](https://github.com/taichi-dev/taichi/issues) if you run into any problem with runtime instance coexistence. ```cpp -TiRuntime runtime = ti_create_runtime(TI_ARCH_VULKAN); +TiRuntime runtime = ti_create_runtime(TI_ARCH_VULKAN, 0); ``` When your program runs to the end, ensure that: @@ -961,7 +961,8 @@ Sets the provided error as the last error raised by Taichi C-API invocations. It ```c // function.create_runtime TI_DLL_EXPORT TiRuntime TI_API_CALL ti_create_runtime( - TiArch arch + TiArch arch, + uint32_t device_index ); ``` From 0c0f18971fd83b08701668c28b072bfda21ae658 Mon Sep 17 00:00:00 2001 From: PENGUINLIONG Date: Thu, 22 Dec 2022 10:36:04 +0800 Subject: [PATCH 05/12] Fixed behavior tests --- c_api/tests/c_api_behavior_test.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/c_api/tests/c_api_behavior_test.cpp b/c_api/tests/c_api_behavior_test.cpp index 8165e3e15e413..686ee21368646 100644 --- a/c_api/tests/c_api_behavior_test.cpp +++ b/c_api/tests/c_api_behavior_test.cpp @@ -8,7 +8,7 @@ TEST_F(CapiTest, TestBehaviorCreateRuntime) { auto inner = [this](TiArch arch) { - TiRuntime runtime = ti_create_runtime(arch); + TiRuntime runtime = ti_create_runtime(arch, 0); TI_ASSERT(runtime == TI_NULL_HANDLE); EXPECT_TAICHI_ERROR(TI_ERROR_NOT_SUPPORTED); }; From 45e2a4bfc414ea1dab9e67b9e129526e414de8f6 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 22 Dec 2022 02:52:50 +0000 Subject: [PATCH 06/12] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- c_api/include/taichi/cpp/taichi.hpp | 4 +++- docs/lang/articles/c-api/taichi_vulkan.md | 1 - 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/c_api/include/taichi/cpp/taichi.hpp b/c_api/include/taichi/cpp/taichi.hpp index 5db6d133366e8..4971c0f900cca 100644 --- a/c_api/include/taichi/cpp/taichi.hpp +++ b/c_api/include/taichi/cpp/taichi.hpp @@ -884,7 +884,9 @@ class Runtime { should_destroy_(std::exchange(b.should_destroy_, false)) { } Runtime(TiArch arch) - : arch_(arch), runtime_(ti_create_runtime(arch, 0)), should_destroy_(true) { + : arch_(arch), + runtime_(ti_create_runtime(arch, 0)), + should_destroy_(true) { } Runtime(TiArch arch, TiRuntime runtime, bool should_destroy) : arch_(arch), runtime_(runtime), should_destroy_(should_destroy) { diff --git a/docs/lang/articles/c-api/taichi_vulkan.md b/docs/lang/articles/c-api/taichi_vulkan.md index 282e4b024b0a4..f6b9d85028ec2 100644 --- a/docs/lang/articles/c-api/taichi_vulkan.md +++ b/docs/lang/articles/c-api/taichi_vulkan.md @@ -187,4 +187,3 @@ TI_DLL_EXPORT void TI_API_CALL ti_export_vulkan_image( ``` Exports a Vulkan image from external procedures to Taichi. - From 4d08a13e815690edc4595182543442fd1f94a704 Mon Sep 17 00:00:00 2001 From: PENGUINLIONG Date: Thu, 22 Dec 2022 10:54:57 +0800 Subject: [PATCH 07/12] Fixed --- c_api/include/taichi/cpp/taichi.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/c_api/include/taichi/cpp/taichi.hpp b/c_api/include/taichi/cpp/taichi.hpp index 5db6d133366e8..146efb88d68ad 100644 --- a/c_api/include/taichi/cpp/taichi.hpp +++ b/c_api/include/taichi/cpp/taichi.hpp @@ -883,8 +883,8 @@ class Runtime { runtime_(detail::move_handle(b.runtime_)), should_destroy_(std::exchange(b.should_destroy_, false)) { } - Runtime(TiArch arch) - : arch_(arch), runtime_(ti_create_runtime(arch, 0)), should_destroy_(true) { + Runtime(TiArch arch, uint32_t device_index = 0) + : arch_(arch), runtime_(ti_create_runtime(arch, device_index)), should_destroy_(true) { } Runtime(TiArch arch, TiRuntime runtime, bool should_destroy) : arch_(arch), runtime_(runtime), should_destroy_(should_destroy) { From 993865a89c636318b15f2af029b209d6e5ffc74e Mon Sep 17 00:00:00 2001 From: PENGUINLIONG Date: Thu, 22 Dec 2022 11:17:04 +0800 Subject: [PATCH 08/12] Fixed --- c_api/docs/taichi/taichi_core.h.md | 12 ------------ c_api/src/taichi_core_impl.cpp | 2 +- c_api/src/taichi_core_impl.h | 22 +--------------------- c_api/src/taichi_gfx_impl.cpp | 2 +- c_api/src/taichi_gfx_impl.h | 5 +---- c_api/src/taichi_llvm_impl.cpp | 4 ++-- c_api/src/taichi_llvm_impl.h | 2 +- taichi/rhi/device.h | 15 --------------- taichi/rhi/vulkan/vulkan_device.h | 4 ---- taichi/runtime/gfx/runtime.h | 4 ---- 10 files changed, 7 insertions(+), 65 deletions(-) diff --git a/c_api/docs/taichi/taichi_core.h.md b/c_api/docs/taichi/taichi_core.h.md index a5b9f558c26f8..414d5f5ea3535 100644 --- a/c_api/docs/taichi/taichi_core.h.md +++ b/c_api/docs/taichi/taichi_core.h.md @@ -526,18 +526,6 @@ Launches a Taichi kernel with the provided arguments. The arguments *must* have Launches a Taichi compute graph with provided named arguments. The named arguments *must* have the same count, names, and types as in the source code. -`function.signal_event` - -Sets an event primitive to a signaled state so that the queues waiting for it can go on execution. If the event has been signaled, you *must* call `function.reset_event` to reset it; otherwise, an undefined behavior would occur. - -`function.reset_event` - -Sets a signaled event primitive back to an unsignaled state. - -`function.wait_event` - -Waits until an event primitive transitions to a signaled state. The awaited event *must* be signaled by an external procedure or a previous invocation to `function.reset_event`; otherwise, an undefined behavior would occur. - `function.flush` Submits all previously invoked device commands to the offload device for execution. diff --git a/c_api/src/taichi_core_impl.cpp b/c_api/src/taichi_core_impl.cpp index d0523c78159c0..1bae3ecb365cf 100644 --- a/c_api/src/taichi_core_impl.cpp +++ b/c_api/src/taichi_core_impl.cpp @@ -848,7 +848,7 @@ void ti_flush(TiRuntime runtime) { TI_CAPI_TRY_CATCH_BEGIN(); TI_CAPI_ARGUMENT_NULL(runtime); - ((Runtime *)runtime)->submit(); + ((Runtime *)runtime)->flush(); TI_CAPI_TRY_CATCH_END(); } void ti_wait(TiRuntime runtime) { diff --git a/c_api/src/taichi_core_impl.h b/c_api/src/taichi_core_impl.h index b7fcf57b94353..02eb3ba54213f 100644 --- a/c_api/src/taichi_core_impl.h +++ b/c_api/src/taichi_core_impl.h @@ -169,16 +169,7 @@ class Runtime { taichi::lang::ImageLayout layout) { TI_NOT_IMPLEMENTED } - virtual void signal_event(taichi::lang::DeviceEvent *event) { - TI_NOT_IMPLEMENTED - } - virtual void reset_event(taichi::lang::DeviceEvent *event) { - TI_NOT_IMPLEMENTED - } - virtual void wait_event(taichi::lang::DeviceEvent *event) { - TI_NOT_IMPLEMENTED - } - virtual void submit() = 0; + virtual void flush() = 0; virtual void wait() = 0; class VulkanRuntime *as_vk(); @@ -201,17 +192,6 @@ class AotModule { Runtime &runtime(); }; -class Event { - Runtime *runtime_; - std::unique_ptr event_; - - public: - Event(Runtime &runtime, std::unique_ptr event); - - taichi::lang::DeviceEvent &get(); - Runtime &runtime(); -}; - namespace { template diff --git a/c_api/src/taichi_gfx_impl.cpp b/c_api/src/taichi_gfx_impl.cpp index 46b6cfd10741b..f485625b09408 100644 --- a/c_api/src/taichi_gfx_impl.cpp +++ b/c_api/src/taichi_gfx_impl.cpp @@ -54,7 +54,7 @@ void GfxRuntime::transition_image(const taichi::lang::DeviceAllocation &image, taichi::lang::ImageLayout layout) { get_gfx_runtime().transition_image(image, layout); } -void GfxRuntime::submit() { +void GfxRuntime::flush() { get_gfx_runtime().flush(); } void GfxRuntime::wait() { diff --git a/c_api/src/taichi_gfx_impl.h b/c_api/src/taichi_gfx_impl.h index 86aeb4a3cb78c..e665098ee74cc 100644 --- a/c_api/src/taichi_gfx_impl.h +++ b/c_api/src/taichi_gfx_impl.h @@ -27,9 +27,6 @@ class GfxRuntime : public Runtime { virtual void transition_image( const taichi::lang::DeviceAllocation &image, taichi::lang::ImageLayout layout) override final; - virtual void signal_event(taichi::lang::DeviceEvent *event) override final; - virtual void reset_event(taichi::lang::DeviceEvent *event) override final; - virtual void wait_event(taichi::lang::DeviceEvent *event) override final; - virtual void submit() override final; + virtual void flush() override final; virtual void wait() override final; }; diff --git a/c_api/src/taichi_llvm_impl.cpp b/c_api/src/taichi_llvm_impl.cpp index e83b2382e7a83..ced0c4cf916fc 100644 --- a/c_api/src/taichi_llvm_impl.cpp +++ b/c_api/src/taichi_llvm_impl.cpp @@ -125,8 +125,8 @@ void LlvmRuntime::buffer_copy(const taichi::lang::DevicePtr &dst, TI_NOT_IMPLEMENTED; } -void LlvmRuntime::submit() { - // (penguinliong) Submit in LLVM backends is a nop atm. +void LlvmRuntime::flush() { + // (penguinliong) Flush in LLVM backends is a nop atm. // TI_NOT_IMPLEMENTED; } diff --git a/c_api/src/taichi_llvm_impl.h b/c_api/src/taichi_llvm_impl.h index 51e990810bdd0..1081b6e849d23 100644 --- a/c_api/src/taichi_llvm_impl.h +++ b/c_api/src/taichi_llvm_impl.h @@ -33,7 +33,7 @@ class LlvmRuntime : public Runtime { const taichi::lang::DevicePtr &src, size_t size) override; - void submit() override; + void flush() override; void wait() override; diff --git a/taichi/rhi/device.h b/taichi/rhi/device.h index 05da052f1ea89..299a01510925f 100644 --- a/taichi/rhi/device.h +++ b/taichi/rhi/device.h @@ -232,12 +232,6 @@ struct ImageCopyParams { uint32_t depth{1}; }; -class DeviceEvent { - public: - virtual ~DeviceEvent() { - } -}; - class CommandList { public: virtual ~CommandList() { @@ -334,15 +328,6 @@ class CommandList { const ImageCopyParams ¶ms) { TI_NOT_IMPLEMENTED } - virtual void signal_event(DeviceEvent *event) { - TI_NOT_IMPLEMENTED - } - virtual void reset_event(DeviceEvent *event) { - TI_NOT_IMPLEMENTED - } - virtual void wait_event(DeviceEvent *event) { - TI_NOT_IMPLEMENTED - } }; struct PipelineSourceDesc { diff --git a/taichi/rhi/vulkan/vulkan_device.h b/taichi/rhi/vulkan/vulkan_device.h index d1f133d2002d1..9818c965a8321 100644 --- a/taichi/rhi/vulkan/vulkan_device.h +++ b/taichi/rhi/vulkan/vulkan_device.h @@ -415,10 +415,6 @@ class VulkanCommandList : public CommandList { ImageLayout src_img_layout, const ImageCopyParams ¶ms) override; - void signal_event(DeviceEvent *event) override; - void reset_event(DeviceEvent *event) override; - void wait_event(DeviceEvent *event) override; - vkapi::IVkRenderPass current_renderpass(); // Vulkan specific functions diff --git a/taichi/runtime/gfx/runtime.h b/taichi/runtime/gfx/runtime.h index 86dafc33d5ec3..ceb660c1cf09d 100644 --- a/taichi/runtime/gfx/runtime.h +++ b/taichi/runtime/gfx/runtime.h @@ -110,10 +110,6 @@ class TI_DLL_EXPORT GfxRuntime { void untrack_image(DeviceAllocation image); void transition_image(DeviceAllocation image, ImageLayout layout); - void signal_event(DeviceEvent *event); - void reset_event(DeviceEvent *event); - void wait_event(DeviceEvent *event); - void synchronize(); StreamSemaphore flush(); From c12d11b2ea17213357b3e3659d24a12791472570 Mon Sep 17 00:00:00 2001 From: PENGUINLIONG Date: Thu, 22 Dec 2022 20:16:28 +0800 Subject: [PATCH 09/12] Fix include --- .github/workflows/scripts/aot-demo.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/scripts/aot-demo.sh b/.github/workflows/scripts/aot-demo.sh index 7c5071a61e362..72c437d7cb78b 100755 --- a/.github/workflows/scripts/aot-demo.sh +++ b/.github/workflows/scripts/aot-demo.sh @@ -8,7 +8,7 @@ export TAICHI_AOT_DEMO_URL=https://github.com/taichi-dev/taichi-aot-demo export TAICHI_AOT_DEMO_BRANCH=master export TAICHI_UNITY2_URL=https://github.com/taichi-dev/taichi-unity2 -export TAICHI_UNITY2_BRANCH=main +export TAICHI_UNITY2_BRANCH=fix-include export TAICHI_UNITY_EXAMPLE_URL=https://github.com/taichi-dev/Taichi-UnityExample export TAICHI_UNITY_EXAMPLE_BRANCH=main From e19bdb3c603ed686f7ce74ee34428400dbb6d304 Mon Sep 17 00:00:00 2001 From: PENGUINLIONG Date: Thu, 22 Dec 2022 22:57:30 +0800 Subject: [PATCH 10/12] Fixed AOT demo --- .github/workflows/scripts/aot-demo.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/scripts/aot-demo.sh b/.github/workflows/scripts/aot-demo.sh index 72c437d7cb78b..f949c63f4b7c5 100755 --- a/.github/workflows/scripts/aot-demo.sh +++ b/.github/workflows/scripts/aot-demo.sh @@ -4,8 +4,8 @@ set -ex export TI_SKIP_VERSION_CHECK=ON export TI_CI=1 -export TAICHI_AOT_DEMO_URL=https://github.com/taichi-dev/taichi-aot-demo -export TAICHI_AOT_DEMO_BRANCH=master +export TAICHI_AOT_DEMO_URL=https://github.com/PENGUINLIONG/taichi-aot-demo +export TAICHI_AOT_DEMO_BRANCH=fix-cgraph-demo export TAICHI_UNITY2_URL=https://github.com/taichi-dev/taichi-unity2 export TAICHI_UNITY2_BRANCH=fix-include From e265c0383fd29544ab617c1f1f5fbb1e4c4d30e4 Mon Sep 17 00:00:00 2001 From: PENGUINLIONG Date: Fri, 23 Dec 2022 14:42:26 +0800 Subject: [PATCH 11/12] Docs --- c_api/docs/taichi/taichi_core.h.md | 4 ++++ c_api/include/taichi/taichi_core.h | 9 +++++++-- docs/lang/articles/c-api/taichi_core.md | 4 ++++ docs/lang/articles/c-api/taichi_vulkan.md | 1 + 4 files changed, 16 insertions(+), 2 deletions(-) diff --git a/c_api/docs/taichi/taichi_core.h.md b/c_api/docs/taichi/taichi_core.h.md index 414d5f5ea3535..02026722923af 100644 --- a/c_api/docs/taichi/taichi_core.h.md +++ b/c_api/docs/taichi/taichi_core.h.md @@ -35,6 +35,7 @@ The following section provides a brief introduction to the Taichi C-API. You *must* create a runtime instance before working with Taichi, and *only* one runtime per thread. Currently, we do not officially claim that multiple runtime instances can coexist in a process, but please feel free to [file an issue with us](https://github.com/taichi-dev/taichi/issues) if you run into any problem with runtime instance coexistence. ```cpp +// Create a Taichi Runtime on Vulkan device at index 0. TiRuntime runtime = ti_create_runtime(TI_ARCH_VULKAN, 0); ``` @@ -467,6 +468,9 @@ Sets the provided error as the last error raised by Taichi C-API invocations. It Creates a Taichi Runtime with the specified `enumeration.arch`. +- `function.create_runtime.arch`: Arch of Taichi Runtime. +- `function.create_runtime.device_index`: The index of device in `function.create_runtime.arch` to create Taichi Runtime on. + `function.destroy_runtime` Destroys a Taichi Runtime. diff --git a/c_api/include/taichi/taichi_core.h b/c_api/include/taichi/taichi_core.h index 645309b87ce29..02739964e3644 100644 --- a/c_api/include/taichi/taichi_core.h +++ b/c_api/include/taichi/taichi_core.h @@ -48,6 +48,7 @@ // any problem with runtime instance coexistence. // // ```cpp +// // Create a Taichi Runtime on Vulkan device at index 0. // TiRuntime runtime = ti_create_runtime(TI_ARCH_VULKAN, 0); // ``` // @@ -839,8 +840,12 @@ TI_DLL_EXPORT void TI_API_CALL ti_set_last_error( // Function `ti_create_runtime` // // Creates a Taichi Runtime with the specified [`TiArch`](#enumeration-tiarch). -TI_DLL_EXPORT TiRuntime TI_API_CALL ti_create_runtime(TiArch arch, - uint32_t device_index); +TI_DLL_EXPORT TiRuntime TI_API_CALL ti_create_runtime( + // Arch of Taichi Runtime. + TiArch arch, + // The index of device in `function.create_runtime.arch` to create Taichi + // Runtime on. + uint32_t device_index); // Function `ti_destroy_runtime` // diff --git a/docs/lang/articles/c-api/taichi_core.md b/docs/lang/articles/c-api/taichi_core.md index 259f068b387eb..704746a448cc9 100644 --- a/docs/lang/articles/c-api/taichi_core.md +++ b/docs/lang/articles/c-api/taichi_core.md @@ -35,6 +35,7 @@ The following section provides a brief introduction to the Taichi C-API. You *must* create a runtime instance before working with Taichi, and *only* one runtime per thread. Currently, we do not officially claim that multiple runtime instances can coexist in a process, but please feel free to [file an issue with us](https://github.com/taichi-dev/taichi/issues) if you run into any problem with runtime instance coexistence. ```cpp +// Create a Taichi Runtime on Vulkan device at index 0. TiRuntime runtime = ti_create_runtime(TI_ARCH_VULKAN, 0); ``` @@ -968,6 +969,9 @@ TI_DLL_EXPORT TiRuntime TI_API_CALL ti_create_runtime( Creates a Taichi Runtime with the specified [`TiArch`](#enumeration-tiarch). +- `arch`: Arch of Taichi Runtime. +- `device_index`: The index of device in `arch` to create Taichi Runtime on. + --- ### Function `ti_destroy_runtime` diff --git a/docs/lang/articles/c-api/taichi_vulkan.md b/docs/lang/articles/c-api/taichi_vulkan.md index f6b9d85028ec2..282e4b024b0a4 100644 --- a/docs/lang/articles/c-api/taichi_vulkan.md +++ b/docs/lang/articles/c-api/taichi_vulkan.md @@ -187,3 +187,4 @@ TI_DLL_EXPORT void TI_API_CALL ti_export_vulkan_image( ``` Exports a Vulkan image from external procedures to Taichi. + From ca84be4e4ba165d036b47bb296674b8acdf52312 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 23 Dec 2022 06:43:46 +0000 Subject: [PATCH 12/12] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- docs/lang/articles/c-api/taichi_vulkan.md | 1 - 1 file changed, 1 deletion(-) diff --git a/docs/lang/articles/c-api/taichi_vulkan.md b/docs/lang/articles/c-api/taichi_vulkan.md index 282e4b024b0a4..f6b9d85028ec2 100644 --- a/docs/lang/articles/c-api/taichi_vulkan.md +++ b/docs/lang/articles/c-api/taichi_vulkan.md @@ -187,4 +187,3 @@ TI_DLL_EXPORT void TI_API_CALL ti_export_vulkan_image( ``` Exports a Vulkan image from external procedures to Taichi. -