Skip to content

Commit

Permalink
[aot] [vulkan] Expose symbols for AOT (taichi-dev#4879)
Browse files Browse the repository at this point in the history
* [aot] [vulkan] Expose symbols for AOT

* weird windows

* hide to make win happy

* fix
  • Loading branch information
k-ye committed May 5, 2022
1 parent bd0c188 commit 9d94c01
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 22 deletions.
2 changes: 1 addition & 1 deletion taichi/backends/device.h
Original file line number Diff line number Diff line change
Expand Up @@ -584,7 +584,7 @@ struct RasterParams {
std::vector<BlendingParams> blending{};
};

class GraphicsDevice : public Device {
class TI_DLL_EXPORT GraphicsDevice : public Device {
public:
virtual std::unique_ptr<Pipeline> create_raster_pipeline(
const std::vector<PipelineSourceDesc> &src,
Expand Down
37 changes: 23 additions & 14 deletions taichi/backends/vulkan/vulkan_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1224,6 +1224,15 @@ vkapi::IVkCommandBuffer VulkanCommandList::finalize() {
return buffer_;
}

struct VulkanDevice::ThreadLocalStreams {
unordered_map<std::thread::id, std::unique_ptr<VulkanStream>> map;
};

VulkanDevice::VulkanDevice()
: compute_streams_(std::make_unique<ThreadLocalStreams>()),
graphics_streams_(std::make_unique<ThreadLocalStreams>()) {
}

void VulkanDevice::init_vulkan_structs(Params &params) {
instance_ = params.instance;
device_ = params.device;
Expand Down Expand Up @@ -1479,33 +1488,33 @@ void VulkanDevice::memcpy_internal(DevicePtr dst,

Stream *VulkanDevice::get_compute_stream() {
auto tid = std::this_thread::get_id();
auto iter = compute_stream_.find(tid);
if (iter == compute_stream_.end()) {
compute_stream_[tid] = std::make_unique<VulkanStream>(
auto &stream_map = compute_streams_->map;
auto iter = stream_map.find(tid);
if (iter == stream_map.end()) {
stream_map[tid] = std::make_unique<VulkanStream>(
*this, compute_queue_, compute_queue_family_index_);
return compute_stream_.at(tid).get();
} else {
return iter->second.get();
return stream_map.at(tid).get();
}
return iter->second.get();
}

Stream *VulkanDevice::get_graphics_stream() {
auto tid = std::this_thread::get_id();
auto iter = graphics_stream_.find(tid);
if (iter == graphics_stream_.end()) {
graphics_stream_[tid] = std::make_unique<VulkanStream>(
auto &stream_map = graphics_streams_->map;
auto iter = stream_map.find(tid);
if (iter == stream_map.end()) {
stream_map[tid] = std::make_unique<VulkanStream>(
*this, graphics_queue_, graphics_queue_family_index_);
return graphics_stream_.at(tid).get();
} else {
return iter->second.get();
return stream_map.at(tid).get();
}
return iter->second.get();
}

void VulkanDevice::wait_idle() {
for (auto &[tid, stream] : compute_stream_) {
for (auto &[tid, stream] : compute_streams_->map) {
stream->command_sync();
}
for (auto &[tid, stream] : graphics_stream_) {
for (auto &[tid, stream] : graphics_streams_->map) {
stream->command_sync();
}
}
Expand Down
13 changes: 7 additions & 6 deletions taichi/backends/vulkan/vulkan_device.h
Original file line number Diff line number Diff line change
Expand Up @@ -516,9 +516,7 @@ class VulkanStream : public Stream {
std::vector<TrackedCmdbuf> submitted_cmdbuffers_;
};

class VulkanDevice : public GraphicsDevice {
friend VulkanSurface;

class TI_DLL_EXPORT VulkanDevice : public GraphicsDevice {
public:
struct Params {
VkInstance instance;
Expand All @@ -530,6 +528,7 @@ class VulkanDevice : public GraphicsDevice {
uint32_t graphics_queue_family_index;
};

VulkanDevice();
void init_vulkan_structs(Params &params);
~VulkanDevice() override;

Expand Down Expand Up @@ -620,6 +619,8 @@ class VulkanDevice : public GraphicsDevice {
vkapi::IVkDescriptorSet alloc_desc_set(vkapi::IVkDescriptorSetLayout layout);

private:
friend VulkanSurface;

void create_vma_allocator();
void new_descriptor_pool();

Expand All @@ -635,9 +636,9 @@ class VulkanDevice : public GraphicsDevice {
VkQueue graphics_queue_;
uint32_t graphics_queue_family_index_;

unordered_map<std::thread::id, std::unique_ptr<VulkanStream>> compute_stream_;
unordered_map<std::thread::id, std::unique_ptr<VulkanStream>>
graphics_stream_;
struct ThreadLocalStreams;
std::unique_ptr<ThreadLocalStreams> compute_streams_{nullptr};
std::unique_ptr<ThreadLocalStreams> graphics_streams_{nullptr};

// Memory allocation
struct AllocationInternal {
Expand Down
2 changes: 1 addition & 1 deletion taichi/backends/vulkan/vulkan_loader.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace taichi {
namespace lang {
namespace vulkan {

class VulkanLoader {
class TI_DLL_EXPORT VulkanLoader {
public:
static VulkanLoader &instance() {
static VulkanLoader instance;
Expand Down

0 comments on commit 9d94c01

Please sign in to comment.