未验证 提交 c000091e 编写于 作者: G gouzil 提交者: GitHub

[clang-tidy] NO.6 enable `modernize-avoid-c-arrays` check (#55774)

* [clang-tidy] modernize-avoid-c-arrays

* rollback

* [clang-tidy] fix

* close modernize-avoid-c-arrays

* fix PHI_DEFINE_string; add PHI_DEFINE_bool NOLINT

* fix PHI_DEFINE_string

* fix next_h_state and parity err

* fix win32

* fix cuda_graph

* fix accuracy_kernel

* fix math_function

* fix fused_softmax_mask_kernel.cu load_data and warp_reduce; rollback concat_and_split_functor ins_addr

* fix fused_dropout_add_grad_kernel

* fix

* rollback cu

* rollback concat_and_split_functor.cu

* rollback
上级 22c7a6eb
......@@ -20,7 +20,7 @@
namespace ir {
const char *ModuleOp::attributes_name[attributes_num] = {"program"};
const char *ModuleOp::attributes_name[attributes_num] = {"program"}; // NOLINT
Program *ModuleOp::program() {
const AttributeMap &attr = this->attributes();
......@@ -67,7 +67,7 @@ void ModuleOp::Verify() const {
IR_ENFORCE(num_results() == 0u, "The size of inputs must be equal to 0.");
}
const char *GetParameterOp::attributes_name[attributes_num] = {
const char *GetParameterOp::attributes_name[attributes_num] = { // NOLINT
"parameter_name"};
void GetParameterOp::Build(Builder &builder,
......@@ -94,7 +94,7 @@ void GetParameterOp::Verify() const {
IR_ENFORCE(num_results() == 1u, "The size of outputs must be equal to 1.");
}
const char *SetParameterOp::attributes_name[attributes_num] = {
const char *SetParameterOp::attributes_name[attributes_num] = { // NOLINT
"parameter_name"};
void SetParameterOp::Build(Builder &builder, // NOLINT
......@@ -161,7 +161,7 @@ void CombineOp::Verify() const {
}
}
const char *SliceOp::attributes_name[attributes_num] = {"index"};
const char *SliceOp::attributes_name[attributes_num] = {"index"}; // NOLINT
void SliceOp::Verify() const {
// inputs.size() == 1
auto input_size = num_operands();
......@@ -207,7 +207,7 @@ void SliceOp::Verify() const {
output_type);
}
const char *ConstantOp::attributes_name[attributes_num] = {"value"};
const char *ConstantOp::attributes_name[attributes_num] = {"value"}; // NOLINT
void ConstantOp::Build(Builder &builder,
OperationArgument &argument,
......
......@@ -30,7 +30,7 @@
namespace ir {
namespace {
constexpr char newline[] = "\n";
constexpr char newline[] = "\n"; // NOLINT
} // namespace
void BasicIrPrinter::PrintType(Type type) {
......
......@@ -22,7 +22,7 @@ OpInfo OpInfoImpl::Create(Dialect *dialect,
std::vector<InterfaceValue> &&interface_map,
const std::vector<TypeId> &trait_set,
size_t attributes_num,
const char *attributes_name[],
const char *attributes_name[], // NOLINT
VerifyPtr verify) {
// (1) Malloc memory for interfaces, traits, opinfo_impl.
size_t interfaces_num = interface_map.size();
......
......@@ -13,6 +13,7 @@ See the License for the specific language governing permissions and
limitations under the License. */
#include "paddle/phi/backends/cpu/cpu_info.h"
#include <array>
#ifdef __APPLE__
#include <sys/sysctl.h>
......@@ -43,7 +44,7 @@ DECLARE_double(fraction_of_cuda_pinned_memory_to_use);
// between host and device. Allocates too much would reduce the amount
// of memory available to the system for paging. So, by default, we
// should set false to use_pinned_memory.
PHI_DEFINE_EXPORTED_bool(use_pinned_memory,
PHI_DEFINE_EXPORTED_bool(use_pinned_memory, // NOLINT
true,
"If set, allocate cpu pinned memory.");
......@@ -53,12 +54,12 @@ namespace cpu {
size_t CpuTotalPhysicalMemory() {
#ifdef __APPLE__
int mib[2];
std::array<int, 2> mib;
mib[0] = CTL_HW;
mib[1] = HW_MEMSIZE;
int64_t size = 0;
size_t len = sizeof(size);
if (sysctl(mib, 2, &size, &len, NULL, 0) == 0) {
if (sysctl(mib.data(), 2, &size, &len, NULL, 0) == 0) {
return static_cast<size_t>(size);
}
return 0L;
......
......@@ -29,48 +29,54 @@ limitations under the License. */
#include "glog/logging.h"
#include "paddle/phi/core/flags.h"
PHI_DEFINE_string(cudnn_dir,
PHI_DEFINE_string(cudnn_dir, // NOLINT
"",
"Specify path for loading libcudnn.so. For instance, "
"/usr/local/cudnn/lib. If empty [default], dlopen "
"will search cudnn from LD_LIBRARY_PATH");
PHI_DEFINE_string(
PHI_DEFINE_string( // NOLINT
cuda_dir,
"",
"Specify path for loading cuda library, such as libcublas, libcublasLt "
"libcurand, libcusolver. For instance, /usr/local/cuda/lib64. "
"If default, dlopen will search cuda from LD_LIBRARY_PATH");
PHI_DEFINE_string(nccl_dir,
PHI_DEFINE_string(nccl_dir, // NOLINT
"",
"Specify path for loading nccl library, such as libnccl.so. "
"For instance, /usr/local/cuda/lib64. If default, "
"dlopen will search cuda from LD_LIBRARY_PATH");
PHI_DEFINE_string(cupti_dir, "", "Specify path for loading cupti.so.");
PHI_DEFINE_string(cupti_dir,
"",
"Specify path for loading cupti.so."); // NOLINT
PHI_DEFINE_string(
PHI_DEFINE_string( // NOLINT
tensorrt_dir,
"",
"Specify path for loading tensorrt library, such as libnvinfer.so.");
PHI_DEFINE_string(mklml_dir, "", "Specify path for loading libmklml_intel.so.");
PHI_DEFINE_string(mklml_dir,
"",
"Specify path for loading libmklml_intel.so."); // NOLINT
PHI_DEFINE_string(lapack_dir, "", "Specify path for loading liblapack.so.");
PHI_DEFINE_string(lapack_dir,
"",
"Specify path for loading liblapack.so."); // NOLINT
PHI_DEFINE_string(mkl_dir,
PHI_DEFINE_string(mkl_dir, // NOLINT
"",
"Specify path for loading libmkl_rt.so. "
"For insrance, /opt/intel/oneapi/mkl/latest/lib/intel64/."
"If default, "
"dlopen will search mkl from LD_LIBRARY_PATH");
PHI_DEFINE_string(op_dir,
PHI_DEFINE_string(op_dir, // NOLINT
"",
"Specify path for loading user-defined op library.");
PHI_DEFINE_string(cusparselt_dir,
PHI_DEFINE_string(cusparselt_dir, // NOLINT
"",
"Specify path for loading libcusparseLt.so.");
......@@ -107,13 +113,13 @@ struct PathNode {
std::string path = "";
};
static constexpr char cupti_lib_path[] = CUPTI_LIB_PATH;
static constexpr char cupti_lib_path[] = CUPTI_LIB_PATH; // NOLINT
// NOTE: In order to adapt to the default installation path of cuda
#if defined(_WIN32) && defined(PADDLE_WITH_CUDA)
static constexpr char cuda_lib_path[] = CUDA_TOOLKIT_ROOT_DIR "/bin";
#else
static constexpr char cuda_lib_path[] = "/usr/local/cuda/lib64";
static constexpr char cuda_lib_path[] = "/usr/local/cuda/lib64"; // NOLINT
#endif
static PathNode s_py_site_pkg_path;
......
......@@ -14,6 +14,7 @@
#include <paddle/phi/backends/dynload/port.h>
#include <array>
#include <memory>
#include <stdexcept>
#include <string>
......@@ -74,7 +75,7 @@ int gettimeofday(struct timeval *tp, void *tzp) {
#endif // !_WIN32
void ExecShellCommand(const std::string &cmd, std::string *message) {
char buffer[128];
std::array<char, 128> buffer;
#if !defined(_WIN32)
std::shared_ptr<FILE> pipe(popen(cmd.c_str(), "r"), pclose);
#else
......@@ -85,8 +86,8 @@ void ExecShellCommand(const std::string &cmd, std::string *message) {
return;
}
while (!feof(pipe.get())) {
if (fgets(buffer, 128, pipe.get()) != nullptr) {
*message += buffer;
if (fgets(buffer.data(), 128, pipe.get()) != nullptr) {
*message += buffer.data();
}
}
}
......
......@@ -14,6 +14,7 @@
#include "paddle/phi/backends/gpu/cuda/cuda_graph.h"
#include <array>
#include <queue>
#include <unordered_map>
#include <unordered_set>
......@@ -277,14 +278,14 @@ bool CUDAGraph::IsValidCapturing() {
static std::string ConcatPath(const std::string &dirname,
const std::string &filename) {
#ifdef _WIN32
const char kFileSep[] = "\\";
const std::array<char, 3> kFileSep = {"\\"};
#else
const char kFileSep[] = "/";
const std::array<char, 2> kFileSep = {"/"};
#endif
if (!dirname.empty() && dirname.back() == kFileSep[0]) {
return dirname + filename;
} else {
return dirname + kFileSep + filename;
return dirname + kFileSep.data() + filename;
}
}
......
......@@ -13,6 +13,7 @@
// limitations under the License.
#include "paddle/phi/core/distributed/store/socket.h"
#include <array>
#ifndef _WIN32
#include <arpa/inet.h>
......@@ -42,21 +43,21 @@ static int _get_sockname(int sock, char *out, int out_len) {
return -1;
}
char ip[128];
std::array<char, 128> ip;
int port = 0;
// deal with both IPv4 and IPv6:
if (addr.sin_family == AF_INET) {
struct sockaddr_in *s = (struct sockaddr_in *)&addr;
port = ntohs(s->sin_port);
::inet_ntop(AF_INET, &s->sin_addr, ip, sizeof(ip));
::inet_ntop(AF_INET, &s->sin_addr, ip.data(), sizeof(ip));
} else { // AF_INET6
struct sockaddr_in6 *s = (struct sockaddr_in6 *)&addr;
port = ntohs(s->sin6_port);
::inet_ntop(AF_INET6, &s->sin6_addr, ip, sizeof(ip));
::inet_ntop(AF_INET6, &s->sin6_addr, ip.data(), sizeof(ip));
}
::snprintf(out, out_len, "%s:%d", ip, port);
::snprintf(out, out_len, "%s:%d", ip.data(), port);
return 0;
}
#endif
......@@ -70,9 +71,9 @@ int GetSockName(int sock, char* out, int out_len) {
}
std::string GetSockName(int fd) {
char out[256];
GetSockName(fd, out, sizeof(out));
return std::string(out);
std::array<char, 256> out;
GetSockName(fd, out.data(), sizeof(out));
return std::string(out.data());
}
} // namespace distributed
......
......@@ -14,6 +14,7 @@ limitations under the License. */
#include "paddle/phi/core/enforce.h"
#include <array>
#include <map>
#include <memory>
#include <unordered_map>
......@@ -141,9 +142,9 @@ std::string GetCurrentTraceBackString(bool for_signal) {
#if !defined(_WIN32) && !defined(PADDLE_WITH_MUSL)
static constexpr int TRACE_STACK_LIMIT = 100;
void* call_stack[TRACE_STACK_LIMIT];
auto size = backtrace(call_stack, TRACE_STACK_LIMIT);
auto symbols = backtrace_symbols(call_stack, size);
std::array<void*, TRACE_STACK_LIMIT> call_stack;
auto size = backtrace(call_stack.data(), TRACE_STACK_LIMIT);
auto symbols = backtrace_symbols(call_stack.data(), size);
Dl_info info;
int idx = 0;
// `for_signal` used to remove the stack trace introduced by
......
......@@ -470,7 +470,7 @@ PHI_DEFINE_EXPORTED_double(
* Example:
* Note: For selecting allocator policy of PaddlePaddle.
*/
static constexpr char kDefaultAllocatorStrategy[] = "auto_growth";
static constexpr char kDefaultAllocatorStrategy[] = "auto_growth"; // NOLINT
PHI_DEFINE_EXPORTED_string(
allocator_strategy,
kDefaultAllocatorStrategy,
......@@ -1060,13 +1060,13 @@ DEFINE_int32(record_pool_max_size,
2000000,
"SlotRecordDataset slot record pool max size");
DEFINE_int32(slotpool_thread_num, 1, "SlotRecordDataset slot pool thread num");
DEFINE_bool(enable_slotpool_wait_release,
DEFINE_bool(enable_slotpool_wait_release, // NOLINT
false,
"enable slotrecord object wait release, default false");
DEFINE_bool(enable_slotrecord_reset_shrink,
DEFINE_bool(enable_slotrecord_reset_shrink, // NOLINT
false,
"enable slotrecord object reset shrink memory, default false");
DEFINE_bool(enable_ins_parser_file,
DEFINE_bool(enable_ins_parser_file, // NOLINT
false,
"enable parser ins file, default false");
PHI_DEFINE_EXPORTED_bool(
......
......@@ -14,6 +14,7 @@
#pragma once
#include <array>
#include <cstdint>
#include <map>
#include <string>
......@@ -83,7 +84,7 @@
#define PHI_DEFINE_bool(name, val, txt) \
namespace fLB { \
typedef ::fLB::CompileAssert FLAG_##name##_value_is_not_a_bool \
typedef ::fLB::CompileAssert FLAG_##name##_value_is_not_a_bool /* NOLINT */ \
[(sizeof(::fLB::IsBoolFlag(val)) != sizeof(double)) ? 1 : -1]; \
} \
PHI_DEFINE_VARIABLE(bool, B, name, val, txt)
......@@ -107,19 +108,20 @@
namespace fLS { \
using ::fLS::clstring; \
using ::fLS::StringFlagDestructor; \
static union { \
static union { /* NOLINT */ \
void* align; \
char s[sizeof(clstring)]; \
} s_##name[2]; \
std::array<char, sizeof(clstring)> s; \
} s_##name[2]; /* NOLINT */ \
clstring* const FLAGS_no##name = \
::fLS::dont_pass0toDEFINE_string(s_##name[0].s, val); \
::fLS::dont_pass0toDEFINE_string(s_##name[0].s.data(), val); \
static GFLAGS_NAMESPACE::FlagRegisterer o_##name( \
#name, \
MAYBE_STRIPPED_HELP(txt), \
__FILE__, \
FLAGS_no##name, \
new (s_##name[1].s) clstring(*FLAGS_no##name)); \
static StringFlagDestructor d_##name(s_##name[0].s, s_##name[1].s); \
new (s_##name[1].s.data()) clstring(*FLAGS_no##name)); \
static StringFlagDestructor d_##name(s_##name[0].s.data(), \
s_##name[1].s.data()); \
extern PHI_EXPORT_FLAG clstring& FLAGS_##name; \
using fLS::FLAGS_##name; \
clstring& FLAGS_##name = *FLAGS_no##name; \
......
......@@ -24,6 +24,7 @@
**/
#include "paddle/phi/kernels/funcs/gpc.h"
#include <array>
#include "paddle/phi/core/enforce.h"
......@@ -43,7 +44,7 @@ typedef struct sbt_t_shape { /* Scanbeam tree */
} sb_tree;
typedef struct it_shape { /* Intersection table */
edge_node *ie[2]; /* Intersecting edge (bundle) pair */
std::array<edge_node *, 2> ie; /* Intersecting edge (bundle) pair */
gpc_vertex point; /* Point of intersection */
struct it_shape *next; /* The next intersection table node */
} it_node;
......@@ -70,16 +71,15 @@ typedef struct bbox_shape { /* Contour axis-aligned bounding box */
*/
/* Horizontal edge state transitions within scanbeam boundary */
const h_state next_h_state[3][6] = {
/* ABOVE BELOW CROSS */
const std::array<std::array<h_state, 6>, 3> next_h_state = {
{/* ABOVE BELOW CROSS */
/* L R L R L R */
/* NH */
{BH, TH, TH, BH, NH, NH},
{{BH, TH, TH, BH, NH, NH}},
/* BH */
{NH, NH, NH, NH, TH, TH},
{{NH, NH, NH, NH, TH, TH}},
/* TH */
{NH, NH, NH, NH, BH, BH}};
{NH, NH, NH, NH, BH, BH}}};
/*
===========================================================================
Private Functions
......@@ -942,10 +942,10 @@ void gpc_polygon_clip(gpc_op op,
polygon_node *cf = NULL;
vertex_node *vtx = NULL;
vertex_node *nv = NULL;
h_state horiz[2];
int in[2];
int exists[2];
int parity[2] = {LEFT, LEFT};
std::array<h_state, 2> horiz;
std::array<int, 2> in;
std::array<int, 2> exists;
std::array<int, 2> parity = {LEFT, LEFT};
int c = 0;
int v = 0;
int contributing = 0;
......@@ -1586,11 +1586,11 @@ void gpc_tristrip_clip(gpc_op op,
vertex_node *ltn = NULL;
vertex_node *rt = NULL;
vertex_node *rtn = NULL;
h_state horiz[2];
std::array<h_state, 2> horiz;
vertex_type cft = NUL;
int in[2];
int exists[2];
int parity[2] = {LEFT, LEFT};
std::array<int, 2> in;
std::array<int, 2> exists;
std::array<int, 2> parity = {LEFT, LEFT};
int s = 0;
int v = 0;
int contributing = 0;
......
......@@ -13,6 +13,7 @@
* limitations under the License. */
#include "paddle/phi/kernels/funcs/jit/gen/act.h"
#include <array>
#include "paddle/phi/backends/cpu/cpu_info.h"
#include "paddle/phi/kernels/funcs/jit/registry.h"
......@@ -21,7 +22,7 @@ namespace phi {
namespace jit {
namespace gen {
const float ALIGN32_BEG exp_float_consts[] ALIGN32_END = {
const float ALIGN32_BEG exp_float_consts[] ALIGN32_END = { // NOLINT
REPEAT_8TIMES(1.f),
REPEAT_8TIMES(2.f),
REPEAT_8TIMES(0.5f),
......@@ -40,8 +41,9 @@ const float ALIGN32_BEG exp_float_consts[] ALIGN32_END = {
REPEAT_8TIMES(SIGMOID_THRESHOLD_MAX),
REPEAT_8TIMES(SIGMOID_THRESHOLD_MIN)};
const int ALIGN32_BEG exp_int_0x7f[] ALIGN32_END = {REPEAT_8TIMES(0x7f)};
int ALIGN32_BEG g_tmp_mem[16] ALIGN32_END = {0};
const int ALIGN32_BEG exp_int_0x7f[] ALIGN32_END = {
REPEAT_8TIMES(0x7f)}; // NOLINT
int ALIGN32_BEG g_tmp_mem[16] ALIGN32_END = {0}; // NOLINT
void VActJitCode::genCode() {
int offset = 0;
......
......@@ -15,6 +15,7 @@
#include "paddle/phi/kernels/funcs/jit/kernel_key.h"
#include <xxhash.h> // XXH64: 13.8 GB/s
#include <array>
namespace phi {
namespace jit {
......@@ -36,18 +37,18 @@ int64_t JitCodeKey<gru_attr_t>(const gru_attr_t& attr) {
template <>
int64_t JitCodeKey<lstm_attr_t>(const lstm_attr_t& attr) {
int keys[5] = {attr.d,
std::array<int, 5> keys = {attr.d,
static_cast<int>(attr.act_gate),
static_cast<int>(attr.act_cand),
static_cast<int>(attr.act_cell),
static_cast<int>(attr.use_peephole)};
return XXH64(keys, sizeof(int) * 5, 0);
return XXH64(keys.data(), sizeof(int) * 5, 0);
}
template <>
int64_t JitCodeKey<seq_pool_attr_t>(const seq_pool_attr_t& attr) {
int keys[2] = {attr.w, static_cast<int>(attr.type)};
return XXH64(keys, sizeof(int) * 2, 0);
std::array<int, 2> keys = {attr.w, static_cast<int>(attr.type)};
return XXH64(keys.data(), sizeof(int) * 2, 0);
}
template <>
......
......@@ -16,7 +16,7 @@
#include "gflags/gflags.h"
DEFINE_bool(color, true, "Whether to turn on pretty log");
DEFINE_bool(color, true, "Whether to turn on pretty log"); // NOLINT
namespace paddle {
namespace string {} // namespace string
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册