Skip to content
This repository has been archived by the owner on Feb 2, 2024. It is now read-only.

Commit

Permalink
Update cppcheck to 1.85 (ROCm#1358)
Browse files Browse the repository at this point in the history
* Update cppcheck version

* Fix several cppcheck issues

* Formatting

* Fix some knownConditionTrue issues

* Formatting

* Call JoinStrings

* Formatting

* Remove stray semicolon

* remove unused variable
  • Loading branch information
pfultz2 authored and Daniel Lowell committed Nov 27, 2018
1 parent 17a492c commit 7f20999
Show file tree
Hide file tree
Showing 16 changed files with 52 additions and 71 deletions.
2 changes: 1 addition & 1 deletion cmake/CppCheck.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ macro(enable_cppcheck)
${CPPCHECK_FORCE}
--cppcheck-build-dir=${CPPCHECK_BUILD_DIR}
--platform=native
\"--template={file}:{line}: {severity}: {message} [{id}]\"
--template=gcc
--error-exitcode=1
-j ${CPPCHECK_JOBS}
${CPPCHECK_DEFINES}
Expand Down
2 changes: 1 addition & 1 deletion dev-requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pfultz2/rocm-recipes
ROCm-Developer-Tools/HIP@3a41f286203968421c557338d6fb39c36f3c717c
-f requirements.txt
danmar/cppcheck@fe1b1d537ecaa0e573000f7d073a0e661e3256f2
danmar/cppcheck@1.85
10 changes: 6 additions & 4 deletions src/fusion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1057,10 +1057,12 @@ std::vector<Exec_arg_t> FusionPlanDescriptor::CalcArgOrder(Handle& handle)
{
auto keys = ptr_map.at(idx);
std::sort(keys.begin(), keys.end());
for(auto& key : keys)
{
arg_keys.emplace_back(key, Pointer, sizeof(ConstData_t));
}
std::transform(keys.begin(),
keys.end(),
std::back_inserter(arg_keys),
[&](auto&& key) -> Exec_arg_t {
return {key, Pointer, sizeof(ConstData_t)};
});
}
}
if(kernel_source_type == AsmText)
Expand Down
6 changes: 1 addition & 5 deletions src/include/miopen/hipoc_kernel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,7 @@ struct KernelArgsPack<>
template <class... Ts>
struct KernelArgs
{
KernelArgs(Ts... xs) : pack(xs...)
{
for(auto& x : hidden)
x = 0;
}
KernelArgs(Ts... xs) : pack(xs...) { std::fill(std::begin(hidden), std::end(hidden), 0); }
KernelArgsPack<Ts...> pack;
uint64_t hidden[6] = {};
};
Expand Down
15 changes: 6 additions & 9 deletions src/include/miopen/logger.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#ifndef GUARD_MIOPEN_LOGGER_HPP
#define GUARD_MIOPEN_LOGGER_HPP

#include <algorithm>
#include <array>
#include <iostream>
#include <miopen/each_args.hpp>
Expand Down Expand Up @@ -166,15 +167,11 @@ std::array<T, sizeof...(Ts) + 1> make_array(T x, Ts... xs)
template <class T, class Range>
std::ostream& LogEnum(std::ostream& os, T x, Range&& values)
{
for(auto&& p : values)
{
if(p.second == x)
{
os << p.first;
return os;
}
}
os << "Unknown: " << x;
auto it = std::find_if(values.begin(), values.end(), [&](auto&& p) { return p.second == x; });
if(it == values.end())
os << "Unknown: " << x;
else
os << it->first;
return os;
}

Expand Down
9 changes: 3 additions & 6 deletions src/include/miopen/solver.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -272,12 +272,9 @@ auto SearchForSolution(const Context& search_params, Db db) ->
template <class Solution>
static inline bool IsPureOpenCLSolution(const Solution& s)
{
for(auto& k : s.construction_params)
{
if(!miopen::EndsWith(k.kernel_file, ".cl"))
return false;
}
return true;
return std::all_of(s.construction_params.begin(),
s.construction_params.end(),
[](const auto& k) { return miopen::EndsWith(k.kernel_file, ".cl"); });
}

