Skip to content

Commit

Permalink
fix comments
Browse files Browse the repository at this point in the history
  • Loading branch information
xiang1guo committed Dec 26, 2024
1 parent 89d402e commit 470f190
Show file tree
Hide file tree
Showing 29 changed files with 104 additions and 73 deletions.
2 changes: 1 addition & 1 deletion src/graph/backend/dnnl/common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -646,7 +646,7 @@ dnnl::memory::format_tag get_format_tag(const dnnl::memory::desc &md) {
return format_tag;
}

size_t generate_constant_cache_key(
size_t generate_constant_md_hash(
size_t part_id, const std::vector<dnnl::memory::desc> &const_mds) {
size_t key = 0;
key = hash_combine(key, part_id);
Expand Down
2 changes: 1 addition & 1 deletion src/graph/backend/dnnl/common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ std::string get_format_tag_str(const dnnl::memory::desc &md);

dnnl::memory::format_tag get_format_tag(const dnnl::memory::desc &md);

size_t generate_constant_cache_key(
size_t generate_constant_md_hash(
size_t part_id, const std::vector<dnnl::memory::desc> &const_mds);

#ifndef NDEBUG
Expand Down
11 changes: 7 additions & 4 deletions src/graph/backend/dnnl/kernels/batch_norm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ status_t batch_norm_fwd_t::compile_impl(const dnnl_partition_impl_t *part,
return this->memory_planner_.get_exec_args_set().clone();
};

constant_key_ = generate_constant_cache_key(part->id(),
const_md_hash_ = generate_constant_md_hash(part->id(),
memory_planner_.get_exec_args_set().get_persistent_mem_desc_list());

return status::success;
Expand All @@ -135,7 +135,8 @@ status_t batch_norm_fwd_t::execute_impl(const stream_t *g_stream,

constant_cache_t::cached_t c_buffer;
if (enabled_constant_cache()) {
size_t encoded_key = encode_constant_cache_key(inputs, constant_key_);
const size_t encoded_key
= encode_constant_cache_key(inputs, const_md_hash_);
std::promise<constant_cache_t::cached_t> c_promise;
constant_cache_t::value_t cached_value
= dnnl_constant_cache_get_or_add(p_engine_, encoded_key,
Expand Down Expand Up @@ -205,7 +206,8 @@ status_t batch_norm_fwd_t::sycl_execute_impl(const stream_t *g_stream,

constant_cache_t::cached_t c_buffer;
if (enabled_constant_cache()) {
size_t encoded_key = encode_constant_cache_key(inputs, constant_key_);
const size_t encoded_key
= encode_constant_cache_key(inputs, const_md_hash_);
std::promise<constant_cache_t::cached_t> c_promise;
constant_cache_t::value_t cached_value
= dnnl_constant_cache_get_or_add(p_engine_, encoded_key,
Expand Down Expand Up @@ -281,7 +283,8 @@ status_t batch_norm_fwd_t::ocl_execute_impl(const stream_t *g_stream,

constant_cache_t::cached_t c_buffer;
if (enabled_constant_cache()) {
size_t encoded_key = encode_constant_cache_key(inputs, constant_key_);
const size_t encoded_key
= encode_constant_cache_key(inputs, const_md_hash_);
std::promise<constant_cache_t::cached_t> c_promise;
constant_cache_t::value_t cached_value
= dnnl_constant_cache_get_or_add(p_engine_, encoded_key,
Expand Down
2 changes: 1 addition & 1 deletion src/graph/backend/dnnl/kernels/batch_norm.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ struct batch_norm_fwd_t : public kernel_base_t {
memory_planner_t memory_planner_;

std::function<std::shared_ptr<execution_args_set_t>()> resource_ctor_;
constant_cache_t::key_t constant_key_ = 0;
size_t const_md_hash_ = 0;

public:
batch_norm_fwd_t() {
Expand Down
4 changes: 2 additions & 2 deletions src/graph/backend/dnnl/kernels/conv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ status_t conv_fwd_t<quantized>::compile_impl(const dnnl_partition_impl_t *part,
return this->memory_planner_.get_exec_args_set().clone();
};

constant_key_ = generate_constant_cache_key(part->id(),
const_md_hash_ = generate_constant_md_hash(part->id(),
memory_planner_.get_exec_args_set().get_persistent_mem_desc_list());

return status::success;
Expand Down Expand Up @@ -202,7 +202,7 @@ status_t conv_bwd_data_t::compile_impl(const dnnl_partition_impl_t *part,
return this->memory_planner_.get_exec_args_set().clone();
};

constant_key_ = generate_constant_cache_key(part->id(),
const_md_hash_ = generate_constant_md_hash(part->id(),
memory_planner_.get_exec_args_set().get_persistent_mem_desc_list());

return status::success;
Expand Down
9 changes: 6 additions & 3 deletions src/graph/backend/dnnl/kernels/conv_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ status_t conv_base_t::execute_impl(const stream_t *g_stream,

constant_cache_t::cached_t c_buffer;
if (enabled_constant_cache()) {
size_t encoded_key = encode_constant_cache_key(inputs, constant_key_);
const size_t encoded_key
= encode_constant_cache_key(inputs, const_md_hash_);
std::promise<constant_cache_t::cached_t> c_promise;
constant_cache_t::value_t cached_value
= dnnl_constant_cache_get_or_add(p_engine_, encoded_key,
Expand Down Expand Up @@ -133,7 +134,8 @@ status_t conv_base_t::sycl_execute_impl(const stream_t *g_stream,

constant_cache_t::cached_t c_buffer;
if (enabled_constant_cache()) {
size_t encoded_key = encode_constant_cache_key(inputs, constant_key_);
const size_t encoded_key
= encode_constant_cache_key(inputs, const_md_hash_);
std::promise<constant_cache_t::cached_t> c_promise;
constant_cache_t::value_t cached_value
= dnnl_constant_cache_get_or_add(p_engine_, encoded_key,
Expand Down Expand Up @@ -209,7 +211,8 @@ status_t conv_base_t::ocl_execute_impl(const stream_t *g_stream,

constant_cache_t::cached_t c_buffer;
if (enabled_constant_cache()) {
size_t encoded_key = encode_constant_cache_key(inputs, constant_key_);
const size_t encoded_key
= encode_constant_cache_key(inputs, const_md_hash_);
std::promise<constant_cache_t::cached_t> c_promise;
constant_cache_t::value_t cached_value
= dnnl_constant_cache_get_or_add(p_engine_, encoded_key,
Expand Down
2 changes: 1 addition & 1 deletion src/graph/backend/dnnl/kernels/conv_base.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ struct conv_base_t : public kernel_base_t {

std::function<std::shared_ptr<execution_args_set_t>()> resource_ctor_;

constant_cache_t::key_t constant_key_ = 0;
size_t const_md_hash_ = 0;

public:
conv_base_t() {
Expand Down
4 changes: 2 additions & 2 deletions src/graph/backend/dnnl/kernels/conv_transpose.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ status_t conv_transpose_fwd_t<quantized>::compile_impl(
return this->memory_planner_.get_exec_args_set().clone();
};

constant_key_ = generate_constant_cache_key(part->id(),
const_md_hash_ = generate_constant_md_hash(part->id(),
memory_planner_.get_exec_args_set().get_persistent_mem_desc_list());

return status::success;
Expand Down Expand Up @@ -183,7 +183,7 @@ status_t conv_transpose_bwd_data_t::compile_impl(
return this->memory_planner_.get_exec_args_set().clone();
};

constant_key_ = generate_constant_cache_key(part->id(),
const_md_hash_ = generate_constant_md_hash(part->id(),
memory_planner_.get_exec_args_set().get_persistent_mem_desc_list());

return status::success;
Expand Down
11 changes: 7 additions & 4 deletions src/graph/backend/dnnl/kernels/eltwise.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ status_t eltwise_fwd_t<quantized>::compile_impl(
return this->memory_planner_.get_exec_args_set().clone();
};

constant_key_ = generate_constant_cache_key(part->id(),
const_md_hash_ = generate_constant_md_hash(part->id(),
memory_planner_.get_exec_args_set().get_persistent_mem_desc_list());

return status::success;
Expand Down Expand Up @@ -138,7 +138,8 @@ status_t eltwise_fwd_t<quantized>::execute_impl(const stream_t *g_stream,

constant_cache_t::cached_t c_buffer;
if (enabled_constant_cache()) {
size_t encoded_key = encode_constant_cache_key(inputs, constant_key_);
const size_t encoded_key
= encode_constant_cache_key(inputs, const_md_hash_);
std::promise<constant_cache_t::cached_t> c_promise;
constant_cache_t::value_t cached_value
= dnnl_constant_cache_get_or_add(p_engine_, encoded_key,
Expand Down Expand Up @@ -209,7 +210,8 @@ status_t eltwise_fwd_t<quantized>::sycl_execute_impl(const stream_t *g_stream,

constant_cache_t::cached_t c_buffer;
if (enabled_constant_cache()) {
size_t encoded_key = encode_constant_cache_key(inputs, constant_key_);
const size_t encoded_key
= encode_constant_cache_key(inputs, const_md_hash_);
std::promise<constant_cache_t::cached_t> c_promise;
constant_cache_t::value_t cached_value
= dnnl_constant_cache_get_or_add(p_engine_, encoded_key,
Expand Down Expand Up @@ -286,7 +288,8 @@ status_t eltwise_fwd_t<quantized>::ocl_execute_impl(const stream_t *g_stream,

constant_cache_t::cached_t c_buffer;
if (enabled_constant_cache()) {
size_t encoded_key = encode_constant_cache_key(inputs, constant_key_);
const size_t encoded_key
= encode_constant_cache_key(inputs, const_md_hash_);
std::promise<constant_cache_t::cached_t> c_promise;
constant_cache_t::value_t cached_value
= dnnl_constant_cache_get_or_add(p_engine_, encoded_key,
Expand Down
2 changes: 1 addition & 1 deletion src/graph/backend/dnnl/kernels/eltwise.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ struct eltwise_fwd_t : public kernel_base_t {

std::function<std::shared_ptr<execution_args_set_t>()> resource_ctor_;

constant_cache_t::key_t constant_key_ = 0;
size_t const_md_hash_ = 0;

public:
eltwise_fwd_t() {
Expand Down
11 changes: 7 additions & 4 deletions src/graph/backend/dnnl/kernels/group_norm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ status_t group_norm_fwd_t::compile_impl(const dnnl_partition_impl_t *part,
return this->memory_planner_.get_exec_args_set().clone();
};

constant_key_ = generate_constant_cache_key(part->id(),
const_md_hash_ = generate_constant_md_hash(part->id(),
memory_planner_.get_exec_args_set().get_persistent_mem_desc_list());

return status::success;
Expand Down Expand Up @@ -143,7 +143,8 @@ status_t group_norm_fwd_t::execute_impl(const stream_t *g_stream,

constant_cache_t::cached_t c_buffer;
if (enabled_constant_cache()) {
size_t encoded_key = encode_constant_cache_key(inputs, constant_key_);
const size_t encoded_key
= encode_constant_cache_key(inputs, const_md_hash_);
std::promise<constant_cache_t::cached_t> c_promise;
constant_cache_t::value_t cached_value
= dnnl_constant_cache_get_or_add(p_engine_, encoded_key,
Expand Down Expand Up @@ -213,7 +214,8 @@ status_t group_norm_fwd_t::sycl_execute_impl(const stream_t *g_stream,

constant_cache_t::cached_t c_buffer;
if (enabled_constant_cache()) {
size_t encoded_key = encode_constant_cache_key(inputs, constant_key_);
const size_t encoded_key
= encode_constant_cache_key(inputs, const_md_hash_);
std::promise<constant_cache_t::cached_t> c_promise;
constant_cache_t::value_t cached_value
= dnnl_constant_cache_get_or_add(p_engine_, encoded_key,
Expand Down Expand Up @@ -289,7 +291,8 @@ status_t group_norm_fwd_t::ocl_execute_impl(const stream_t *g_stream,

constant_cache_t::cached_t c_buffer;
if (enabled_constant_cache()) {
size_t encoded_key = encode_constant_cache_key(inputs, constant_key_);
const size_t encoded_key
= encode_constant_cache_key(inputs, const_md_hash_);
std::promise<constant_cache_t::cached_t> c_promise;
constant_cache_t::value_t cached_value
= dnnl_constant_cache_get_or_add(p_engine_, encoded_key,
Expand Down
2 changes: 1 addition & 1 deletion src/graph/backend/dnnl/kernels/group_norm.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ struct group_norm_fwd_t : public kernel_base_t {

std::function<std::shared_ptr<execution_args_set_t>()> resource_ctor_;

constant_cache_t::key_t constant_key_ = 0;
size_t const_md_hash_ = 0;

public:
group_norm_fwd_t() {
Expand Down
11 changes: 3 additions & 8 deletions src/graph/backend/dnnl/kernels/kernel_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,9 @@ size_t kernel_base_t::encode_constant_cache_key(
// Encode the constant memory address into cache key for differentiation
size_t encoded_cache_key = cache_key;
for (const auto &in : inputs) {
if (in.get_logical_tensor().property
== dnnl_graph_tensor_property_t::
dnnl_graph_tensor_property_constant) {
auto data_handle = in.get_data_handle();
if (data_handle != nullptr) {
encoded_cache_key = hash_combine(encoded_cache_key,
reinterpret_cast<uintptr_t>(data_handle));
}
if (logical_tensor_wrapper_t(in.get_logical_tensor()).is_constant()) {
encoded_cache_key = hash_combine(encoded_cache_key,
reinterpret_cast<uintptr_t>(in.get_data_handle()));
}
}
return encoded_cache_key;
Expand Down
11 changes: 7 additions & 4 deletions src/graph/backend/dnnl/kernels/large_partition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ status_t larger_partition_kernel_t::compile_impl(
return this->memory_planner_.get_exec_args_set().clone();
};

constant_key_ = generate_constant_cache_key(part->id(),
const_md_hash_ = generate_constant_md_hash(part->id(),
memory_planner_.get_exec_args_set().get_persistent_mem_desc_list());

return status::success;
Expand All @@ -248,7 +248,8 @@ status_t larger_partition_kernel_t::execute_impl(const stream_t *g_stream,

constant_cache_t::cached_t c_buffer;
if (enabled_constant_cache()) {
size_t encoded_key = encode_constant_cache_key(inputs, constant_key_);
const size_t encoded_key
= encode_constant_cache_key(inputs, const_md_hash_);
std::promise<constant_cache_t::cached_t> c_promise;
constant_cache_t::value_t cached_value
= dnnl_constant_cache_get_or_add(p_engine_, encoded_key,
Expand Down Expand Up @@ -317,7 +318,8 @@ status_t larger_partition_kernel_t::sycl_execute_impl(const stream_t *g_stream,

constant_cache_t::cached_t c_buffer;
if (enabled_constant_cache()) {
size_t encoded_key = encode_constant_cache_key(inputs, constant_key_);
const size_t encoded_key
= encode_constant_cache_key(inputs, const_md_hash_);
std::promise<constant_cache_t::cached_t> c_promise;
constant_cache_t::value_t cached_value
= dnnl_constant_cache_get_or_add(p_engine_, encoded_key,
Expand Down Expand Up @@ -391,7 +393,8 @@ status_t larger_partition_kernel_t::ocl_execute_impl(const stream_t *g_stream,

constant_cache_t::cached_t c_buffer;
if (enabled_constant_cache()) {
size_t encoded_key = encode_constant_cache_key(inputs, constant_key_);
const size_t encoded_key
= encode_constant_cache_key(inputs, const_md_hash_);
std::promise<constant_cache_t::cached_t> c_promise;
constant_cache_t::value_t cached_value
= dnnl_constant_cache_get_or_add(p_engine_, encoded_key,
Expand Down
2 changes: 1 addition & 1 deletion src/graph/backend/dnnl/kernels/large_partition.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class larger_partition_kernel_t : public kernel_base_t {

std::function<std::shared_ptr<execution_args_set_t>()> resource_ctor_;

constant_cache_t::key_t constant_key_ = 0;
size_t const_md_hash_ = 0;

std::once_flag once_flag_;
subgraph_visualizer_t vis_;
Expand Down
11 changes: 7 additions & 4 deletions src/graph/backend/dnnl/kernels/layer_norm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ status_t layer_norm_fwd_t::compile_impl(const dnnl_partition_impl_t *part,
return this->memory_planner_.get_exec_args_set().clone();
};

constant_key_ = generate_constant_cache_key(part->id(),
const_md_hash_ = generate_constant_md_hash(part->id(),
memory_planner_.get_exec_args_set().get_persistent_mem_desc_list());

return status::success;
Expand Down Expand Up @@ -140,7 +140,8 @@ status_t layer_norm_fwd_t::execute_impl(const stream_t *g_stream,

constant_cache_t::cached_t c_buffer;
if (enabled_constant_cache()) {
size_t encoded_key = encode_constant_cache_key(inputs, constant_key_);
const size_t encoded_key
= encode_constant_cache_key(inputs, const_md_hash_);
std::promise<constant_cache_t::cached_t> c_promise;
constant_cache_t::value_t cached_value
= dnnl_constant_cache_get_or_add(p_engine_, encoded_key,
Expand Down Expand Up @@ -210,7 +211,8 @@ status_t layer_norm_fwd_t::sycl_execute_impl(const stream_t *g_stream,

constant_cache_t::cached_t c_buffer;
if (enabled_constant_cache()) {
size_t encoded_key = encode_constant_cache_key(inputs, constant_key_);
const size_t encoded_key
= encode_constant_cache_key(inputs, const_md_hash_);
std::promise<constant_cache_t::cached_t> c_promise;
constant_cache_t::value_t cached_value
= dnnl_constant_cache_get_or_add(p_engine_, encoded_key,
Expand Down Expand Up @@ -286,7 +288,8 @@ status_t layer_norm_fwd_t::ocl_execute_impl(const stream_t *g_stream,

constant_cache_t::cached_t c_buffer;
if (enabled_constant_cache()) {
size_t encoded_key = encode_constant_cache_key(inputs, constant_key_);
const size_t encoded_key
= encode_constant_cache_key(inputs, const_md_hash_);
std::promise<constant_cache_t::cached_t> c_promise;
constant_cache_t::value_t cached_value
= dnnl_constant_cache_get_or_add(p_engine_, encoded_key,
Expand Down
2 changes: 1 addition & 1 deletion src/graph/backend/dnnl/kernels/layer_norm.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ struct layer_norm_fwd_t : public kernel_base_t {

std::function<std::shared_ptr<execution_args_set_t>()> resource_ctor_;

constant_cache_t::key_t constant_key_ = 0;
size_t const_md_hash_ = 0;

public:
layer_norm_fwd_t() {
Expand Down
11 changes: 7 additions & 4 deletions src/graph/backend/dnnl/kernels/matmul.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ status_t matmul_t<quantized>::compile_impl(const dnnl_partition_impl_t *part,
return this->memory_planner_.get_exec_args_set().clone();
};

constant_key_ = generate_constant_cache_key(part->id(),
const_md_hash_ = generate_constant_md_hash(part->id(),
memory_planner_.get_exec_args_set().get_persistent_mem_desc_list());

return status::success;
Expand Down Expand Up @@ -193,7 +193,8 @@ status_t matmul_t<quantized>::execute_impl(const stream_t *g_stream,

constant_cache_t::cached_t c_buffer;
if (enabled_constant_cache()) {
size_t encoded_key = encode_constant_cache_key(inputs, constant_key_);
const size_t encoded_key
= encode_constant_cache_key(inputs, const_md_hash_);
std::promise<constant_cache_t::cached_t> c_promise;
constant_cache_t::value_t cached_value
= dnnl_constant_cache_get_or_add(p_engine_, encoded_key,
Expand Down Expand Up @@ -264,7 +265,8 @@ status_t matmul_t<quantized>::sycl_execute_impl(const stream_t *g_stream,

constant_cache_t::cached_t c_buffer;
if (enabled_constant_cache()) {
size_t encoded_key = encode_constant_cache_key(inputs, constant_key_);
const size_t encoded_key
= encode_constant_cache_key(inputs, const_md_hash_);
std::promise<constant_cache_t::cached_t> c_promise;
constant_cache_t::value_t cached_value
= dnnl_constant_cache_get_or_add(p_engine_, encoded_key,
Expand Down Expand Up @@ -341,7 +343,8 @@ status_t matmul_t<quantized>::ocl_execute_impl(const stream_t *g_stream,

constant_cache_t::cached_t c_buffer;
if (enabled_constant_cache()) {
size_t encoded_key = encode_constant_cache_key(inputs, constant_key_);
const size_t encoded_key
= encode_constant_cache_key(inputs, const_md_hash_);
std::promise<constant_cache_t::cached_t> c_promise;
constant_cache_t::value_t cached_value
= dnnl_constant_cache_get_or_add(p_engine_, encoded_key,
Expand Down
2 changes: 1 addition & 1 deletion src/graph/backend/dnnl/kernels/matmul.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ struct matmul_t : public kernel_base_t {

std::function<std::shared_ptr<execution_args_set_t>()> resource_ctor_;

constant_cache_t::key_t constant_key_ = 0;
size_t const_md_hash_ = 0;

public:
matmul_t() {
Expand Down
Loading

0 comments on commit 470f190

Please sign in to comment.