Skip to content

Commit

Permalink
Replace stdx::make_unique with std::make_unique
Browse files Browse the repository at this point in the history
  • Loading branch information
VivekPanyam committed May 27, 2022
1 parent 1d3c46c commit d65f4eb
Show file tree
Hide file tree
Showing 27 changed files with 43 additions and 109 deletions.
4 changes: 2 additions & 2 deletions source/neuropod/backends/neuropod_backend.cc
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ NeuropodBackend::NeuropodBackend(const std::string &neuropod_path, RuntimeOption
: model_config_(load_model_config(neuropod_path)),
neuropod_path_(neuropod_path),
options_(std::move(options)),
sealer_(stdx::make_unique<Sealer>(get_device_mapping(*model_config_, options_)))
sealer_(std::make_unique<Sealer>(get_device_mapping(*model_config_, options_)))
{
loader_ = get_loader(neuropod_path);
}
Expand Down Expand Up @@ -301,7 +301,7 @@ std::unique_ptr<NeuropodValueMap> NeuropodBackend::infer_internal(const Neuropod

// Run inference and get all the outputs
auto data = infer_internal(inputs);
auto out = stdx::make_unique<NeuropodValueMap>();
auto out = std::make_unique<NeuropodValueMap>();

// Filter to the requested outputs
for (const auto &tensor_name : requested_outputs)
Expand Down
6 changes: 3 additions & 3 deletions source/neuropod/backends/python_bridge/python_bridge.cc
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ std::unique_ptr<py::gil_scoped_release> maybe_initialize()

// TODO: shutdown the interpreter once we know that there are no more python objects left
// atexit(py::finalize_interpreter);
return stdx::make_unique<py::gil_scoped_release>();
return std::make_unique<py::gil_scoped_release>();
}

// Handle interpreter startup and shutdown
Expand Down Expand Up @@ -205,7 +205,7 @@ void PythonBridge::load_model_internal()
const auto local_path = loader_->ensure_local();

// Load the neuropod and save a reference to it
neuropod_ = stdx::make_unique<py::object>(load_neuropod(local_path));
neuropod_ = std::make_unique<py::object>(load_neuropod(local_path));
}

PythonBridge::~PythonBridge()
Expand Down Expand Up @@ -249,7 +249,7 @@ std::unique_ptr<NeuropodValueMap> PythonBridge::infer_internal(const NeuropodVal
auto outputs = from_numpy_dict(*get_tensor_allocator(), model_outputs);

// We need a unique pointer
return stdx::make_unique<NeuropodValueMap>(std::move(outputs));
return std::make_unique<NeuropodValueMap>(std::move(outputs));
}

