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

[aot] [vulkan] Expose symbols for AOT #4879

Merged
merged 4 commits into from
Apr 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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;
k-ye marked this conversation as resolved.
Show resolved Hide resolved
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