This is an automated email from the ASF dual-hosted git repository.

kparzysz pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tvm.git


The following commit(s) were added to refs/heads/main by this push:
     new 247c54b97d Use std::make_unique instead of std::unique_ptr(new ...), 
NFC (#12459)
247c54b97d is described below

commit 247c54b97dffaa8afbe5681310f73306551b53e8
Author: Krzysztof Parzyszek <[email protected]>
AuthorDate: Tue Aug 16 16:06:48 2022 -0500

    Use std::make_unique instead of std::unique_ptr(new ...), NFC (#12459)
---
 apps/cpp_rpc/win32_process.cc                            | 4 ++--
 include/tvm/runtime/logging.h                            | 3 +--
 include/tvm/target/target_kind.h                         | 6 +++---
 src/relay/analysis/call_graph.cc                         | 2 +-
 src/runtime/contrib/edgetpu/edgetpu_runtime.cc           | 2 +-
 src/runtime/contrib/tflite/tflite_runtime.cc             | 2 +-
 src/runtime/graph_executor/debug/graph_executor_debug.cc | 4 ++--
 src/runtime/rpc/rpc_event_impl.cc                        | 2 +-
 src/runtime/rpc/rpc_pipe_impl.cc                         | 5 ++---
 src/runtime/rpc/rpc_socket_impl.cc                       | 8 +++-----
 src/runtime/thread_pool.cc                               | 9 ++++-----
 src/target/llvm/codegen_amdgpu.cc                        | 2 +-
 src/target/llvm/codegen_hexagon.cc                       | 2 +-
 src/target/llvm/codegen_nvptx.cc                         | 2 +-
 src/target/llvm/llvm_module.cc                           | 4 ++--
 src/tir/transforms/storage_rewrite.cc                    | 2 +-
 tests/cpp/aot_metadata_test.cc                           | 2 +-
 17 files changed, 28 insertions(+), 33 deletions(-)

diff --git a/apps/cpp_rpc/win32_process.cc b/apps/cpp_rpc/win32_process.cc
index bbf8367903..cd24e34b55 100644
--- a/apps/cpp_rpc/win32_process.cc
+++ b/apps/cpp_rpc/win32_process.cc
@@ -178,7 +178,7 @@ void SpawnRPCChild(SOCKET fd, seconds timeout) {
   child_command_line += file_map_path;
 
   // CreateProcessA requires a non const char*, so we copy our std::string
-  std::unique_ptr<char[]> command_line_ptr(new char[child_command_line.size() 
+ 1]);
+  auto command_line_ptr = std::make_unique<char[]>(child_command_line.size() + 
1);
   strcpy(command_line_ptr.get(), child_command_line.c_str());
 
   PROCESS_INFORMATION child_process_info;
@@ -258,4 +258,4 @@ void ChildProcSocketHandler(const std::string& mmap_path) {
   }
 }
 }  // namespace runtime
-}  // namespace tvm
\ No newline at end of file
+}  // namespace tvm
diff --git a/include/tvm/runtime/logging.h b/include/tvm/runtime/logging.h
index 8f6ccea40b..7b635eab04 100644
--- a/include/tvm/runtime/logging.h
+++ b/include/tvm/runtime/logging.h
@@ -540,8 +540,7 @@ std::unique_ptr<std::string> LogCheckFormat(const X& x, 
const Y& y) {
   std::ostringstream os;
   os << " (" << x << " vs. " << y << ") ";  // CHECK_XX(x, y) requires x and y 
can be serialized to
                                             // string. Use CHECK(x OP y) 
otherwise.
-  // no std::make_unique until c++14
-  return std::unique_ptr<std::string>(new std::string(os.str()));
+  return std::make_unique<std::string>(os.str());
 }
 
 // Inline _Pragma in macros does not work reliably on old version of MSVC and
