Skip to content

Commit

Permalink
fix: fix c++ code style
Browse files Browse the repository at this point in the history
Signed-off-by: liwuhen <liwuhen5788@gmail.com>
  • Loading branch information
liwuhen committed Nov 21, 2024
1 parent 449b54e commit 8834cf9
Show file tree
Hide file tree
Showing 24 changed files with 95 additions and 50 deletions.
8 changes: 7 additions & 1 deletion .github/workflows/linters.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,10 @@ jobs:
reporter: github-pr-check
level: warning
flags: --linelength=120
filter: "-runtime/references, -build/include"
filter: "-runtime/references,\
-build/include,\
-build/namespaces,\
-build/header_guard,\
-whitespace/line_length,\
-whitespace/indent_namespace,\
-runtime/string" # Ignore runtime checks on string usage.
4 changes: 3 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
cmake_minimum_required(VERSION 3.10.2)

option(ENABLE_CROSSCOMPILE "Enable crosscomplile for arm platform" OFF)
option(MODEL_FLAG "Enable crosscomplile model type")
set(MODEL_FLAG
"default"
CACHE STRING "Model configuration flag")

add_definitions("-Wall -g")
add_compile_options(-std=c++11)
Expand Down
2 changes: 1 addition & 1 deletion modules/app_yolo/appinterface/interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class InterfaceYolo {
return instance;
}

~InterfaceYolo(){};
~InterfaceYolo() {}

/**
* @brief init.
Expand Down
2 changes: 1 addition & 1 deletion modules/app_yolo/architecture/common/appconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class AppConfig {
REG_YAML_VAR(std::vector<int>, predict_dim_);

protected:
AppConfig(const std::string& config_filename);
explicit AppConfig(const std::string& config_filename);
~AppConfig() {}
std::string config_filename_;

Expand Down
19 changes: 18 additions & 1 deletion modules/app_yolo/architecture/cuda/gpu_decode.cu
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
/* ==================================================================
* Copyright (c) 2024, LiWuHen. All rights reserved.
*
* Licensed under the Apache License, Version 2.0
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an
BASIS
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ===================================================================
*/

