gemini-code-assist[bot] commented on code in PR #19620:
URL: https://github.com/apache/tvm/pull/19620#discussion_r3310993907
##########
src/runtime/contrib/dnnl/dnnl_json_runtime.cc:
##########
@@ -49,6 +48,16 @@ namespace contrib {
using namespace tvm::runtime;
using namespace tvm::runtime::json;
+namespace {
+inline bool contains(const std::string& s, const std::string& sub) {
+ return s.find(sub) != std::string::npos;
+}
+inline bool contains_any(const std::string& s, const std::string& a, const
std::string& b,
+ const std::string& c) {
+ return contains(s, a) || contains(s, b) || contains(s, c);
+}
Review Comment:

Instead of hardcoding `contains_any` to exactly three arguments, we can use
a C++17 variadic template with a fold expression. This makes the helper
function much more flexible and reusable for any number of search substrings.
```suggestion
template <typename... Args>
inline bool contains_any(const std::string& s, const Args&... args) {
return (contains(s, args) || ...);
}
```
##########
src/runtime/contrib/dnnl/dnnl_json_runtime.cc:
##########
@@ -250,31 +247,24 @@ class DNNLJSONRuntime : public JSONRuntimeBase {
std::set<uint32_t> io_eid_set(run_arg_eid_.begin(), run_arg_eid_.end());
tensor_registry_ = TensorRegistry(engine_, io_eid_set);
- std::string conv_pat(".*conv[1-3]d.*");
- std::string deconv_pat(".*deconv[1-3]d.*");
- std::string conv_transpose_pat(".*conv[1-3]d_transpose.*");
- std::string dense_pat(".*dense.*");
- std::string max_pool_pat(".*max_pool[1-3]d");
- std::string avg_pool_pat(".*avg_pool[1-3]d");
-
// Build subgraph engine.
for (size_t nid = 0; nid < nodes_.size(); ++nid) {
const auto& node = nodes_[nid];
if (node.GetOpType() == "kernel") {
TVM_FFI_ICHECK_EQ(node.GetOpType(), "kernel");
auto op_name = node.GetOpName();
- if (tvm::runtime::regex_match(op_name, deconv_pat) ||
- tvm::runtime::regex_match(op_name, conv_transpose_pat)) {
+ if (contains_any(op_name, "deconv1d", "deconv2d", "deconv3d") ||
+ contains_any(op_name, "conv1d_transpose", "conv2d_transpose",
"conv3d_transpose")) {
Review Comment:

With the variadic template version of `contains_any`, we can simplify this
check by combining the two calls into a single call with all six patterns.
```suggestion
if (contains_any(op_name, "deconv1d", "deconv2d", "deconv3d",
"conv1d_transpose", "conv2d_transpose",
"conv3d_transpose")) {
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]