diff --git a/include/tvm/target/target_kind.h b/include/tvm/target/target_kind.h
index 96a6f27a86..63c92fedbd 100644
--- a/include/tvm/target/target_kind.h
+++ b/include/tvm/target/target_kind.h
@@ -324,7 +324,7 @@ struct ValueTypeInfoMaker<ValueType, std::true_type, 
std::false_type> {
     ValueTypeInfo info;
     info.type_index = tindex;
     info.type_key = runtime::Object::TypeIndex2Key(tindex);
-    info.key = std::unique_ptr<ValueTypeInfo>(new ValueTypeInfo(key_type()()));
+    info.key = std::make_unique<ValueTypeInfo>(key_type()());
     info.val = nullptr;
     return info;
   }
@@ -340,8 +340,8 @@ struct ValueTypeInfoMaker<ValueType, std::false_type, 
std::true_type> {
     ValueTypeInfo info;
     info.type_index = tindex;
     info.type_key = runtime::Object::TypeIndex2Key(tindex);
-    info.key = std::unique_ptr<ValueTypeInfo>(new ValueTypeInfo(key_type()()));
-    info.val = std::unique_ptr<ValueTypeInfo>(new ValueTypeInfo(val_type()()));
+    info.key = std::make_unique<ValueTypeInfo>(key_type()());
+    info.val = std::make_unique<ValueTypeInfo>(val_type()());
     return info;
   }
 };
diff --git a/src/relay/analysis/call_graph.cc b/src/relay/analysis/call_graph.cc
index 17bbe5e951..d12ec7b98c 100644
--- a/src/relay/analysis/call_graph.cc
+++ b/src/relay/analysis/call_graph.cc
@@ -112,7 +112,7 @@ CallGraphEntry* CallGraphNode::LookupGlobalVar(const 
GlobalVar& gv) {
   if (call_graph_node) return call_graph_node.get();
 
   // Create the node for the inserted entry.
-  call_graph_node = std::unique_ptr<CallGraphEntry>(new CallGraphEntry(gv));
+  call_graph_node = std::make_unique<CallGraphEntry>(gv);
   return call_graph_node.get();
 }
 