#include <cuda_runtime.h>
#include <stdio.h>
Expand Down Expand Up @@ -97,7 +114,7 @@ static __global__ void fast_nms_kernel(float* bboxes, int max_objects, float thr
// 如果是日常推理, 则可以使用这个gpu nms
int position = (blockDim.x * blockIdx.x + threadIdx.x);
int count =
min((int)*bboxes, max_objects); // *bboxes表示首地址的第一个元素。 count是bbox的数量。
min(static_cast<int>(*bboxes), max_objects); // *bboxes表示首地址的第一个元素。 count是bbox的数量。
if (position >= count) return;

// left, top, right, bottom, confidence, class, keepflag
Expand Down
19 changes: 19 additions & 0 deletions modules/app_yolo/architecture/cuda/warpaffine.cu
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@

/* ==================================================================
* Copyright (c) 2024, LiWuHen. All rights reserved.
*
* Licensed under the Apache License, Version 2.0
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an
BASIS
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ===================================================================
*/

#include "warpaffine.hpp"

__device__ void affine_project(Matrix3f affineMatrix_inv, int x, int y, float* proj_x,
Expand Down
2 changes: 1 addition & 1 deletion modules/app_yolo/architecture/cuda/warpaffine.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ struct Norm {

static dim3 grid_dims(int numJobs) {
int numBlockThreads = numJobs < GPU_BLOCK_THREADS ? numJobs : GPU_BLOCK_THREADS;
return dim3(((numJobs * 10 + numBlockThreads - 1) / (float)numBlockThreads));
return dim3(((numJobs * 10 + numBlockThreads - 1) / static_cast<float>(numBlockThreads)));
}

static dim3 block_dims(int numJobs) {
Expand Down
4 changes: 2 additions & 2 deletions modules/app_yolo/architecture/decodeprocessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ bool DecodeProcessor::SetParam(shared_ptr<ParseMsgs>& parse_msgs) {
if (parse_msgs != nullptr) {
this->parsemsgs_ = parse_msgs;
}
imgshape_["dst"] = make_pair<int&, int&>(parsemsgs_->dst_img_h_, parsemsgs_->dst_img_w_);
imgshape_["dst"] = make_pair(parsemsgs_->dst_img_h_, parsemsgs_->dst_img_w_);

GLOG_INFO("[SetParam]: DecodeProcessor module set param ");
return true;
Expand All @@ -81,7 +81,7 @@ bool DecodeProcessor::DataResourceRelease() {}
*/
bool DecodeProcessor::Inference(float* predict, InfertMsg& infer_msg,
std::shared_ptr<InferMsgQue>& bboxQueue) {
imgshape_["src"] = make_pair<int, int>(infer_msg.height, infer_msg.width);
imgshape_["src"] = make_pair(infer_msg.height, infer_msg.width);

vector<Box> box_result;
CpuDecode(predict, box_result);
Expand Down
2 changes: 1 addition & 1 deletion modules/app_yolo/architecture/inference.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ bool InferenceEngine::InferenceV1() {
LOG(INFO) << " Begin inferenceV1 ... ";
auto image = cv::imread(parsemsgs_->img_path_);
auto data = trtInfer_->LoadFile(parsemsgs_->predict_path_);
float* ptr = (float*)data.data();
float* ptr = reinterpret_cast<float*>(data.data());
int nelem = data.size() / sizeof(float);
int nrows = nelem / 6.0; // 行数,预测的 object 的数量

Expand Down
2 changes: 1 addition & 1 deletion modules/app_yolo/architecture/module/module.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ using namespace hpc::common;
*/
class InferModuleBase {
public:
InferModuleBase(){};
InferModuleBase() {}
virtual ~InferModuleBase() = default;

virtual bool Init() = 0;
Expand Down
2 changes: 1 addition & 1 deletion modules/app_yolo/architecture/postprocessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ void PostProcessor::Inference() {
* @description: Visualization.
*/
void PostProcessor::Visualization(bool real_time, cv::Mat& img, int64_t timestamp,
vector<Box>& results) {
vector<Box>& results) {
for (auto& box : results) {
cv::rectangle(img, cv::Point(box.left, box.top), cv::Point(box.right, box.bottom),
cv::Scalar(0, 255, 0), 2);
Expand Down
15 changes: 9 additions & 6 deletions modules/app_yolo/architecture/preprocessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ bool PreProcessor::DataResourceRelease() {}
* @description: Inference.
*/
bool PreProcessor::Inference(InfertMsg& input_msg, float* dstimg, DeviceMode inferMode,
cudaStream_t stream) {
cudaStream_t stream) {
CalAffineMatrix(input_msg);

switch (inferMode) {
Expand All @@ -92,7 +92,6 @@ bool PreProcessor::Inference(InfertMsg& input_msg, float* dstimg, DeviceMode inf
break;
case DeviceMode::CPU_MODE:
if (!CpuPreprocessor(input_msg.image, input_msg.timestamp, dstimg, stream))
;
{ return false; }
break;
default:
Expand Down Expand Up @@ -126,8 +125,12 @@ bool PreProcessor::GpuPreprocessor(InfertMsg& input_msg, float* dstimg, cudaStre
/**
* @description: Cpu preprocessor.
*/
bool PreProcessor::CpuPreprocessor(cv::Mat& srcimg, uint64_t timestamp, float* input_device_gpu,
cudaStream_t stream) {
bool PreProcessor::CpuPreprocessor(
cv::Mat& srcimg,
uint64_t timestamp,
float* input_device_gpu,
cudaStream_t stream) {

checkRuntime(cudaMallocHost(&input_data_host_, sizeof(float) * parsemsgs_->dstimg_size_));

float scale_x = parsemsgs_->dst_img_w_ / static_cast<float>(parsemsgs_->src_img_w_);
Expand Down Expand Up @@ -176,8 +179,8 @@ bool PreProcessor::CpuPreprocessor(cv::Mat& srcimg, uint64_t timestamp, float* i
* @description: AffineMatrix.
*/
void PreProcessor::CalAffineMatrix(InfertMsg& input_msg) {
float scale_x = parsemsgs_->dst_img_w_ / (float)input_msg.width;
float scale_y = parsemsgs_->dst_img_h_ / (float)input_msg.height;
float scale_x = parsemsgs_->dst_img_w_ / static_cast<float>(input_msg.width);
float scale_y = parsemsgs_->dst_img_h_ / static_cast<float>(input_msg.height);
float scale = min(scale_x, scale_y);

input_msg.affineMatrix(0, 0) = scale;
Expand Down
8 changes: 4 additions & 4 deletions modules/app_yolo/architecture/trt_infer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ bool TrtInfer::Inference(float* output_img_device) {
output_img_device, parsemsgs_->dstimg_size_ * sizeof(uint8_t),
cudaMemcpyDeviceToDevice));

bool success = execution_context_->enqueueV2((void**)gpu_buffers_, stream_, nullptr);
bool success = execution_context_->enqueueV2(reinterpret_cast<void**>(gpu_buffers_), stream_, nullptr);
if (!success) {
LOG(ERROR) << " Inference failed ";
return false;
Expand Down Expand Up @@ -236,8 +236,8 @@ bool TrtInfer::ParseModel() {
string name = execution_context_->getEngine().getBindingName(i);
auto dim = execution_context_->getBindingDimensions(i);

switch (execution_context_->getEngine().bindingIsInput(i)) // < tensorrt 8.5
{
// < tensorrt 8.5
switch (execution_context_->getEngine().bindingIsInput(i)) {
case false:
out_size++;
binding_names_["output"].push_back(name);
Expand Down Expand Up @@ -323,7 +323,7 @@ std::vector<uint8_t> TrtInfer::LoadFile(const string& file) {
in.seekg(0, ios::beg);
data.resize(length);

in.read((char*)&data[0], length);
in.read(reinterpret_cast<char*>(&data[0]), length);
}
in.close();
return data;
Expand Down
2 changes: 1 addition & 1 deletion modules/app_yolo/architecture/utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ inline const char* severity_string(nvinfer1::ILogger::Severity t) {

class TRTLogger : public nvinfer1::ILogger {
public:
virtual void log(Severity severity, nvinfer1::AsciiChar const* msg) noexcept override {
void log(Severity severity, nvinfer1::AsciiChar const* msg) noexcept override {
if (severity <= Severity::kINFO) {
// 打印带颜色的字符,格式如下:
// printf("\033[47;33m 打印的文本\033[0m");
Expand Down
3 changes: 1 addition & 2 deletions modules/common/logging/logging.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
#ifndef TENSORRT_LOGGING_H
#define TENSORRT_LOGGING_H

//#include "NvInferRuntimeCommon.h"
#include <cassert>
#include <ctime>
#include <iomanip>
Expand Down Expand Up @@ -188,7 +187,7 @@ class LogStreamConsumer : protected LogStreamConsumerBase, public std::ostream {

class Logger : public nvinfer1::ILogger {
public:
Logger(Severity severity = Severity::kWARNING) : mReportableSeverity(severity) {}
explicit Logger(Severity severity = Severity::kWARNING) : mReportableSeverity(severity) {}

//!
//! \enum TestResult
Expand Down
4 changes: 2 additions & 2 deletions modules/common/msg_img/dataset.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ static const char* cocolabels[] = {"person", "bicycle", "car",
"oven", "toaster", "sink",
"refrigerator", "book", "clock",
"vase", "scissors", "teddy bear",
"hair drier", "toothbrush"};
"hair drier", "toothbrush"
};

// hsv 转 bgr
static std::tuple<uint8_t, uint8_t, uint8_t> hsv2bgr(float h, float s, float v) {
Expand Down Expand Up @@ -114,7 +115,6 @@ static std::tuple<uint8_t, uint8_t, uint8_t> hsv2bgr(float h, float s, float v)

static std::tuple<uint8_t, uint8_t, uint8_t> random_color(int id) {
float h_plane = ((((unsigned int)id << 2) ^ 0x937151) % 100) / 100.0f;
;
float s_plane = ((((unsigned int)id << 3) ^ 0x315793) % 100) / 100.0f;
return hsv2bgr(h_plane, s_plane, 1);
}
Expand Down
8 changes: 4 additions & 4 deletions modules/common/msg_img/img_msg.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,18 @@ class ImageInfos {
frame_id_ = 0;
timestamp_ = 0;
image_ = cv::Mat();
};
~ImageInfos(){};
}
~ImageInfos() {}

bool DeepCopy(const ImageInfos* src) {
this->image_ = src->image_.clone();
return true;
};
}

bool MoveCopy(const ImageInfos* src) {
this->image_ = std::move(src->image_);
return true;
};
}

public:
uint16_t width_;
Expand Down
16 changes: 8 additions & 8 deletions modules/common/msg_struct/task_struct.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,13 @@ struct Box {
this->confidence = obj.confidence;
this->label = obj.label;
return *this;
};
}
};

struct InfertMsg {
InfertMsg() : width(0), height(0), frame_id(0), timestamp(0), img_size(0) {
this->image = cv::Mat();
};
}

InfertMsg operator=(const InfertMsg& obj) {
this->width = obj.width;
Expand All @@ -73,7 +73,7 @@ struct InfertMsg {
this->bboxes.emplace_back(box);
}
return *this;
};
}

public:
uint32_t width;
Expand All @@ -96,10 +96,10 @@ struct CVImage {
std::vector<uint8_t> data; // 存储连续的像素值

CVImage();
CVImage(int width, int height, int channel)
: img_width(width), img_height(height), img_channel(channel), img_size(0){};
CVImage(int width, int height, int channel) : img_width(width), \
img_height(height), img_channel(channel), img_size(0) {}

~CVImage(){};
~CVImage() {}

CVImage operator=(const CVImage& obj) {
this->img_width = obj.img_width;
Expand All @@ -110,15 +110,15 @@ struct CVImage {
std::memcpy(data.data(), obj.data.data(), length); // 拷贝数据
}
return *this;
};
}

// 指针类型
void setDataFromArray(const uint8_t* obj, int size) {
img_size = img_width * img_height * img_channel;
if (obj != nullptr && size <= img_size) {
std::memcpy(data.data(), obj, size); // 拷贝数据
}
};
}
};

using InputMsgQue = MsgQueue<InfertMsg>;
Expand Down
2 changes: 1 addition & 1 deletion modules/common/utils/colorprintf.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
namespace hpc {
namespace common {

//颜色宏定义
// 颜色宏定义
#define NONEC "\033[0m"
#define RED "\033[1;32;31m"
#define LIGHT_RED "\033[1;31m"
Expand Down
2 changes: 1 addition & 1 deletion modules/common/utils/glog_msg.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class GlogMsg {
~GlogMsg() {
google::FlushLogFiles(google::GLOG_INFO);
google::ShutdownGoogleLogging();
};
}
bool init_ = false;
std::mutex glog_mutex_;
std::shared_ptr<ParseMsgs> ParseMsgs_;
Expand Down
6 changes: 3 additions & 3 deletions modules/common/utils/std_buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ namespace common {
template <typename T>
class MsgQueue {
public:
MsgQueue(int length) { length_ = std::max(1, length); };
explicit MsgQueue(int length) { length_ = std::max(1, length); }
~MsgQueue() = default;
void Push(const T& message);
int Size() const;
Expand All @@ -57,7 +57,7 @@ template <typename T>
void MsgQueue<T>::Push(const T& message) {
std::unique_lock<std::mutex> lock(mutex_);
queue_.push(message);
while ((int)queue_.size() > length_) {
while (static_cast<int>(queue_.size()) > length_) {
queue_.pop();
}
lock.unlock();
Expand Down Expand Up @@ -100,7 +100,7 @@ void MsgQueue<T>::Clear() {
while (!queue_.empty()) {
queue_.pop();
}
};
}

} // namespace common
} // namespace hpc
Expand Down
Loading

0 comments on commit 8834cf9

Please sign in to comment.