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