diff --git a/src/runtime/contrib/edgetpu/edgetpu_runtime.cc 
b/src/runtime/contrib/edgetpu/edgetpu_runtime.cc
index bf179cc8cf..a2f159b55d 100644
--- a/src/runtime/contrib/edgetpu/edgetpu_runtime.cc
+++ b/src/runtime/contrib/edgetpu/edgetpu_runtime.cc
@@ -39,7 +39,7 @@ void EdgeTPURuntime::Init(const std::string& 
tflite_model_bytes, Device dev) {
   // According to tflite_runtime.cc, the buffer for tflite::FlatBufferModel
   // should be allocated on flatBuffersBuffer_ to make share it must be kept 
alive
   // for interpreters.
-  flatBuffersBuffer_ = std::unique_ptr<char[]>(new char[buffer_size]);
+  flatBuffersBuffer_ = std::make_unique<char[]>(buffer_size);
   std::memcpy(flatBuffersBuffer_.get(), buffer, buffer_size);
   std::unique_ptr<tflite::FlatBufferModel> model =
       tflite::FlatBufferModel::BuildFromBuffer(flatBuffersBuffer_.get(), 
buffer_size);
diff --git a/src/runtime/contrib/tflite/tflite_runtime.cc 
b/src/runtime/contrib/tflite/tflite_runtime.cc
index 2d323ba51d..3f3c758145 100644
--- a/src/runtime/contrib/tflite/tflite_runtime.cc
+++ b/src/runtime/contrib/tflite/tflite_runtime.cc
@@ -95,7 +95,7 @@ void TFLiteRuntime::Init(const std::string& 
tflite_model_bytes, Device dev) {
   size_t buffer_size = tflite_model_bytes.size();
   // The buffer used to construct the model must be kept alive for
   // dependent interpreters to be used.
-  flatBuffersBuffer_ = std::unique_ptr<char[]>(new char[buffer_size]);
+  flatBuffersBuffer_ = std::make_unique<char[]>(buffer_size);
   std::memcpy(flatBuffersBuffer_.get(), buffer, buffer_size);
   std::unique_ptr<tflite::FlatBufferModel> model =
       tflite::FlatBufferModel::BuildFromBuffer(flatBuffersBuffer_.get(), 
buffer_size);
diff --git a/src/runtime/graph_executor/debug/graph_executor_debug.cc 
b/src/runtime/graph_executor/debug/graph_executor_debug.cc
index ba546165c6..2288aece62 100644
--- a/src/runtime/graph_executor/debug/graph_executor_debug.cc
+++ b/src/runtime/graph_executor/debug/graph_executor_debug.cc
@@ -175,8 +175,8 @@ class GraphExecutorDebug : public GraphExecutor {
                        repeats_to_cooldown, "");
 
     int num_flat_args = num_inputs + num_outputs;
-    std::unique_ptr<TVMValue> values(new TVMValue[num_flat_args]);
-    std::unique_ptr<int> type_codes(new int[num_flat_args]);
+    auto values = std::make_unique<TVMValue[]>(num_flat_args);
+    auto type_codes = std::make_unique<int[]>(num_flat_args);
     TVMArgsSetter setter(values.get(), type_codes.get());
     int offs = 0;
     const auto& inode = nodes_[index];
diff --git a/src/runtime/rpc/rpc_event_impl.cc 
b/src/runtime/rpc/rpc_event_impl.cc
index f5b933fcf7..3bf9538c18 100644
--- a/src/runtime/rpc/rpc_event_impl.cc
+++ b/src/runtime/rpc/rpc_event_impl.cc
@@ -37,7 +37,7 @@ PackedFunc CreateEventDrivenServer(PackedFunc fsend, 
std::string name, std::stri
     return 0;
   });
 
-  std::unique_ptr<CallbackChannel> ch(new CallbackChannel(fsend, frecv));
+  auto ch = std::make_unique<CallbackChannel>(fsend, frecv);
   std::shared_ptr<RPCEndpoint> sess = RPCEndpoint::Create(std::move(ch), name, 
remote_key);
   return PackedFunc([sess](TVMArgs args, TVMRetValue* rv) {
     int ret = sess->ServerAsyncIOEventHandler(args[0], args[1]);
diff --git a/src/runtime/rpc/rpc_pipe_impl.cc b/src/runtime/rpc/rpc_pipe_impl.cc
index 6f2f7e22de..631f8859d0 100644
--- a/src/runtime/rpc/rpc_pipe_impl.cc
+++ b/src/runtime/rpc/rpc_pipe_impl.cc
@@ -106,9 +106,8 @@ Module CreatePipeClient(std::vector<std::string> cmd) {
   close(child_read);
   close(child_write);
 
-  auto endpt = RPCEndpoint::Create(
-      std::unique_ptr<PipeChannel>(new PipeChannel(parent_read, parent_write, 
pid)), "pipe",
-      "pipe");
+  auto endpt = RPCEndpoint::Create(std::make_unique<PipeChannel>(parent_read, 
parent_write, pid),
+                                   "pipe", "pipe");
   endpt->InitRemoteSession(TVMArgs(nullptr, nullptr, 0));
   return CreateRPCSessionModule(CreateClientSession(endpt));
 }
diff --git a/src/runtime/rpc/rpc_socket_impl.cc 
b/src/runtime/rpc/rpc_socket_impl.cc
index bc274ff888..3cc8cdc51f 100644
--- a/src/runtime/rpc/rpc_socket_impl.cc
+++ b/src/runtime/rpc/rpc_socket_impl.cc
@@ -97,7 +97,7 @@ std::shared_ptr<RPCEndpoint> RPCConnect(std::string url, int 
port, std::string k
     ICHECK_EQ(sock.RecvAll(&remote_key[0], keylen), keylen);
   }
 
-  std::unique_ptr<RPCChannel> channel{new SockChannel(sock)};
+  std::unique_ptr<RPCChannel> channel = std::make_unique<SockChannel>(sock);
   if (enable_logging) {
     channel.reset(new RPCChannelLogging(std::move(channel)));
   }
@@ -116,13 +116,11 @@ Module RPCClientConnect(std::string url, int port, 
std::string key, bool enable_
 // TVM_DLL needed for MSVC
 TVM_DLL void RPCServerLoop(int sockfd) {
   support::TCPSocket sock(static_cast<support::TCPSocket::SockType>(sockfd));
-  RPCEndpoint::Create(std::unique_ptr<SockChannel>(new SockChannel(sock)), 
"SockServerLoop", "")
-      ->ServerLoop();
+  RPCEndpoint::Create(std::make_unique<SockChannel>(sock), "SockServerLoop", 
"")->ServerLoop();
 }
 
 void RPCServerLoop(PackedFunc fsend, PackedFunc frecv) {
-  RPCEndpoint::Create(std::unique_ptr<CallbackChannel>(new 
CallbackChannel(fsend, frecv)),
-                      "SockServerLoop", "")
+  RPCEndpoint::Create(std::make_unique<CallbackChannel>(fsend, frecv), 
"SockServerLoop", "")
       ->ServerLoop();
 }
 
diff --git a/src/runtime/thread_pool.cc b/src/runtime/thread_pool.cc
index 6dc87cda11..58b81f05a4 100644
--- a/src/runtime/thread_pool.cc
+++ b/src/runtime/thread_pool.cc
@@ -336,12 +336,11 @@ class ThreadPool {
   void Init() {
     for (int i = 0; i < num_workers_; ++i) {
       // The SpscTaskQueue only hosts ONE item at a time
-      queues_.emplace_back(std::unique_ptr<SpscTaskQueue>(new 
SpscTaskQueue()));
+      queues_.emplace_back(std::make_unique<SpscTaskQueue>());
     }
-    threads_ = std::unique_ptr<tvm::runtime::threading::ThreadGroup>(
-        new tvm::runtime::threading::ThreadGroup(
-            num_workers_, [this](int worker_id) { this->RunWorker(worker_id); 
},
-            exclude_worker0_ /* include_main_thread */));
+    threads_ = std::make_unique<tvm::runtime::threading::ThreadGroup>(
+        num_workers_, [this](int worker_id) { this->RunWorker(worker_id); },
+        exclude_worker0_ /* include_main_thread */);
     num_workers_used_ = threads_->Configure(threading::ThreadGroup::kBig, 0, 
exclude_worker0_);
   }
 
diff --git a/src/target/llvm/codegen_amdgpu.cc 
b/src/target/llvm/codegen_amdgpu.cc
index c080814056..89b567b6b0 100644
--- a/src/target/llvm/codegen_amdgpu.cc
+++ b/src/target/llvm/codegen_amdgpu.cc
@@ -254,7 +254,7 @@ runtime::Module BuildAMDGPU(IRModule mod, Target target) {
   // Lower versions will crash when loading the bitcode, see
   // issue #4087 for a discussion
 #endif
-  std::unique_ptr<CodeGenAMDGPU> cg(new CodeGenAMDGPU());
+  auto cg = std::make_unique<CodeGenAMDGPU>();
 
   cg->Init("TVMAMDGPUModule", llvm_target.get(), false, false, false);
 
diff --git a/src/target/llvm/codegen_hexagon.cc 
b/src/target/llvm/codegen_hexagon.cc
index 657945c025..ff59dfcceb 100644
--- a/src/target/llvm/codegen_hexagon.cc
+++ b/src/target/llvm/codegen_hexagon.cc
@@ -518,7 +518,7 @@ runtime::Module BuildHexagon(IRModule mod, Target target) {
   static bool CallOnce = (ProcessLLVMOptions(llvm_options_vec), true);
   (void)CallOnce;
 
-  std::unique_ptr<CodeGenHexagon> cg(new CodeGenHexagon());
+  auto cg = std::make_unique<CodeGenHexagon>();
 
   std::vector<PrimFunc> funcs;
   std::string entry_func;
diff --git a/src/target/llvm/codegen_nvptx.cc b/src/target/llvm/codegen_nvptx.cc
index c758ca3836..2442d2ccba 100644
--- a/src/target/llvm/codegen_nvptx.cc
+++ b/src/target/llvm/codegen_nvptx.cc
@@ -303,7 +303,7 @@ runtime::Module BuildNVPTX(IRModule mod, Target target) {
   With<LLVMTarget> llvm_target(llvm_instance, target);
 
   int compute_ver = GetCUDAComputeVersion(target);
-  std::unique_ptr<CodeGenNVPTX> cg(new CodeGenNVPTX());
+  auto cg = std::make_unique<CodeGenNVPTX>();
 
   cg->Init("TVMPTXModule", llvm_target.get(), false, false, false);
 
diff --git a/src/target/llvm/llvm_module.cc b/src/target/llvm/llvm_module.cc
index 9aed66fffc..47f8880a0a 100644
--- a/src/target/llvm/llvm_module.cc
+++ b/src/target/llvm/llvm_module.cc
@@ -496,7 +496,7 @@ runtime::Module 
CreateLLVMCppMetadataModule(runtime::metadata::Metadata metadata
   auto llvm_instance = std::make_unique<LLVMInstance>();
   With<LLVMTarget> llvm_target(*llvm_instance, target);
   bool system_lib = runtime->GetAttr<Bool>("system-lib").value_or(Bool(false));
-  std::unique_ptr<CodeGenCPU> cg{new CodeGenCPU()};
+  auto cg = std::make_unique<CodeGenCPU>();
 
   cg->Init("TVMMetadataMod", llvm_target.get(), system_lib, system_lib,
            /*target_c_runtime=*/false);
@@ -544,7 +544,7 @@ runtime::Module CreateLLVMCrtMetadataModule(const 
Array<runtime::Module>& module
   ICHECK(system_lib && target_c_runtime)
       << "For LLVM C-runtime metadata module, must include --system-lib and 
--runtime=c; "
       << "got target: " << target->str();
-  std::unique_ptr<CodeGenCPU> cg{new CodeGenCPU()};
+  auto cg = std::make_unique<CodeGenCPU>();
   cg->Init("TVMMetadataMod", llvm_target.operator->(), system_lib, system_lib, 
target_c_runtime);
 
   cg->DefineFunctionRegistry(func_names);
diff --git a/src/tir/transforms/storage_rewrite.cc 
b/src/tir/transforms/storage_rewrite.cc
index 421af99ab3..acb0526500 100644
--- a/src/tir/transforms/storage_rewrite.cc
+++ b/src/tir/transforms/storage_rewrite.cc
@@ -899,7 +899,7 @@ class StoragePlanRewriter : public StmtExprMutator {
                          const StorageScope& scope, size_t const_nbits) {
     ICHECK(op != nullptr);
     // Re-use not successful, allocate a new buffer.
-    std::unique_ptr<StorageEntry> entry(new StorageEntry());
+    auto entry = std::make_unique<StorageEntry>();
     entry->attach_scope_ = attach_scope;
     entry->scope = scope;
     entry->elem_type = op->dtype.element_of();
diff --git a/tests/cpp/aot_metadata_test.cc b/tests/cpp/aot_metadata_test.cc
index 5c4ba9a528..7d280538e0 100644
--- a/tests/cpp/aot_metadata_test.cc
+++ b/tests/cpp/aot_metadata_test.cc
@@ -420,6 +420,6 @@ TEST(DiscoverComplexTypesVisitor, DiscoverComplexTypes) {
 
 TEST(Metadata, TVMConstantInfo) {
   std::vector<tvm::runtime::metadata::MetadataBase> q;
-  std::unique_ptr<TVMConstantInfo[]> ci{new struct TVMConstantInfo[10]};
+  auto ci = std::make_unique<TVMConstantInfo[]>(10);
   EXPECT_TRUE(ci.get() != nullptr);
 }

Reply via email to