// Search for all applicable solutions among many solvers
Expand Down
7 changes: 3 additions & 4 deletions src/kernel_warnings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
#include <iterator>
#include <miopen/config.h>
#include <miopen/kernel_warnings.hpp>
#include <miopen/stringutils.hpp>
#include <numeric>
#include <sstream>

namespace miopen {
Expand All @@ -51,16 +53,13 @@ std::vector<std::string> KernelWarnings()

std::string MakeKernelWarningsString()
{
std::string result;
#if MIOPEN_BACKEND_OPENCL
std::string prefix = " -Wf,";

#else
std::string prefix = " ";
#endif
for(auto&& x : KernelWarnings())
result += prefix + x;
return result;
return prefix + JoinStrings(KernelWarnings(), prefix);
}

const std::string& KernelWarningsString()
Expand Down
31 changes: 17 additions & 14 deletions src/md_graph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,14 +191,13 @@ bool FusionMDGraph::SetConvAlgo(miopenConvFwdAlgorithm_t algo)

for(auto& kinder : cur_vertex)
{
MDGraph_vertex_ptr& cur_vertex_ptr = kinder.first;
auto& cur_map = kinder.second;
auto& cur_map = kinder.second;
if(cur_map.find("algo") != cur_map.end())
{
miopenConvFwdAlgorithm_t a = boost::any_cast<miopenConvFwdAlgorithm_t>(cur_map["algo"]);
if(a == algo)
{
new_list.emplace_back(cur_vertex_ptr, cur_map);
new_list.emplace_back(kinder.first, cur_map);
}
}
else
Expand Down Expand Up @@ -1088,19 +1087,23 @@ bool FusionMDGraph::CmpOpKey(const FusionMDGraph_Edge_Map& edge_val,
auto op_val = op->MDGraphKey();
if(op_val.count(kv.first) == 1)
{
for(auto& edg_ops : kv.second)
auto edg_op_it =
std::find_if(kv.second.begin(), kv.second.end(), [&](auto&& edg_ops) {
return !FusionMDGraph::ExecEdgeOp(edg_ops, op_val.at(kv.first).at(0));
});
if(edg_op_it == kv.second.end())
{
if(!FusionMDGraph::ExecEdgeOp(edg_ops, op_val.at(kv.first).at(0)))
{
MIOPEN_LOG_I2("Edge Op :" << edg_ops << " Op Val: "
<< op_val.at(kv.first).at(0)
<< " Edge Op for key: "
<< kv.first
<< " Failed");
return false;
}
MIOPEN_LOG_I2("Edge Op for key: " << kv.first << " Successfull");
}
else
{
MIOPEN_LOG_I2("Edge Op :" << *edg_op_it << " Op Val: "
<< op_val.at(kv.first).at(0)
<< " Edge Op for key: "
<< kv.first
<< " Failed");
return false;
}
MIOPEN_LOG_I2("Edge Op for key: " << kv.first << " Successfull");
}
else
{
Expand Down
1 change: 1 addition & 0 deletions src/ocl/convolutionocl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1016,6 +1016,7 @@ void ConvolutionDescriptor::FindConvFwdAlgorithm(Handle& handle,
ProblemDescription problem(xDesc, wDesc, yDesc, *this, 1);

const auto find_db_path = GetFindDbPath() + "/" + handle.GetDbPathFilename() + ".cd.fdb.txt";
(void)find_db_path;
auto record =
boost::optional<DbRecord>{boost::none}; // Db{find_db_path, false}.FindRecord(problem);
auto loaded = record.is_initialized();
Expand Down
5 changes: 2 additions & 3 deletions src/solver/conv_asm_3x3u.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,8 @@ bool PerformanceConfigConvAsm3x3U::IsValid(const ConvolutionContext& config) con
assert(active_lanes != 0);
if(active_lanes == 0)
return false;
const bool uneven_line_read_mode = (img_x_blocks % active_lanes != 0);
const bool uneven_line_write_mode = (img_width % active_lanes != 0);
if(uneven_line_read_mode || uneven_line_write_mode)
const bool uneven_line_read_mode = (img_x_blocks % active_lanes != 0);
if(uneven_line_read_mode)
++n;

const int block_size_x = 1;
Expand Down
1 change: 1 addition & 0 deletions src/solver/conv_ocl_dir2D11x11.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ ConvSolution ConvOclDirectFwd11x11::GetSolution(const ConvolutionContext& params

// param
// 6 get us the min
// cppcheck-suppress knownConditionTrueFalse
static const int backwards_min_output = (data_multiplier1 > 1 || data_multiplier0 > 1) ? 1 : 4;
result.n_out_pix_tiles = (is_forward)
? std::min(6, (params.n_outputs + n_out_stacks - 1) / n_out_stacks)
Expand Down
12 changes: 6 additions & 6 deletions test/args.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include <functional>

#include <miopen/each_args.hpp>
#include <numeric>
#include <sstream>
#include <stdexcept>
#include <string>
Expand Down Expand Up @@ -274,12 +275,11 @@ struct read_value
ARGS_REQUIRES(is_container<Container>{} and not is_output_streamable<Container>{})>
std::string operator()(Container& xs) const
{
std::string result;
for(auto&& x : xs)
{
result += (*this)(x) + " ";
}
return result;
if(xs.begin() == xs.end())
return "";
return std::accumulate(xs.begin() + 1, xs.end(), (*this)(*xs.begin()), [&](auto x, auto y) {
return x + " " + (*this)(y);
});
}

template <class T, ARGS_REQUIRES(is_output_streamable<T>{})>
Expand Down
4 changes: 1 addition & 3 deletions test/gru.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2853,9 +2853,7 @@ struct gru_driver : test_driver
std::cout << "batch seq[" << i << "]: " << batchSeq.at(i) << std::endl;
}
#endif
int batch_n = 0;
for(auto& n : batchSeq)
batch_n += n;
int batch_n = std::accumulate(batchSeq.begin(), batchSeq.end(), 0);

miopenRNNDescriptor_t rnnDesc;
miopenCreateRNNDescriptor(&rnnDesc);
Expand Down
4 changes: 1 addition & 3 deletions test/lstm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2669,9 +2669,7 @@ struct lstm_driver : test_driver

auto&& handle = get_handle();

int batch_n = 0;
for(auto& n : batchSeq)
batch_n += n;
int batch_n = std::accumulate(batchSeq.begin(), batchSeq.end(), 0);

miopenRNNDescriptor_t rnnDesc;
miopenCreateRNNDescriptor(&rnnDesc);
Expand Down
10 changes: 1 addition & 9 deletions test/rnn_util.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,15 +108,7 @@ inline std::vector<std::vector<int>> generate_batchSeq(const int batchSize, cons
return {batchSeq};
}

inline int sumvc(const std::vector<int>& x)
{
int sum = 0;
for(int i : x)
{
sum += i;
}
return sum;
}
inline int sumvc(const std::vector<int>& x) { return std::accumulate(x.begin(), x.end(), 0); }

inline float activfunc(float x, int actvf)
{
Expand Down
4 changes: 1 addition & 3 deletions test/rnn_vanilla.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2269,9 +2269,7 @@ struct rnn_vanilla_driver : test_driver

auto&& handle = get_handle();

int batch_n = 0;
for(auto& n : batchSeq)
batch_n += n;
int batch_n = std::accumulate(batchSeq.begin(), batchSeq.end(), 0);

miopenRNNDescriptor_t rnnDesc;
miopenCreateRNNDescriptor(&rnnDesc);
Expand Down

0 comments on commit 7f20999

Please sign in to comment.