Skip to content
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
4 changes: 4 additions & 0 deletions backends/vulkan/runtime/VulkanBackend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -621,6 +621,10 @@ class VulkanBackend final : public ::executorch::runtime::BackendInterface {
void destroy(DelegateHandle* handle) const override {
if (handle != nullptr) {
ComputeGraph* compute_graph = static_cast<ComputeGraph*>(handle);
compute_graph->context()
->adapter_ptr()
->compute_pipeline_cache()
.save_cache();
// ComputeGraph is not trivially destructible. Since
// this was constructed manually in init(), we must destroy it manually
// here.
Expand Down
17 changes: 13 additions & 4 deletions backends/vulkan/runtime/vk_api/Pipeline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -406,8 +406,6 @@ ComputePipelineCache::~ComputePipelineCache() {
return;
}

save_cache();

vkDestroyPipelineCache(device_, pipeline_cache_, nullptr);
pipeline_cache_ = VK_NULL_HANDLE;
}
Expand All @@ -433,12 +431,12 @@ void ComputePipelineCache::purge() {
}

std::vector<char> ComputePipelineCache::load_cache() {
// Return if path is not specified; this means the optimization is disabled
// No optimization if path is unspecified
if (cache_data_path_.empty()) {
return {};
}

// Return if file doesn't exist; this is expected on the first model-load
// Return if file doesn't exist; this is expected on first model-load
std::ifstream file(cache_data_path_, std::ios::binary | std::ios::ate);
if (file.fail()) {
return {};
Expand All @@ -454,6 +452,17 @@ std::vector<char> ComputePipelineCache::load_cache() {
}

void ComputePipelineCache::save_cache() {
// No optimization if path is unspecified
if (cache_data_path_.empty()) {
return;
}

// Return if file exists; the cache is already saved
std::ifstream ifile(cache_data_path_);
if (ifile.good()) {
return;
}

size_t size{};
vkGetPipelineCacheData(device_, pipeline_cache_, &size, nullptr);

Expand Down
3 changes: 2 additions & 1 deletion backends/vulkan/runtime/vk_api/Pipeline.h
Original file line number Diff line number Diff line change
Expand Up @@ -269,9 +269,10 @@ class ComputePipelineCache final {
}
};

void save_cache();

private:
std::vector<char> load_cache();
void save_cache();

// Multiple threads could potentially be adding entries into the cache, so use
// a mutex to manage access
Expand Down
12 changes: 1 addition & 11 deletions backends/vulkan/runtime/vk_api/Runtime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ std::unique_ptr<Runtime> init_global_vulkan_runtime() {
};

try {
return std::make_unique<Runtime>(Runtime(default_config));
return std::make_unique<Runtime>(default_config);
} catch (...) {
}

Expand Down Expand Up @@ -323,16 +323,6 @@ Runtime::~Runtime() {
instance_ = VK_NULL_HANDLE;
}

Runtime::Runtime(Runtime&& other) noexcept
: config_(other.config_),
instance_(other.instance_),
adapters_(std::move(other.adapters_)),
default_adapter_i_(other.default_adapter_i_),
debug_report_callback_(other.debug_report_callback_) {
other.instance_ = VK_NULL_HANDLE;
other.debug_report_callback_ = {};
}

uint32_t Runtime::create_adapter(const Selector& selector) {
VK_CHECK_COND(
!device_mappings_.empty(),
Expand Down
2 changes: 1 addition & 1 deletion backends/vulkan/runtime/vk_api/Runtime.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class Runtime final {
Runtime(const Runtime&) = delete;
Runtime& operator=(const Runtime&) = delete;

Runtime(Runtime&&) noexcept;
Runtime(Runtime&&) = delete;
Runtime& operator=(Runtime&&) = delete;

~Runtime();
Expand Down
Loading