Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions mmros/include/mmros/archetype/exception.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class MmRosException : public std::exception
*
* @param error `MmRosError` object.
*/
explicit MmRosException(const MmRosError & error) : error_(error) { appendMessagePrefix(); }
explicit MmRosException(const MmRosError & error) : error_(error) { append_message_prefix(); }

/**
* @brief Construct a new MmRosException object with error kind and message.
Expand All @@ -75,7 +75,7 @@ class MmRosException : public std::exception
*/
MmRosException(const MmRosError_t & kind, const std::string & msg) : error_(kind, msg)
{
appendMessagePrefix();
append_message_prefix();
}

/**
Expand All @@ -87,7 +87,7 @@ class MmRosException : public std::exception
/**
* @brief Append prefix to the error message depending on its kind.
*/
void appendMessagePrefix() noexcept
void append_message_prefix() noexcept
{
switch (error_.kind) {
case MmRosError_t::TENSORRT:
Expand Down
12 changes: 6 additions & 6 deletions mmros/include/mmros/archetype/result.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,14 @@ class Result
/**
* @brief Check whether holding value is expected type.
*/
bool isOk() const noexcept { return std::holds_alternative<T>(value_); }
bool is_ok() const noexcept { return std::holds_alternative<T>(value_); }

/**
* @brief Return the expected value if it holds, otherwise throw `MmRosException`.
*/
T unwrap() const
{
if (isOk()) {
if (is_ok()) {
return std::get<T>(value_);
} else {
throw MmRosException(std::get<MmRosError>(value_));
Expand All @@ -74,7 +74,7 @@ class Result
*/

template <typename T>
Result<T> Ok(const T & value) noexcept
Result<T> make_ok(const T & value) noexcept
{
return Result<T>(value);
}
Expand All @@ -86,7 +86,7 @@ Result<T> Ok(const T & value) noexcept
* @param error `MmRosError` object.
*/
template <typename T>
Result<T> Err(const MmRosError & error) noexcept
Result<T> make_err(const MmRosError & error) noexcept
{
return Result<T>(error);
}
Expand All @@ -98,7 +98,7 @@ Result<T> Err(const MmRosError & error) noexcept
* @param kind Error kind.
*/
template <typename T>
Result<T> Err(const MmRosError_t & kind) noexcept
Result<T> make_err(const MmRosError_t & kind) noexcept
{
MmRosError error(kind);
return Result<T>(error);
Expand All @@ -112,7 +112,7 @@ Result<T> Err(const MmRosError_t & kind) noexcept
* @param msg Error message.
*/
template <typename T>
Result<T> Err(const MmRosError_t & kind, const std::string & msg) noexcept
Result<T> make_err(const MmRosError_t & kind, const std::string & msg) noexcept
{
MmRosError error(kind, msg);
return Result<T>(error);
Expand Down
14 changes: 7 additions & 7 deletions mmros/src/detector/detector2d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,36 +77,36 @@ archetype::Result<outputs_type> Detector2D::doInference(
const std::vector<cv::Mat> & images) noexcept
{
if (images.empty()) {
return archetype::Err<outputs_type>(archetype::MmRosError_t::UNKNOWN, "No image.");
return archetype::make_err<outputs_type>(archetype::MmRosError_t::UNKNOWN, "No image.");
}

// 1. Init CUDA pointers
try {
initCudaPtr(images.size());
} catch (const archetype::MmRosException & e) {
return archetype::Err<outputs_type>(archetype::MmRosError_t::CUDA, e.what());
return archetype::make_err<outputs_type>(archetype::MmRosError_t::CUDA, e.what());
}

// 2. Execute preprocess
try {
preprocess(images);
} catch (const archetype::MmRosException & e) {
return archetype::Err<outputs_type>(archetype::MmRosError_t::CUDA, e.what());
return archetype::make_err<outputs_type>(archetype::MmRosError_t::CUDA, e.what());
}

// 3. Set tensors
std::vector<void *> buffers{input_d_.get(), out_boxes_d_.get(), out_labels_d_.get()};
if (!trt_common_->setTensorsAddresses(buffers)) {
std::ostringstream os;
os << "@" << __FILE__ << ", #F:" << __FUNCTION__ << ", #L:" << __LINE__;
return archetype::Err<outputs_type>(archetype::MmRosError_t::TENSORRT, os.str());
return archetype::make_err<outputs_type>(archetype::MmRosError_t::TENSORRT, os.str());
}

// 4. Execute inference
if (!trt_common_->enqueueV3(stream_)) {
std::ostringstream os;
os << "@" << __FILE__ << ", #F:" << __FUNCTION__ << ", #L:" << __LINE__;
return archetype::Err<outputs_type>(archetype::MmRosError_t::TENSORRT, os.str());
return archetype::make_err<outputs_type>(archetype::MmRosError_t::TENSORRT, os.str());
}

// 5. Execute postprocess
Expand Down Expand Up @@ -184,7 +184,7 @@ archetype::Result<outputs_type> Detector2D::postprocess(
sizeof(int) * batch_size * num_detection * class_dim, ::cudaMemcpyDeviceToHost, stream_));
CHECK_CUDA_ERROR(cudaStreamSynchronize(stream_));
} catch (const archetype::MmRosException & e) {
return archetype::Err<outputs_type>(archetype::MmRosError_t::CUDA, e.what());
return archetype::make_err<outputs_type>(archetype::MmRosError_t::CUDA, e.what());
}

outputs_type output;
Expand All @@ -210,6 +210,6 @@ archetype::Result<outputs_type> Detector2D::postprocess(
output.push_back(std::move(boxes));
}

return archetype::Ok(output);
return archetype::make_ok(output);
}
} // namespace mmros::detector
14 changes: 7 additions & 7 deletions mmros/src/detector/instance_segmeter2d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,33 +79,33 @@ archetype::Result<outputs_type> InstanceSegmenter2D::doInference(
const std::vector<cv::Mat> & images) noexcept
{
if (images.empty()) {
return archetype::Err<outputs_type>(archetype::MmRosError_t::UNKNOWN, "No image.");
return archetype::make_err<outputs_type>(archetype::MmRosError_t::UNKNOWN, "No image.");
}

// 1. Init CUDA pointers
try {
initCudaPtr(images.size());
} catch (const archetype::MmRosException & e) {
return archetype::Err<outputs_type>(archetype::MmRosError_t::CUDA, e.what());
return archetype::make_err<outputs_type>(archetype::MmRosError_t::CUDA, e.what());
}

// 2. Execute preprocess
try {
preprocess(images);
} catch (const archetype::MmRosException & e) {
return archetype::Err<outputs_type>(archetype::MmRosError_t::CUDA, e.what());
return archetype::make_err<outputs_type>(archetype::MmRosError_t::CUDA, e.what());
}

// 3. Set tensors
std::vector<void *> buffers{
input_d_.get(), out_boxes_d_.get(), out_labels_d_.get(), out_segments_d_.get()};
if (!trt_common_->setTensorsAddresses(buffers)) {
return archetype::Err<outputs_type>(archetype::MmRosError_t::TENSORRT);
return archetype::make_err<outputs_type>(archetype::MmRosError_t::TENSORRT);
}

// 4. Execute inference
if (!trt_common_->enqueueV3(stream_)) {
return archetype::Err<outputs_type>(archetype::MmRosError_t::TENSORRT);
return archetype::make_err<outputs_type>(archetype::MmRosError_t::TENSORRT);
}

// 5. Execute postprocess
Expand Down Expand Up @@ -196,7 +196,7 @@ archetype::Result<outputs_type> InstanceSegmenter2D::postprocess(
::cudaMemcpyDeviceToHost, stream_));
CHECK_CUDA_ERROR(::cudaStreamSynchronize(stream_));
} catch (const archetype::MmRosException & e) {
return archetype::Err<outputs_type>(archetype::MmRosError_t::CUDA, e.what());
return archetype::make_err<outputs_type>(archetype::MmRosError_t::CUDA, e.what());
}

outputs_type outputs;
Expand Down Expand Up @@ -234,6 +234,6 @@ archetype::Result<outputs_type> InstanceSegmenter2D::postprocess(
outputs.emplace_back(std::move(boxes), std::move(masks));
}

return archetype::Ok(outputs);
return archetype::make_ok(outputs);
}
} // namespace mmros::detector
14 changes: 7 additions & 7 deletions mmros/src/detector/panoptic_segmenter2d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,21 +76,21 @@ archetype::Result<outputs_type> PanopticSegmenter2D::doInference(
const std::vector<cv::Mat> & images) noexcept
{
if (images.empty()) {
return archetype::Err<outputs_type>(archetype::MmRosError_t::UNKNOWN, "No image.");
return archetype::make_err<outputs_type>(archetype::MmRosError_t::UNKNOWN, "No image.");
}

// 1. Init CUDA pointers
try {
initCudaPtr(images.size());
} catch (const archetype::MmRosException & e) {
return archetype::Err<outputs_type>(archetype::MmRosError_t::CUDA, e.what());
return archetype::make_err<outputs_type>(archetype::MmRosError_t::CUDA, e.what());
}

// 2. Execute preprocess
try {
preprocess(images);
} catch (const archetype::MmRosException & e) {
return archetype::Err<outputs_type>(archetype::MmRosError_t::CUDA, e.what());
return archetype::make_err<outputs_type>(archetype::MmRosError_t::CUDA, e.what());
}

// 3. Set tensors
Expand All @@ -100,14 +100,14 @@ archetype::Result<outputs_type> PanopticSegmenter2D::doInference(
if (!trt_common_->setTensorsAddresses(buffers)) {
std::ostringstream os;
os << "@" << __FILE__ << ", #F:" << __FUNCTION__ << ", #L:" << __LINE__;
return archetype::Err<outputs_type>(archetype::MmRosError_t::TENSORRT, os.str());
return archetype::make_err<outputs_type>(archetype::MmRosError_t::TENSORRT, os.str());
}

// 4. Execute inference
if (!trt_common_->enqueueV3(stream_)) {
std::ostringstream os;
os << "@" << __FILE__ << ", #F:" << __FUNCTION__ << ", #L:" << __LINE__;
return archetype::Err<outputs_type>(archetype::MmRosError_t::TENSORRT, os.str());
return archetype::make_err<outputs_type>(archetype::MmRosError_t::TENSORRT, os.str());
}

// 5. Execute postprocess
Expand Down Expand Up @@ -216,7 +216,7 @@ archetype::Result<outputs_type> PanopticSegmenter2D::postprocess(
::cudaMemcpyDeviceToHost, stream_));
CHECK_CUDA_ERROR(cudaStreamSynchronize(stream_));
} catch (const archetype::MmRosException & e) {
return archetype::Err<outputs_type>(archetype::MmRosError_t::CUDA, e.what());
return archetype::make_err<outputs_type>(archetype::MmRosError_t::CUDA, e.what());
}

outputs_type output;
Expand Down Expand Up @@ -248,6 +248,6 @@ archetype::Result<outputs_type> PanopticSegmenter2D::postprocess(
output.emplace_back(std::move(boxes), std::move(mask));
}

return archetype::Ok(output);
return archetype::make_ok(output);
}
} // namespace mmros::detector
14 changes: 7 additions & 7 deletions mmros/src/detector/semantic_segmenter2d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,36 +78,36 @@ archetype::Result<outputs_type> SemanticSegmenter2D::doInference(
const std::vector<cv::Mat> & images) noexcept
{
if (images.empty()) {
return archetype::Err<outputs_type>(archetype::MmRosError_t::UNKNOWN, "No image.");
return archetype::make_err<outputs_type>(archetype::MmRosError_t::UNKNOWN, "No image.");
}

// 1. Init CUDA pointers
try {
initCudaPtr(images.size());
} catch (const archetype::MmRosException & e) {
return archetype::Err<outputs_type>(archetype::MmRosError_t::CUDA, e.what());
return archetype::make_err<outputs_type>(archetype::MmRosError_t::CUDA, e.what());
}

// 2. Execute preprocess
try {
preprocess(images);
} catch (const archetype::MmRosException & e) {
return archetype::Err<outputs_type>(archetype::MmRosError_t::CUDA, e.what());
return archetype::make_err<outputs_type>(archetype::MmRosError_t::CUDA, e.what());
}

// 3. Set tensors
std::vector<void *> buffers{input_d_.get(), output_d_.get()};
if (!trt_common_->setTensorsAddresses(buffers)) {
std::ostringstream os;
os << "@" << __FILE__ << ", #F:" << __FUNCTION__ << ", #L:" << __LINE__;
return archetype::Err<outputs_type>(archetype::MmRosError_t::TENSORRT, os.str());
return archetype::make_err<outputs_type>(archetype::MmRosError_t::TENSORRT, os.str());
}

// 4. Execute inference
if (!trt_common_->enqueueV3(stream_)) {
std::ostringstream os;
os << "@" << __FILE__ << ", #F:" << __FUNCTION__ << ", #L:" << __LINE__;
return archetype::Err<outputs_type>(archetype::MmRosError_t::TENSORRT, os.str());
return archetype::make_err<outputs_type>(archetype::MmRosError_t::TENSORRT, os.str());
}

// 5. Execute postprocess
Expand Down Expand Up @@ -160,7 +160,7 @@ archetype::Result<outputs_type> SemanticSegmenter2D::postprocess(
output_h.data(), output_d_.get(),
sizeof(int64_t) * batch_size * 1 * output_width * output_height, ::cudaMemcpyDeviceToHost));
} catch (const archetype::MmRosException & e) {
return archetype::Err<outputs_type>(archetype::MmRosError_t::CUDA, e.what());
return archetype::make_err<outputs_type>(archetype::MmRosError_t::CUDA, e.what());
}

outputs_type output;
Expand Down Expand Up @@ -197,6 +197,6 @@ archetype::Result<outputs_type> SemanticSegmenter2D::postprocess(
output.push_back(std::move(final_mask));
}

return archetype::Ok(output);
return archetype::make_ok(output);
}
} // namespace mmros::detector
Loading