refactoring: opt graph key gen

This commit is contained in:
hongruichen 2024-07-27 10:38:43 +08:00
parent be9a8c73a0
commit 18aa6654d5

View file

@ -82,14 +82,10 @@ template <size_t _InputSize, size_t _OutputSize>
std::string get_graph_key(const std::string &op_name, const std::array<ggml_tensor *, _InputSize> &inputs, std::string get_graph_key(const std::string &op_name, const std::array<ggml_tensor *, _InputSize> &inputs,
const std::array<ggml_tensor *, _OutputSize> &outputs) { const std::array<ggml_tensor *, _OutputSize> &outputs) {
constexpr static const auto append_dimensions = [](std::string &key, const ggml_tensor *tensor) { constexpr static const auto append_dimensions = [](std::string &key, const ggml_tensor *tensor) {
key += "_"; char buffer[256] = {};
key += std::to_string(tensor->ne[0]); snprintf(buffer, sizeof(buffer), "_%ldx%ldx%ldx%ld", (long)tensor->ne[0], (long)tensor->ne[1],
key += "x"; (long)tensor->ne[2], (long)tensor->ne[3]);
key += std::to_string(tensor->ne[1]); key += buffer;
key += "x";
key += std::to_string(tensor->ne[2]);
key += "x";
key += std::to_string(tensor->ne[3]);
}; };
std::string graph_key(op_name); std::string graph_key(op_name);