REGISTER_NEUROPOD_BACKEND(PythonBridge, "python", PY_VERSION)
Expand Down
2 changes: 1 addition & 1 deletion source/neuropod/backends/tensorflow/tf_backend.cc
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ std::unique_ptr<NeuropodValueMap> TensorflowNeuropodBackend::infer_internal(
check_tf_status(session_->RunCallable(handle, tf_inputs, &outputs, nullptr));

// Read the outputs and wrap them in `NeuropodTensor`s
auto to_return = stdx::make_unique<NeuropodValueMap>();
auto to_return = std::make_unique<NeuropodValueMap>();
size_t position = 0;
for (const auto &item : tensor_fetches)
{
Expand Down
4 changes: 2 additions & 2 deletions source/neuropod/backends/torchscript/torch_backend.cc
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ void insert_value_in_output(NeuropodValueMap & output,
(!has_type && list[0].isString()))
{
// Make a TorchNeuropodTensor
auto neuropod_tensor = stdx::make_unique<TorchNeuropodTensor<std::string>>(tensor);
auto neuropod_tensor = std::make_unique<TorchNeuropodTensor<std::string>>(tensor);

// Add it to our output
auto &to_set = output[name];
Expand Down Expand Up @@ -416,7 +416,7 @@ std::unique_ptr<NeuropodValueMap> TorchNeuropodBackend::infer_internal(const Neu
c10::IValue result = model_->forward(torch_inputs);

// Get outputs
auto to_return = stdx::make_unique<NeuropodValueMap>();
auto to_return = std::make_unique<NeuropodValueMap>();

if (result.isGenericDict())
{
Expand Down
2 changes: 1 addition & 1 deletion source/neuropod/bindings/neuropod_native.cc
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ template <typename... Params>
std::unique_ptr<Neuropod> make_neuropod(py::kwargs kwargs, Params &&... params)
{
auto options = get_options_from_kwargs(kwargs);
return stdx::make_unique<Neuropod>(std::forward<Params>(params)..., options);
return std::make_unique<Neuropod>(std::forward<Params>(params)..., options);
}

} // namespace
Expand Down
2 changes: 1 addition & 1 deletion source/neuropod/core/generic_tensor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ namespace neuropod

std::unique_ptr<NeuropodTensorAllocator> get_generic_tensor_allocator()
{
return stdx::make_unique<DefaultTensorAllocator<GenericNeuropodTensor>>();
return std::make_unique<DefaultTensorAllocator<GenericNeuropodTensor>>();
}

} // namespace neuropod
2 changes: 1 addition & 1 deletion source/neuropod/internal/backend_registration.cc
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ std::unique_ptr<std::unordered_map<std::string, BackendInfo>> registered_backend
void init_registrar_if_needed()
{
std::call_once(registrar_initialized, []() {
registered_backends_by_type = stdx::make_unique<std::unordered_map<std::string, BackendInfo>>();
registered_backends_by_type = std::make_unique<std::unordered_map<std::string, BackendInfo>>();

// Make sure our logging is initialized
init_logging();
Expand Down
2 changes: 1 addition & 1 deletion source/neuropod/internal/backend_registration.hh
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ typedef std::unique_ptr<NeuropodBackend> (*BackendFactoryFunction)(const std::st
template <typename T>
std::unique_ptr<NeuropodBackend> createNeuropodBackend(const std::string &neuropod_path, const RuntimeOptions &options)
{
return stdx::make_unique<T>(neuropod_path, options);
return std::make_unique<T>(neuropod_path, options);
}

// Register a backend for a set of specific types
Expand Down
2 changes: 1 addition & 1 deletion source/neuropod/internal/config_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ std::unique_ptr<ModelConfig> load_model_config(std::istream &input_stream)
}

// Not directly using make_unique because of brace initialization
return stdx::make_unique<ModelConfig>(
return std::make_unique<ModelConfig>(
ModelConfig{name, platform, platform_version_semver, inputs, outputs, custom_ops, input_tensor_device});
}

Expand Down
1 change: 0 additions & 1 deletion source/neuropod/internal/config_utils.hh
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ limitations under the License.

#pragma once

#include "neuropod/internal/memory_utils.hh"
#include "neuropod/internal/tensor_types.hh"

#include <memory>
Expand Down
65 changes: 0 additions & 65 deletions source/neuropod/internal/memory_utils.hh

This file was deleted.

8 changes: 4 additions & 4 deletions source/neuropod/internal/neuropod_loader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class LocalLoader : public NeuropodLoader

std::unique_ptr<std::istream> get_istream_for_file(const std::string &path) override
{
auto ret = stdx::make_unique<std::ifstream>(get_file_path(path));
auto ret = std::make_unique<std::ifstream>(get_file_path(path));
if (!(*ret))
{
return nullptr;
Expand Down Expand Up @@ -99,7 +99,7 @@ class ZipLoader : public NeuropodLoader

std::unique_ptr<std::istream> get_istream_for_file(const std::string &path) override
{
auto out = stdx::make_unique<std::stringstream>();
auto out = std::make_unique<std::stringstream>();
if (!unzipper_.extractEntryToStream(path, *out))
{
return nullptr;
Expand Down Expand Up @@ -174,10 +174,10 @@ std::unique_ptr<NeuropodLoader> get_loader(const std::string &neuropod_path)

if (fs::is_directory(neuropod_path))
{
return stdx::make_unique<LocalLoader>(neuropod_path);
return std::make_unique<LocalLoader>(neuropod_path);
}

return stdx::make_unique<ZipLoader>(neuropod_path);
return std::make_unique<ZipLoader>(neuropod_path);
}

} // namespace neuropod
2 changes: 1 addition & 1 deletion source/neuropod/internal/neuropod_tensor.hh
Original file line number Diff line number Diff line change
Expand Up @@ -644,7 +644,7 @@ protected:
// Utility to make a tensor of a specific type
#define MAKE_TENSOR(CPP_TYPE, NEUROPOD_TYPE) \
case NEUROPOD_TYPE: { \
return stdx::make_unique<TensorClass<CPP_TYPE>>(std::forward<Params>(params)...); \
return std::make_unique<TensorClass<CPP_TYPE>>(std::forward<Params>(params)...); \
}

template <template <class> class TensorClass, typename... Params>
Expand Down
8 changes: 4 additions & 4 deletions source/neuropod/multiprocess/mq/ipc_message_queue_impl.hh
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ constexpr auto MAX_QUEUE_SIZE = 20;
template <typename UserPayloadType>
inline std::unique_ptr<ipc::message_queue> make_queue(const std::string &control_queue_name_, const std::string &suffix)
{
return stdx::make_unique<ipc::message_queue>(ipc::open_or_create,
return std::make_unique<ipc::message_queue>(ipc::open_or_create,
("neuropod_" + control_queue_name_ + suffix).c_str(),
MAX_QUEUE_SIZE,
sizeof(WireFormat<UserPayloadType>));
Expand Down Expand Up @@ -67,7 +67,7 @@ void IPCMessageQueue<UserPayloadType>::read_worker_loop()
boost::posix_time::milliseconds(detail::MESSAGE_TIMEOUT_MS);

// Get a message
auto received = stdx::make_unique<WireFormat>();
auto received = std::make_unique<WireFormat>();
size_t received_size;
unsigned int priority;
bool successful_read =
Expand Down Expand Up @@ -196,8 +196,8 @@ IPCMessageQueue<UserPayloadType>::IPCMessageQueue(const std::string &control_que
control_queue_name_(control_queue_name),
send_queue_(detail::make_send_queue<UserPayloadType>(control_queue_name_, type)),
recv_queue_(detail::make_recv_queue<UserPayloadType>(control_queue_name_, type)),
heartbeat_controller_(stdx::make_unique<detail::HeartbeatController>(*this)),
transferrable_controller_(stdx::make_unique<detail::TransferrableController>()),
heartbeat_controller_(std::make_unique<detail::HeartbeatController>(*this)),
transferrable_controller_(std::make_unique<detail::TransferrableController>()),
lost_heartbeat_(false),
read_worker_(&IPCMessageQueue<UserPayloadType>::read_worker_loop, this)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ TEST(test_ipc_message_queue, simple)
{
// A tensor allocator that allocates tensors in shared memory
std::unique_ptr<neuropod::NeuropodTensorAllocator> allocator =
neuropod::stdx::make_unique<neuropod::DefaultTensorAllocator<neuropod::SHMNeuropodTensor>>();
neuropod::std::make_unique<neuropod::DefaultTensorAllocator<neuropod::SHMNeuropodTensor>>();

// Store tensors we allocate so they don't go out of scope
neuropod::NeuropodValueMap sender_map;
Expand Down
2 changes: 1 addition & 1 deletion source/neuropod/multiprocess/mq/test/test_ope_heartbeat.cc
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class TestChannel

TEST(test_ope_heartbeat, basic)
{
auto test_channel = neuropod::stdx::make_unique<TestChannel>();
auto test_channel = neuropod::std::make_unique<TestChannel>();

// Create a controller
neuropod::detail::HeartbeatController controller(*test_channel);
Expand Down
6 changes: 3 additions & 3 deletions source/neuropod/multiprocess/multiprocess.cc
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ class MultiprocessNeuropodBackend : public NeuropodBackendWithDefaultAllocator<S
}

// Load the returned tensors
auto to_return = stdx::make_unique<NeuropodValueMap>();
auto to_return = std::make_unique<NeuropodValueMap>();
received.get(*to_return);

if (free_memory_every_cycle_)
Expand Down Expand Up @@ -309,7 +309,7 @@ std::unique_ptr<NeuropodBackend> load_neuropod_ope(const std::string &
if (control_queue_name.empty())
{
// Start a new worker
return stdx::make_unique<MultiprocessNeuropodBackend>(
return std::make_unique<MultiprocessNeuropodBackend>(
neuropod_path, options, free_memory_every_cycle, default_backend_overrides);
}

Expand All @@ -321,7 +321,7 @@ std::unique_ptr<NeuropodBackend> load_neuropod_ope(const std::string &
}

// Use an existing worker
return stdx::make_unique<MultiprocessNeuropodBackend>(neuropod_path, control_queue_name, free_memory_every_cycle);
return std::make_unique<MultiprocessNeuropodBackend>(neuropod_path, control_queue_name, free_memory_every_cycle);
}

} // namespace neuropod
2 changes: 1 addition & 1 deletion source/neuropod/multiprocess/multiprocess_worker.cc
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ void multiprocess_worker_loop(const std::string &control_queue_name)
opts.use_ope = false;

// Load a neuropod
neuropod = stdx::make_unique<Neuropod>(config.neuropod_path, config.default_backend_overrides, opts);
neuropod = std::make_unique<Neuropod>(config.neuropod_path, config.default_backend_overrides, opts);
allocator = neuropod->get_tensor_allocator();
inputs.clear();
control_channel.send_message(LOAD_SUCCESS);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ inline void ipc_deserialize(std::istream &in, std::string &item)
else
{
// We need to allocate a larger buffer
auto buffer = stdx::make_unique<char[]>(length);
auto buffer = std::make_unique<char[]>(length);
detail::checked_read(in, buffer.get(), length);

// Set the content of `item`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ TEST(test_ipc_serialization, neuropod_value_map)
{
// A tensor allocator that allocates tensors in shared memory
std::unique_ptr<neuropod::NeuropodTensorAllocator> allocator =
neuropod::stdx::make_unique<neuropod::DefaultTensorAllocator<neuropod::SHMNeuropodTensor>>();
neuropod::std::make_unique<neuropod::DefaultTensorAllocator<neuropod::SHMNeuropodTensor>>();

const std::shared_ptr<neuropod::NeuropodValue> float_tensor_1D =
allocator->allocate_tensor({3}, neuropod::FLOAT_TENSOR);
Expand Down
8 changes: 4 additions & 4 deletions source/neuropod/multiprocess/shm/raw_shm_block_allocator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -98,14 +98,14 @@ class RawSHMBlock
: uuid_(uuid_generator())
{
// Create a block of shared memory
shm_ = stdx::make_unique<ipc::shared_memory_object>(
shm_ = std::make_unique<ipc::shared_memory_object>(
ipc::create_only, get_key_from_uuid(uuid_).c_str(), ipc::read_write);

// Set the size
shm_->truncate(sizeof(RawSHMBlockInternal) + size_bytes);

// Map into memory
region_ = stdx::make_unique<ipc::mapped_region>(*shm_, ipc::read_write);
region_ = std::make_unique<ipc::mapped_region>(*shm_, ipc::read_write);

// Get a pointer to the struct and initialize it
block_ = new (region_->get_address()) RawSHMBlockInternal;
Expand All @@ -125,10 +125,10 @@ class RawSHMBlock
const auto shm_key = get_key_from_uuid(uuid_);

// Load a chunk of shared memory
shm_ = stdx::make_unique<ipc::shared_memory_object>(ipc::open_only, shm_key.c_str(), ipc::read_write);
shm_ = std::make_unique<ipc::shared_memory_object>(ipc::open_only, shm_key.c_str(), ipc::read_write);

// Map into memory
region_ = stdx::make_unique<ipc::mapped_region>(*shm_, ipc::read_write);
region_ = std::make_unique<ipc::mapped_region>(*shm_, ipc::read_write);

// Get a pointer to the struct
block_ = static_cast<RawSHMBlockInternal *>(region_->get_address());
Expand Down
2 changes: 1 addition & 1 deletion source/neuropod/multiprocess/shm/shm_allocator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ class AllocationCache
};

SHMAllocator::SHMAllocator()
: allocation_cache_(stdx::make_unique<AllocationCache>()), load_cache_(stdx::make_unique<LoadCache>())
: allocation_cache_(std::make_unique<AllocationCache>()), load_cache_(std::make_unique<LoadCache>())
{
}

Expand Down
4 changes: 2 additions & 2 deletions source/neuropod/multiprocess/shm_tensor.hh
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ public:
const SHMBlockID & block_id)
: TypedNeuropodTensor<std::string>(copy_and_strip_last_dim(dims)), write_buffer_(this->get_num_elements())
{
auto byte_block = stdx::make_unique<SHMNeuropodTensor<uint8_t>>(dims, std::move(block), data, block_id);
auto byte_block = std::make_unique<SHMNeuropodTensor<uint8_t>>(dims, std::move(block), data, block_id);

auto base_ptr = byte_block->get_raw_data_ptr();
auto max_len = dims[dims.size() - 1];
Expand Down Expand Up @@ -229,7 +229,7 @@ public:
dims_copy.push_back(max_len);

// TODO(vip): We can optimize this
last_shm_block_ = stdx::make_unique<SHMNeuropodTensor<uint8_t>>(dims_copy);
last_shm_block_ = std::make_unique<SHMNeuropodTensor<uint8_t>>(dims_copy);
last_shm_block_->overwrite_type(STRING_TENSOR);

// Copy data in
Expand Down
Loading

0 comments on commit d65f4eb

Please sign in to comment.