未验证 提交 724adf49 编写于 作者: H huangjiyi 提交者: GitHub

update cinn flags usage (#56896)

* update

* update

* fix empty arg

* update test

* update

* fix bug

* update
上级 52d29f0d
...@@ -610,6 +610,9 @@ if(WITH_CINN) ...@@ -610,6 +610,9 @@ if(WITH_CINN)
add_subdirectory(python) add_subdirectory(python)
endif() endif()
add_subdirectory(test) add_subdirectory(test)
if(NOT WITH_GFLAGS)
add_subdirectory(paddle/utils)
endif()
return() return()
endif() endif()
endif() endif()
......
...@@ -114,10 +114,6 @@ include(cmake/cinn/core.cmake) ...@@ -114,10 +114,6 @@ include(cmake/cinn/core.cmake)
include(cmake/cinn/nvrtc.cmake) include(cmake/cinn/nvrtc.cmake)
include(cmake/cinn/nvtx.cmake) include(cmake/cinn/nvtx.cmake)
if(CINN_ONLY)
link_libraries(gflags)
endif()
set(LINK_FLAGS set(LINK_FLAGS
"-Wl,--version-script ${CMAKE_CURRENT_SOURCE_DIR}/cmake/cinn/export.map" "-Wl,--version-script ${CMAKE_CURRENT_SOURCE_DIR}/cmake/cinn/export.map"
CACHE INTERNAL "") CACHE INTERNAL "")
...@@ -183,9 +179,9 @@ if(WITH_MKL) ...@@ -183,9 +179,9 @@ if(WITH_MKL)
endif() endif()
endif() endif()
if(NOT WITH_GFLAGS) if(CINN_ONLY)
target_link_libraries(cinnapi gflags) target_link_libraries(cinnapi ${flags_dep})
add_dependencies(cinnapi gflags) add_dependencies(cinnapi ${flags_dep})
endif() endif()
if(WITH_GPU) if(WITH_GPU)
...@@ -242,9 +238,9 @@ function(gen_cinncore LINKTYPE) ...@@ -242,9 +238,9 @@ function(gen_cinncore LINKTYPE)
endif() endif()
endif() endif()
if(NOT WITH_GFLAGS) if(CINN_ONLY)
target_link_libraries(${CINNCORE_TARGET} gflags) target_link_libraries(${CINNCORE_TARGET} ${flags_dep})
add_dependencies(${CINNCORE_TARGET} gflags) add_dependencies(${CINNCORE_TARGET} ${flags_dep})
endif() endif()
if(WITH_GPU) if(WITH_GPU)
...@@ -272,6 +268,8 @@ set(PUBLISH_LIBS ON) ...@@ -272,6 +268,8 @@ set(PUBLISH_LIBS ON)
if(PUBLISH_LIBS) if(PUBLISH_LIBS)
set(core_includes set(core_includes
"${core_includes};paddle/cinn/runtime/cuda/cinn_cuda_runtime_source.cuh") "${core_includes};paddle/cinn/runtime/cuda/cinn_cuda_runtime_source.cuh")
set(core_includes
"${core_includes};paddle/utils/flags.h;paddle/utils/flags_native.h")
foreach(header ${core_includes}) foreach(header ${core_includes})
get_filename_component(prefix ${header} DIRECTORY) get_filename_component(prefix ${header} DIRECTORY)
file(COPY ${header} file(COPY ${header}
......
if(WITH_TESTING) if(WITH_TESTING)
cinn_cc_library(cinn_gtest_main SRCS gtest_main.cc DEPS gtest gflags) cinn_cc_library(cinn_gtest_main SRCS gtest_main.cc DEPS gtest ${flags_dep})
endif() endif()
add_subdirectory(api) add_subdirectory(api)
......
...@@ -32,7 +32,7 @@ ...@@ -32,7 +32,7 @@
#include "paddle/cinn/ir/ir_base.h" #include "paddle/cinn/ir/ir_base.h"
#include "paddle/cinn/runtime/flags.h" #include "paddle/cinn/runtime/flags.h"
DECLARE_bool(auto_schedule_use_cost_model); PD_DECLARE_bool(auto_schedule_use_cost_model);
namespace cinn { namespace cinn {
namespace auto_schedule { namespace auto_schedule {
......
...@@ -34,7 +34,7 @@ ...@@ -34,7 +34,7 @@
#include "paddle/cinn/ir/utils/ir_copy.h" #include "paddle/cinn/ir/utils/ir_copy.h"
#include "paddle/cinn/runtime/flags.h" #include "paddle/cinn/runtime/flags.h"
DECLARE_bool(auto_schedule_use_cost_model); PD_DECLARE_bool(auto_schedule_use_cost_model);
namespace cinn { namespace cinn {
namespace auto_schedule { namespace auto_schedule {
......
...@@ -36,7 +36,7 @@ ...@@ -36,7 +36,7 @@
#include "paddle/cinn/utils/sized_multi_set.h" #include "paddle/cinn/utils/sized_multi_set.h"
#include "paddle/cinn/utils/string.h" #include "paddle/cinn/utils/string.h"
DECLARE_bool(auto_schedule_use_cost_model); PD_DECLARE_bool(auto_schedule_use_cost_model);
namespace cinn { namespace cinn {
namespace auto_schedule { namespace auto_schedule {
......
...@@ -40,7 +40,7 @@ ...@@ -40,7 +40,7 @@
#include "paddle/cinn/backends/cuda_util.h" #include "paddle/cinn/backends/cuda_util.h"
#endif #endif
DECLARE_bool(auto_schedule_use_cost_model); PD_DECLARE_bool(auto_schedule_use_cost_model);
namespace cinn { namespace cinn {
namespace auto_schedule { namespace auto_schedule {
......
...@@ -14,14 +14,13 @@ ...@@ -14,14 +14,13 @@
#pragma once #pragma once
#include <gflags/gflags.h>
#include <mutex> #include <mutex>
#include <string> #include <string>
#include "paddle/cinn/ir/schedule/ir_schedule.h" #include "paddle/cinn/ir/schedule/ir_schedule.h"
#include "paddle/cinn/ir/utils/ir_copy.h" #include "paddle/cinn/ir/utils/ir_copy.h"
#include "paddle/cinn/utils/registry.h" #include "paddle/cinn/utils/registry.h"
#include "paddle/utils/flags.h"
namespace cinn { namespace cinn {
......
...@@ -28,7 +28,7 @@ ...@@ -28,7 +28,7 @@
#include "paddle/cinn/utils/string.h" #include "paddle/cinn/utils/string.h"
#include "paddle/cinn/utils/type_defs.h" #include "paddle/cinn/utils/type_defs.h"
DECLARE_bool(auto_schedule_use_cost_model); PD_DECLARE_bool(auto_schedule_use_cost_model);
namespace cinn { namespace cinn {
namespace auto_schedule { namespace auto_schedule {
......
...@@ -44,9 +44,9 @@ ...@@ -44,9 +44,9 @@
* parameters for more detail. * parameters for more detail.
*/ */
DEFINE_string(resnet50_model_dir, PD_DEFINE_string(resnet50_model_dir,
"./ResNet50", "./ResNet50",
"the path to paddle model resnet50."); "the path to paddle model resnet50.");
// Flags that control which schedule tests will be run. // Flags that control which schedule tests will be run.
// Bit with index 0 controls no schedule test, means options = 1 = "001" will // Bit with index 0 controls no schedule test, means options = 1 = "001" will
// run no schedule test. Bit with index 1 controls manual schedule test, means // run no schedule test. Bit with index 1 controls manual schedule test, means
...@@ -54,10 +54,10 @@ DEFINE_string(resnet50_model_dir, ...@@ -54,10 +54,10 @@ DEFINE_string(resnet50_model_dir,
// auto schedule test, means options = 4 = "100" will run auto schedule test. // auto schedule test, means options = 4 = "100" will run auto schedule test.
// The default value is -1, which means that this flag is disabled to set the // The default value is -1, which means that this flag is disabled to set the
// options // options
DEFINE_int32(evaluate_knobs, PD_DEFINE_int32(evaluate_knobs,
-1, -1,
"the options to control which schedule tests will be run."); "the options to control which schedule tests will be run.");
DECLARE_double(cinn_infer_model_version); PD_DECLARE_double(cinn_infer_model_version);
namespace cinn { namespace cinn {
namespace auto_schedule { namespace auto_schedule {
......
...@@ -29,7 +29,7 @@ ...@@ -29,7 +29,7 @@
#include "paddle/cinn/utils/string.h" #include "paddle/cinn/utils/string.h"
//! Root of the builtin code. //! Root of the builtin code.
DECLARE_string(cinn_x86_builtin_code_root); PD_DECLARE_string(cinn_x86_builtin_code_root);
namespace cinn { namespace cinn {
namespace backends { namespace backends {
......
...@@ -14,8 +14,6 @@ ...@@ -14,8 +14,6 @@
#pragma once #pragma once
#include <gflags/gflags.h>
#include <string> #include <string>
#include <vector> #include <vector>
...@@ -27,6 +25,7 @@ ...@@ -27,6 +25,7 @@
#include "paddle/cinn/ir/utils/ir_printer.h" #include "paddle/cinn/ir/utils/ir_printer.h"
#include "paddle/cinn/lang/packed_func.h" #include "paddle/cinn/lang/packed_func.h"
#include "paddle/cinn/runtime/cinn_runtime.h" #include "paddle/cinn/runtime/cinn_runtime.h"
#include "paddle/utils/flags.h"
namespace cinn { namespace cinn {
......
...@@ -30,11 +30,11 @@ ...@@ -30,11 +30,11 @@
#include "paddle/cinn/runtime/flags.h" #include "paddle/cinn/runtime/flags.h"
#endif #endif
DECLARE_string(cinn_source_code_save_path); PD_DECLARE_string(cinn_source_code_save_path);
DECLARE_string(cinn_dump_group_lowered_func); PD_DECLARE_string(cinn_dump_group_lowered_func);
DECLARE_string(cinn_dump_group_source_code); PD_DECLARE_string(cinn_dump_group_source_code);
DECLARE_string(cinn_dump_group_ptx); PD_DECLARE_string(cinn_dump_group_ptx);
DECLARE_string(cinn_dump_group_instruction); PD_DECLARE_string(cinn_dump_group_instruction);
namespace cinn { namespace cinn {
namespace backends { namespace backends {
......
...@@ -27,7 +27,7 @@ ...@@ -27,7 +27,7 @@
#include "paddle/cinn/runtime/flags.h" #include "paddle/cinn/runtime/flags.h"
#include "paddle/cinn/utils/string.h" #include "paddle/cinn/utils/string.h"
DECLARE_bool(verbose_function_register); PD_DECLARE_bool(verbose_function_register);
namespace cinn { namespace cinn {
namespace backends { namespace backends {
......
...@@ -21,7 +21,7 @@ ...@@ -21,7 +21,7 @@
#include "paddle/cinn/ir/tensor.h" #include "paddle/cinn/ir/tensor.h"
#include "paddle/cinn/runtime/flags.h" #include "paddle/cinn/runtime/flags.h"
DECLARE_bool(verbose_function_register); PD_DECLARE_bool(verbose_function_register);
namespace cinn { namespace cinn {
namespace backends { namespace backends {
......
...@@ -19,10 +19,10 @@ ...@@ -19,10 +19,10 @@
#include <iostream> #include <iostream>
#include "gflags/gflags_declare.h"
#include "paddle/cinn/runtime/flags.h" #include "paddle/cinn/runtime/flags.h"
#include "paddle/utils/flags.h"
DECLARE_bool(verbose_function_register); PD_DECLARE_bool(verbose_function_register);
namespace cinn { namespace cinn {
namespace backends { namespace backends {
......
...@@ -30,8 +30,8 @@ ...@@ -30,8 +30,8 @@
#include "paddle/cinn/runtime/flags.h" #include "paddle/cinn/runtime/flags.h"
#include "paddle/cinn/utils/string.h" #include "paddle/cinn/utils/string.h"
DECLARE_string(cinn_nvcc_cmd_path); PD_DECLARE_string(cinn_nvcc_cmd_path);
DECLARE_bool(nvrtc_compile_to_cubin); PD_DECLARE_bool(nvrtc_compile_to_cubin);
namespace cinn { namespace cinn {
namespace backends { namespace backends {
......
...@@ -78,7 +78,7 @@ std::string NameGenerator::New(const std::string& name_hint) { ...@@ -78,7 +78,7 @@ std::string NameGenerator::New(const std::string& name_hint) {
} // namespace common } // namespace common
DEFINE_bool(cinn_runtime_display_debug_info, PD_DEFINE_bool(cinn_runtime_display_debug_info,
false, false,
"Whether to display debug information in runtime"); "Whether to display debug information in runtime");
} // namespace cinn } // namespace cinn
...@@ -14,7 +14,6 @@ ...@@ -14,7 +14,6 @@
#pragma once #pragma once
#include <absl/types/any.h> #include <absl/types/any.h>
#include <gflags/gflags.h>
#include <isl/cpp.h> #include <isl/cpp.h>
#include <mutex> #include <mutex>
...@@ -25,10 +24,11 @@ ...@@ -25,10 +24,11 @@
#include "paddle/cinn/common/debug_manager.h" #include "paddle/cinn/common/debug_manager.h"
#include "paddle/cinn/common/info_registry.h" #include "paddle/cinn/common/info_registry.h"
#include "paddle/cinn/common/target.h" #include "paddle/cinn/common/target.h"
#include "paddle/utils/flags.h"
namespace cinn { namespace cinn {
DECLARE_bool(cinn_runtime_display_debug_info); PD_DECLARE_bool(cinn_runtime_display_debug_info);
namespace ir { namespace ir {
class Expr; class Expr;
......
...@@ -23,7 +23,7 @@ ...@@ -23,7 +23,7 @@
#include "paddle/cinn/frontend/pass/use_program_pass.h" #include "paddle/cinn/frontend/pass/use_program_pass.h"
#include "paddle/cinn/frontend/program_pass.h" #include "paddle/cinn/frontend/program_pass.h"
DEFINE_string(model_dir, "", ""); PD_DEFINE_string(model_dir, "", "");
namespace cinn { namespace cinn {
namespace frontend { namespace frontend {
......
...@@ -25,7 +25,7 @@ ...@@ -25,7 +25,7 @@
#include "paddle/cinn/hlir/pass/use_pass.h" #include "paddle/cinn/hlir/pass/use_pass.h"
#include "paddle/cinn/runtime/flags.h" #include "paddle/cinn/runtime/flags.h"
DECLARE_bool(enable_auto_tuner); PD_DECLARE_bool(enable_auto_tuner);
namespace cinn::frontend { namespace cinn::frontend {
......
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
#include "paddle/cinn/runtime/use_extern_funcs.h" #include "paddle/cinn/runtime/use_extern_funcs.h"
DEFINE_string(model_dir, "", ""); PD_DEFINE_string(model_dir, "", "");
namespace cinn::frontend { namespace cinn::frontend {
......
...@@ -29,15 +29,15 @@ ...@@ -29,15 +29,15 @@
#include "paddle/cinn/hlir/pass/use_pass.h" #include "paddle/cinn/hlir/pass/use_pass.h"
#include "paddle/cinn/runtime/flags.h" #include "paddle/cinn/runtime/flags.h"
DECLARE_bool(cinn_use_fill_constant_folding); PD_DECLARE_bool(cinn_use_fill_constant_folding);
DECLARE_bool(cinn_use_op_fusion); PD_DECLARE_bool(cinn_use_op_fusion);
DECLARE_bool(cinn_use_common_subexpression_elimination); PD_DECLARE_bool(cinn_use_common_subexpression_elimination);
DECLARE_string(cinn_check_fusion_accuracy_pass); PD_DECLARE_string(cinn_check_fusion_accuracy_pass);
DECLARE_bool(cinn_use_custom_call); PD_DECLARE_bool(cinn_use_custom_call);
DECLARE_bool(use_reduce_split_pass); PD_DECLARE_bool(use_reduce_split_pass);
DECLARE_bool(cinn_use_dense_merge_pass); PD_DECLARE_bool(cinn_use_dense_merge_pass);
DECLARE_string(cinn_custom_call_deny_ops); PD_DECLARE_string(cinn_custom_call_deny_ops);
DECLARE_bool(general_fusion_merge_pass); PD_DECLARE_bool(general_fusion_merge_pass);
namespace cinn { namespace cinn {
namespace frontend { namespace frontend {
......
...@@ -14,10 +14,10 @@ ...@@ -14,10 +14,10 @@
#include "paddle/cinn/frontend/paddle/model_parser.h" #include "paddle/cinn/frontend/paddle/model_parser.h"
#include <gflags/gflags.h>
#include <gtest/gtest.h> #include <gtest/gtest.h>
#include "paddle/utils/flags.h"
DEFINE_string(model_dir, "<NOTEXIST>", "model directory path"); PD_DEFINE_string(model_dir, "<NOTEXIST>", "model directory path");
namespace cinn::frontend::paddle { namespace cinn::frontend::paddle {
......
...@@ -27,7 +27,7 @@ ...@@ -27,7 +27,7 @@
#include "paddle/cinn/frontend/var_type_utils.h" #include "paddle/cinn/frontend/var_type_utils.h"
#include "paddle/cinn/hlir/op/use_ops.h" #include "paddle/cinn/hlir/op/use_ops.h"
DECLARE_double(cinn_infer_model_version); PD_DECLARE_double(cinn_infer_model_version);
namespace cinn { namespace cinn {
namespace frontend { namespace frontend {
......
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
#include "paddle/cinn/frontend/decomposer/test_helper.h" #include "paddle/cinn/frontend/decomposer/test_helper.h"
#include "paddle/cinn/runtime/use_extern_funcs.h" #include "paddle/cinn/runtime/use_extern_funcs.h"
DEFINE_string(model_dir, "", ""); PD_DEFINE_string(model_dir, "", "");
namespace cinn { namespace cinn {
namespace frontend { namespace frontend {
......
...@@ -21,7 +21,7 @@ ...@@ -21,7 +21,7 @@
#include "paddle/cinn/frontend/paddle/pb/program_desc.h" #include "paddle/cinn/frontend/paddle/pb/program_desc.h"
#include "paddle/cinn/hlir/framework/node.h" #include "paddle/cinn/hlir/framework/node.h"
DECLARE_double(cinn_infer_model_version); PD_DECLARE_double(cinn_infer_model_version);
namespace cinn { namespace cinn {
namespace frontend { namespace frontend {
......
...@@ -14,7 +14,6 @@ ...@@ -14,7 +14,6 @@
#pragma once #pragma once
#include <gflags/gflags.h>
#include <gtest/gtest.h> #include <gtest/gtest.h>
#include <algorithm> #include <algorithm>
...@@ -42,8 +41,9 @@ ...@@ -42,8 +41,9 @@
#include "paddle/cinn/hlir/op/use_ops.h" #include "paddle/cinn/hlir/op/use_ops.h"
#include "paddle/cinn/hlir/pass/use_pass.h" #include "paddle/cinn/hlir/pass/use_pass.h"
#include "paddle/cinn/utils/data_util.h" #include "paddle/cinn/utils/data_util.h"
#include "paddle/utils/flags.h"
DECLARE_bool(cinn_use_op_fusion); PD_DECLARE_bool(cinn_use_op_fusion);
namespace cinn { namespace cinn {
namespace frontend { namespace frontend {
......
...@@ -30,7 +30,7 @@ ...@@ -30,7 +30,7 @@
#include "paddle/cinn/hlir/pass/use_pass.h" #include "paddle/cinn/hlir/pass/use_pass.h"
#include "paddle/cinn/utils/data_util.h" #include "paddle/cinn/utils/data_util.h"
DEFINE_string(model_dir, "", ""); PD_DEFINE_string(model_dir, "", "");
namespace cinn { namespace cinn {
namespace frontend { namespace frontend {
......
...@@ -12,12 +12,12 @@ ...@@ -12,12 +12,12 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
#include <gflags/gflags.h>
#include <gtest/gtest.h> #include <gtest/gtest.h>
#include "paddle/utils/flags.h"
int main(int argc, char **argv) { int main(int argc, char **argv) {
testing::InitGoogleTest(&argc, argv); testing::InitGoogleTest(&argc, argv);
GFLAGS_NAMESPACE::ParseCommandLineFlags(&argc, &argv, false); paddle::flags::ParseCommandLineFlags(&argc, &argv);
return RUN_ALL_TESTS(); return RUN_ALL_TESTS();
} }
...@@ -21,7 +21,7 @@ ...@@ -21,7 +21,7 @@
#include <cuda_runtime.h> #include <cuda_runtime.h>
#endif #endif
DECLARE_int64(cinn_self_check_accuracy_num); PD_DECLARE_int64(cinn_self_check_accuracy_num);
namespace cinn { namespace cinn {
namespace hlir { namespace hlir {
......
...@@ -25,7 +25,7 @@ ...@@ -25,7 +25,7 @@
#include "paddle/cinn/hlir/framework/instruction.h" #include "paddle/cinn/hlir/framework/instruction.h"
#include "paddle/cinn/hlir/framework/op_strategy.h" #include "paddle/cinn/hlir/framework/op_strategy.h"
DECLARE_string(cinn_self_check_accuracy); PD_DECLARE_string(cinn_self_check_accuracy);
namespace cinn { namespace cinn {
namespace hlir { namespace hlir {
......
...@@ -21,7 +21,7 @@ ...@@ -21,7 +21,7 @@
#include "paddle/cinn/runtime/flags.h" #include "paddle/cinn/runtime/flags.h"
#include "paddle/cinn/utils/string.h" #include "paddle/cinn/utils/string.h"
DECLARE_string(cinn_fusion_groups_graphviz_dir); PD_DECLARE_string(cinn_fusion_groups_graphviz_dir);
namespace cinn { namespace cinn {
namespace hlir { namespace hlir {
......
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
#include "paddle/cinn/hlir/framework/pass.h" #include "paddle/cinn/hlir/framework/pass.h"
#include "paddle/cinn/hlir/pass/use_pass.h" #include "paddle/cinn/hlir/pass/use_pass.h"
DECLARE_string(cinn_fusion_groups_graphviz_dir); PD_DECLARE_string(cinn_fusion_groups_graphviz_dir);
namespace cinn { namespace cinn {
namespace hlir { namespace hlir {
......
...@@ -22,8 +22,8 @@ ...@@ -22,8 +22,8 @@
#include "paddle/cinn/runtime/flags.h" #include "paddle/cinn/runtime/flags.h"
#include "paddle/cinn/utils/profiler.h" #include "paddle/cinn/utils/profiler.h"
DECLARE_bool(cinn_sync_run); PD_DECLARE_bool(cinn_sync_run);
DECLARE_string(cinn_self_check_accuracy); PD_DECLARE_string(cinn_self_check_accuracy);
namespace cinn { namespace cinn {
namespace hlir { namespace hlir {
......
...@@ -26,7 +26,7 @@ ...@@ -26,7 +26,7 @@
#include "paddle/fluid/ir/dialect/paddle_dialect/ir/pd_type.h" #include "paddle/fluid/ir/dialect/paddle_dialect/ir/pd_type.h"
#include "paddle/phi/core/ddim.h" #include "paddle/phi/core/ddim.h"
DECLARE_bool(cinn_use_cuda_vectorize); PD_DECLARE_bool(cinn_use_cuda_vectorize);
namespace cinn { namespace cinn {
namespace hlir { namespace hlir {
......
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
#include "paddle/cinn/ir/schedule/ir_schedule.h" #include "paddle/cinn/ir/schedule/ir_schedule.h"
#include "paddle/cinn/optim/transform_gpu_forloop.h" #include "paddle/cinn/optim/transform_gpu_forloop.h"
DECLARE_bool(cinn_use_cuda_vectorize); PD_DECLARE_bool(cinn_use_cuda_vectorize);
namespace cinn { namespace cinn {
namespace hlir { namespace hlir {
......
...@@ -32,7 +32,7 @@ ...@@ -32,7 +32,7 @@
#include "paddle/cinn/ir/module.h" #include "paddle/cinn/ir/module.h"
#include "paddle/cinn/runtime/flags.h" #include "paddle/cinn/runtime/flags.h"
DECLARE_int32(cinn_parallel_compile_thread); PD_DECLARE_int32(cinn_parallel_compile_thread);
namespace cinn { namespace cinn {
namespace hlir { namespace hlir {
......
...@@ -30,8 +30,8 @@ ...@@ -30,8 +30,8 @@
#include "paddle/cinn/utils/dot_lang.h" #include "paddle/cinn/utils/dot_lang.h"
#include "paddle/cinn/utils/string.h" #include "paddle/cinn/utils/string.h"
DECLARE_string(cinn_pass_visualize_dir); PD_DECLARE_string(cinn_pass_visualize_dir);
DECLARE_string(cinn_check_fusion_accuracy_pass); PD_DECLARE_string(cinn_check_fusion_accuracy_pass);
namespace cinn { namespace cinn {
namespace hlir { namespace hlir {
namespace framework { namespace framework {
......
...@@ -12,8 +12,6 @@ ...@@ -12,8 +12,6 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
#include <gflags/gflags.h>
#include <memory> #include <memory>
#include <string> #include <string>
#include <utility> #include <utility>
......
...@@ -12,8 +12,6 @@ ...@@ -12,8 +12,6 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
#include <gflags/gflags.h>
#include <memory> #include <memory>
#include <string> #include <string>
#include <utility> #include <utility>
......
...@@ -14,8 +14,6 @@ ...@@ -14,8 +14,6 @@
#include "paddle/cinn/hlir/op/contrib/gather_nd.h" #include "paddle/cinn/hlir/op/contrib/gather_nd.h"
#include <gflags/gflags.h>
#include <memory> #include <memory>
#include <string> #include <string>
#include <utility> #include <utility>
......
...@@ -12,8 +12,6 @@ ...@@ -12,8 +12,6 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
#include <gflags/gflags.h>
#include <memory> #include <memory>
#include <string> #include <string>
#include <utility> #include <utility>
......
...@@ -17,7 +17,6 @@ ...@@ -17,7 +17,6 @@
#include <utility> #include <utility>
#include <vector> #include <vector>
#include "gflags/gflags.h"
#include "paddle/cinn/common/cas.h" #include "paddle/cinn/common/cas.h"
#include "paddle/cinn/common/common.h" #include "paddle/cinn/common/common.h"
#include "paddle/cinn/common/context.h" #include "paddle/cinn/common/context.h"
...@@ -37,6 +36,7 @@ ...@@ -37,6 +36,7 @@
#include "paddle/cinn/ir/tensor.h" #include "paddle/cinn/ir/tensor.h"
#include "paddle/cinn/lang/builtin.h" #include "paddle/cinn/lang/builtin.h"
#include "paddle/cinn/lang/compute.h" #include "paddle/cinn/lang/compute.h"
#include "paddle/utils/flags.h"
namespace cinn { namespace cinn {
namespace hlir { namespace hlir {
......
...@@ -19,7 +19,6 @@ ...@@ -19,7 +19,6 @@
#include <utility> #include <utility>
#include <vector> #include <vector>
#include "gflags/gflags.h"
#include "paddle/cinn/common/cas.h" #include "paddle/cinn/common/cas.h"
#include "paddle/cinn/common/common.h" #include "paddle/cinn/common/common.h"
#include "paddle/cinn/common/context.h" #include "paddle/cinn/common/context.h"
...@@ -38,6 +37,7 @@ ...@@ -38,6 +37,7 @@
#include "paddle/cinn/ir/tensor.h" #include "paddle/cinn/ir/tensor.h"
#include "paddle/cinn/lang/builtin.h" #include "paddle/cinn/lang/builtin.h"
#include "paddle/cinn/lang/compute.h" #include "paddle/cinn/lang/compute.h"
#include "paddle/utils/flags.h"
namespace cinn { namespace cinn {
namespace hlir { namespace hlir {
......
...@@ -14,8 +14,6 @@ ...@@ -14,8 +14,6 @@
#include "paddle/cinn/hlir/op/contrib/one_hot.h" #include "paddle/cinn/hlir/op/contrib/one_hot.h"
#include <gflags/gflags.h>
#include <memory> #include <memory>
#include <string> #include <string>
#include <utility> #include <utility>
......
...@@ -12,8 +12,6 @@ ...@@ -12,8 +12,6 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
#include <gflags/gflags.h>
#include <memory> #include <memory>
#include <string> #include <string>
#include <utility> #include <utility>
......
...@@ -17,7 +17,6 @@ ...@@ -17,7 +17,6 @@
#include <utility> #include <utility>
#include <vector> #include <vector>
#include "gflags/gflags.h"
#include "paddle/cinn/common/cas.h" #include "paddle/cinn/common/cas.h"
#include "paddle/cinn/common/common.h" #include "paddle/cinn/common/common.h"
#include "paddle/cinn/common/context.h" #include "paddle/cinn/common/context.h"
...@@ -37,6 +36,7 @@ ...@@ -37,6 +36,7 @@
#include "paddle/cinn/ir/tensor.h" #include "paddle/cinn/ir/tensor.h"
#include "paddle/cinn/lang/builtin.h" #include "paddle/cinn/lang/builtin.h"
#include "paddle/cinn/lang/compute.h" #include "paddle/cinn/lang/compute.h"
#include "paddle/utils/flags.h"
namespace cinn { namespace cinn {
namespace hlir { namespace hlir {
......
...@@ -14,8 +14,6 @@ ...@@ -14,8 +14,6 @@
#include "paddle/cinn/hlir/op/contrib/repeat.h" #include "paddle/cinn/hlir/op/contrib/repeat.h"
#include <gflags/gflags.h>
#include <memory> #include <memory>
#include <string> #include <string>
#include <utility> #include <utility>
......
...@@ -14,8 +14,6 @@ ...@@ -14,8 +14,6 @@
#include "paddle/cinn/hlir/op/contrib/resize.h" #include "paddle/cinn/hlir/op/contrib/resize.h"
#include <gflags/gflags.h>
#include <memory> #include <memory>
#include <string> #include <string>
#include <utility> #include <utility>
......
...@@ -14,8 +14,6 @@ ...@@ -14,8 +14,6 @@
#include "paddle/cinn/hlir/op/contrib/sort.h" #include "paddle/cinn/hlir/op/contrib/sort.h"
#include <gflags/gflags.h>
#include <memory> #include <memory>
#include <string> #include <string>
#include <utility> #include <utility>
......
...@@ -12,8 +12,6 @@ ...@@ -12,8 +12,6 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
#include <gflags/gflags.h>
#include <memory> #include <memory>
#include <string> #include <string>
#include <utility> #include <utility>
......
...@@ -25,7 +25,7 @@ ...@@ -25,7 +25,7 @@
#include "paddle/cinn/hlir/pass/use_pass.h" #include "paddle/cinn/hlir/pass/use_pass.h"
#include "paddle/cinn/utils/data_util.h" #include "paddle/cinn/utils/data_util.h"
DEFINE_string(model_dir, "", ""); PD_DEFINE_string(model_dir, "", "");
namespace cinn { namespace cinn {
namespace frontend { namespace frontend {
......
...@@ -37,7 +37,7 @@ ...@@ -37,7 +37,7 @@
#include "paddle/cinn/hlir/framework/pass.h" #include "paddle/cinn/hlir/framework/pass.h"
#include "paddle/cinn/utils/data_util.h" #include "paddle/cinn/utils/data_util.h"
DEFINE_string(model_dir, "", ""); PD_DEFINE_string(model_dir, "", "");
namespace cinn { namespace cinn {
namespace frontend { namespace frontend {
......
...@@ -25,7 +25,7 @@ ...@@ -25,7 +25,7 @@
#include "paddle/cinn/hlir/pass/use_pass.h" #include "paddle/cinn/hlir/pass/use_pass.h"
#include "paddle/cinn/utils/data_util.h" #include "paddle/cinn/utils/data_util.h"
DEFINE_string(model_dir, "", ""); PD_DEFINE_string(model_dir, "", "");
namespace cinn { namespace cinn {
namespace frontend { namespace frontend {
......
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
#include "paddle/cinn/hlir/op/external_api_registry.h" #include "paddle/cinn/hlir/op/external_api_registry.h"
#include "paddle/cinn/utils/string.h" #include "paddle/cinn/utils/string.h"
DECLARE_string(cinn_custom_call_deny_ops); PD_DECLARE_string(cinn_custom_call_deny_ops);
namespace cinn { namespace cinn {
namespace hlir { namespace hlir {
......
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
#include "paddle/cinn/hlir/pass/fusion_merge_pass_util.h" #include "paddle/cinn/hlir/pass/fusion_merge_pass_util.h"
DECLARE_bool(enhance_vertical_fusion_with_recompute); PD_DECLARE_bool(enhance_vertical_fusion_with_recompute);
namespace cinn { namespace cinn {
namespace hlir { namespace hlir {
......
...@@ -26,7 +26,7 @@ ...@@ -26,7 +26,7 @@
#include "paddle/cinn/hlir/pass/general_fusion_merge_pass/lightware_fuse_pass_ctx.h" #include "paddle/cinn/hlir/pass/general_fusion_merge_pass/lightware_fuse_pass_ctx.h"
#include "paddle/cinn/hlir/pass/general_fusion_merge_pass_utils.h" #include "paddle/cinn/hlir/pass/general_fusion_merge_pass_utils.h"
DECLARE_bool(enhance_vertical_fusion_with_recompute); PD_DECLARE_bool(enhance_vertical_fusion_with_recompute);
namespace cinn { namespace cinn {
namespace hlir { namespace hlir {
......
...@@ -25,7 +25,7 @@ ...@@ -25,7 +25,7 @@
#include "paddle/cinn/hlir/pass/use_pass.h" #include "paddle/cinn/hlir/pass/use_pass.h"
#include "paddle/cinn/utils/data_util.h" #include "paddle/cinn/utils/data_util.h"
DEFINE_string(model_dir, "", ""); PD_DEFINE_string(model_dir, "", "");
namespace cinn { namespace cinn {
namespace frontend { namespace frontend {
......
...@@ -26,7 +26,7 @@ ...@@ -26,7 +26,7 @@
#include "paddle/cinn/hlir/pass/use_pass.h" #include "paddle/cinn/hlir/pass/use_pass.h"
#include "paddle/cinn/utils/data_util.h" #include "paddle/cinn/utils/data_util.h"
DEFINE_string(model_dir, "", ""); PD_DEFINE_string(model_dir, "", "");
namespace cinn { namespace cinn {
namespace frontend { namespace frontend {
......
...@@ -31,7 +31,7 @@ ...@@ -31,7 +31,7 @@
#include "paddle/cinn/poly/isl_utils.h" #include "paddle/cinn/poly/isl_utils.h"
#include "paddle/cinn/utils/string.h" #include "paddle/cinn/utils/string.h"
DECLARE_bool(cinn_use_cuda_vectorize); PD_DECLARE_bool(cinn_use_cuda_vectorize);
namespace cinn { namespace cinn {
namespace hlir { namespace hlir {
namespace pe { namespace pe {
......
...@@ -41,7 +41,7 @@ ...@@ -41,7 +41,7 @@
#include "paddle/cinn/optim/replace_var_with_expr.h" #include "paddle/cinn/optim/replace_var_with_expr.h"
#include "paddle/cinn/utils/string.h" #include "paddle/cinn/utils/string.h"
DECLARE_int32(cinn_error_message_level); PD_DECLARE_int32(cinn_error_message_level);
namespace cinn { namespace cinn {
namespace ir { namespace ir {
......
...@@ -22,7 +22,7 @@ ...@@ -22,7 +22,7 @@
#include "paddle/cinn/runtime/flags.h" #include "paddle/cinn/runtime/flags.h"
#include "paddle/cinn/utils/string.h" #include "paddle/cinn/utils/string.h"
DECLARE_string(cinn_check_fusion_accuracy_pass); PD_DECLARE_string(cinn_check_fusion_accuracy_pass);
namespace cinn { namespace cinn {
namespace runtime { namespace runtime {
......
...@@ -14,7 +14,6 @@ ...@@ -14,7 +14,6 @@
#include "paddle/cinn/runtime/flags.h" #include "paddle/cinn/runtime/flags.h"
#include <gflags/gflags.h>
#include <glog/logging.h> #include <glog/logging.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <sys/types.h> #include <sys/types.h>
...@@ -23,169 +22,182 @@ ...@@ -23,169 +22,182 @@
#include <unordered_set> #include <unordered_set>
#include "paddle/cinn/common/target.h" #include "paddle/cinn/common/target.h"
#include "paddle/utils/flags.h"
#ifdef CINN_WITH_CUDNN #ifdef CINN_WITH_CUDNN
DEFINE_bool(cinn_cudnn_deterministic, PD_DEFINE_bool(
false, cinn_cudnn_deterministic,
"Whether allow using an autotuning algorithm for convolution " false,
"operator. The autotuning algorithm may be non-deterministic. If " "Whether allow using an autotuning algorithm for convolution "
"true, the algorithm is deterministic."); "operator. The autotuning algorithm may be non-deterministic. If "
"true, the algorithm is deterministic.");
#endif #endif
using ::GFLAGS_NAMESPACE::BoolFromEnv; using ::paddle::flags::BoolFromEnv;
using ::GFLAGS_NAMESPACE::DoubleFromEnv; using ::paddle::flags::DoubleFromEnv;
using ::GFLAGS_NAMESPACE::Int32FromEnv; using ::paddle::flags::Int32FromEnv;
using ::GFLAGS_NAMESPACE::Int64FromEnv; using ::paddle::flags::Int64FromEnv;
using ::GFLAGS_NAMESPACE::StringFromEnv; using ::paddle::flags::StringFromEnv;
DEFINE_string(cinn_x86_builtin_code_root, PD_DEFINE_string(cinn_x86_builtin_code_root,
StringFromEnv("FLAGS_cinn_x86_builtin_code_root", ""), StringFromEnv("FLAGS_cinn_x86_builtin_code_root", ""),
""); "");
DEFINE_string(cinn_nvcc_cmd_path,
StringFromEnv("FLAGS_cinn_nvcc_cmd_path", "/usr/local/cuda/bin"), PD_DEFINE_string(cinn_nvcc_cmd_path,
"Setting nvcc default path!"); StringFromEnv("FLAGS_cinn_nvcc_cmd_path",
"/usr/local/cuda/bin"),
DEFINE_int32(cinn_parallel_compile_thread, "Setting nvcc default path!");
Int32FromEnv("FLAGS_cinn_parallel_compile_thread",
(std::thread::hardware_concurrency() >> 1)), PD_DEFINE_int32(cinn_parallel_compile_thread,
"How much thread the parallel compile used."); Int32FromEnv("FLAGS_cinn_parallel_compile_thread",
(std::thread::hardware_concurrency() >> 1)),
DEFINE_bool(cinn_use_op_fusion, "How much thread the parallel compile used.");
BoolFromEnv("FLAGS_cinn_use_op_fusion", true),
"Whether to use op fusion pass."); PD_DEFINE_bool(cinn_use_op_fusion,
BoolFromEnv("FLAGS_cinn_use_op_fusion", true),
DEFINE_bool(general_fusion_merge_pass, "Whether to use op fusion pass.");
BoolFromEnv("FLAGS_general_fusion_merge_pass", true),
"Whether to use general fusion_merge pass."); PD_DEFINE_bool(general_fusion_merge_pass,
BoolFromEnv("FLAGS_general_fusion_merge_pass", true),
DEFINE_bool(cinn_use_common_subexpression_elimination, "Whether to use general fusion_merge pass.");
BoolFromEnv("FLAGS_cinn_use_common_subexpression_elimination",
false), PD_DEFINE_bool(cinn_use_common_subexpression_elimination,
"Whether to use common subexpression elimination pass."); BoolFromEnv("FLAGS_cinn_use_common_subexpression_elimination",
false),
DEFINE_string( "Whether to use common subexpression elimination pass.");
PD_DEFINE_string(
cinn_custom_call_deny_ops, cinn_custom_call_deny_ops,
StringFromEnv("FLAGS_cinn_custom_call_deny_ops", ""), StringFromEnv("FLAGS_cinn_custom_call_deny_ops", ""),
"a blacklist of op are denied by MarkCustomCallOps pass, separated by ;"); "a blacklist of op are denied by MarkCustomCallOps pass, separated by ;");
DEFINE_bool(cinn_use_custom_call, PD_DEFINE_bool(
BoolFromEnv("FLAGS_cinn_use_custom_call", true), cinn_use_custom_call,
"Whether to use custom_call for ops with external_api registered"); BoolFromEnv("FLAGS_cinn_use_custom_call", true),
"Whether to use custom_call for ops with external_api registered");
DEFINE_bool(cinn_use_fill_constant_folding, PD_DEFINE_bool(cinn_use_fill_constant_folding,
BoolFromEnv("FLAGS_cinn_use_fill_constant_folding", false), BoolFromEnv("FLAGS_cinn_use_fill_constant_folding", false),
"Whether use the FillConstantFolding pass."); "Whether use the FillConstantFolding pass.");
DEFINE_string(cinn_check_fusion_accuracy_pass, PD_DEFINE_string(cinn_check_fusion_accuracy_pass,
StringFromEnv("FLAGS_cinn_check_fusion_accuracy_pass", ""), StringFromEnv("FLAGS_cinn_check_fusion_accuracy_pass", ""),
"Check the correct of fusion kernels, if the results not " "Check the correct of fusion kernels, if the results not "
"satisfied 'allclose(rtol=1e-05f, atol=1e-08f)', " "satisfied 'allclose(rtol=1e-05f, atol=1e-08f)', "
"report error and exited."); "report error and exited.");
DEFINE_bool(cinn_use_cuda_vectorize, PD_DEFINE_bool(cinn_use_cuda_vectorize,
BoolFromEnv("FLAGS_cinn_use_cuda_vectorize", false), BoolFromEnv("FLAGS_cinn_use_cuda_vectorize", false),
"Whether use cuda vectroize on schedule config"); "Whether use cuda vectroize on schedule config");
DEFINE_bool(use_reduce_split_pass, PD_DEFINE_bool(use_reduce_split_pass,
BoolFromEnv("FLAGS_use_reduce_split_pass", false), BoolFromEnv("FLAGS_use_reduce_split_pass", false),
"Whether use reduce split pass."); "Whether use reduce split pass.");
DEFINE_bool(cinn_use_dense_merge_pass, PD_DEFINE_bool(cinn_use_dense_merge_pass,
BoolFromEnv("FLAGS_cinn_use_dense_merge_pass", false), BoolFromEnv("FLAGS_cinn_use_dense_merge_pass", false),
"Whether use dense merge pass."); "Whether use dense merge pass.");
DEFINE_bool(nvrtc_compile_to_cubin, PD_DEFINE_bool(
BoolFromEnv("FLAGS_nvrtc_compile_to_cubin", false), nvrtc_compile_to_cubin,
"Whether nvrtc compile cuda source into cubin instead of ptx (only " BoolFromEnv("FLAGS_nvrtc_compile_to_cubin", false),
"works after cuda-11.1)."); "Whether nvrtc compile cuda source into cubin instead of ptx (only "
"works after cuda-11.1).");
DEFINE_bool(cinn_compile_with_nvrtc, PD_DEFINE_bool(cinn_compile_with_nvrtc,
BoolFromEnv("FLAGS_cinn_compile_with_nvrtc", true), BoolFromEnv("FLAGS_cinn_compile_with_nvrtc", true),
"Whether nvrtc compile cuda source with nvrtc(default nvcc)."); "Whether nvrtc compile cuda source with nvrtc(default nvcc).");
// FLAGS for performance analysis and accuracy debug // FLAGS for performance analysis and accuracy debug
DEFINE_bool(cinn_sync_run, PD_DEFINE_bool(cinn_sync_run,
BoolFromEnv("FLAGS_cinn_sync_run", false), BoolFromEnv("FLAGS_cinn_sync_run", false),
"Whether sync all devices after each instruction run, which is " "Whether sync all devices after each instruction run, which is "
"used for debug."); "used for debug.");
DEFINE_string(cinn_self_check_accuracy, PD_DEFINE_string(
StringFromEnv("FLAGS_cinn_self_check_accuracy", ""), cinn_self_check_accuracy,
"Whether self-check accuracy after each instruction run, which " StringFromEnv("FLAGS_cinn_self_check_accuracy", ""),
"is used for debug."); "Whether self-check accuracy after each instruction run, which "
"is used for debug.");
DEFINE_int64(cinn_self_check_accuracy_num,
Int64FromEnv("FLAGS_cinn_self_check_accuracy_num", 0L), PD_DEFINE_int64(
"Set self-check accuracy print numel, which is used for debug."); cinn_self_check_accuracy_num,
Int64FromEnv("FLAGS_cinn_self_check_accuracy_num", 0L),
DEFINE_string(cinn_fusion_groups_graphviz_dir, "Set self-check accuracy print numel, which is used for debug.");
StringFromEnv("FLAGS_cinn_fusion_groups_graphviz_dir", ""),
"Specify the directory path of dot file of graph, which is used " PD_DEFINE_string(
"for debug."); cinn_fusion_groups_graphviz_dir,
StringFromEnv("FLAGS_cinn_fusion_groups_graphviz_dir", ""),
DEFINE_string(cinn_source_code_save_path, "Specify the directory path of dot file of graph, which is used "
StringFromEnv("FLAGS_cinn_source_code_save_path", ""), "for debug.");
"Specify the directory path of generated source code, which is "
"used for debug."); PD_DEFINE_string(
cinn_source_code_save_path,
DEFINE_string(cinn_dump_group_lowered_func, StringFromEnv("FLAGS_cinn_source_code_save_path", ""),
StringFromEnv("FLAGS_cinn_dump_group_lowered_func", ""), "Specify the directory path of generated source code, which is "
"Specify the path for dump lowered functions by group, which is " "used for debug.");
"used for debug.");
PD_DEFINE_string(
DEFINE_string( cinn_dump_group_lowered_func,
StringFromEnv("FLAGS_cinn_dump_group_lowered_func", ""),
"Specify the path for dump lowered functions by group, which is "
"used for debug.");
PD_DEFINE_string(
cinn_dump_group_source_code, cinn_dump_group_source_code,
StringFromEnv("FLAGS_cinn_dump_group_source_code", ""), StringFromEnv("FLAGS_cinn_dump_group_source_code", ""),
"Specify the path for dump source code by group, which is used for debug."); "Specify the path for dump source code by group, which is used for debug.");
DEFINE_string( PD_DEFINE_string(
cinn_dump_group_ptx, cinn_dump_group_ptx,
StringFromEnv("FLAGS_cinn_dump_group_ptx", ""), StringFromEnv("FLAGS_cinn_dump_group_ptx", ""),
"Specify the path for dump ptx by group, which is used for debug."); "Specify the path for dump ptx by group, which is used for debug.");
DEFINE_string( PD_DEFINE_string(
cinn_dump_group_instruction, cinn_dump_group_instruction,
StringFromEnv("FLAGS_cinn_dump_group_instruction", ""), StringFromEnv("FLAGS_cinn_dump_group_instruction", ""),
"Specify the path for dump instruction by group, which is used for debug."); "Specify the path for dump instruction by group, which is used for debug.");
DEFINE_string(cinn_pass_visualize_dir, PD_DEFINE_string(cinn_pass_visualize_dir,
StringFromEnv("FLAGS_cinn_pass_visualize_dir", ""), StringFromEnv("FLAGS_cinn_pass_visualize_dir", ""),
"Specify the directory path of pass visualize file of graph, " "Specify the directory path of pass visualize file of graph, "
"which is used for debug."); "which is used for debug.");
DEFINE_bool(enable_auto_tuner, PD_DEFINE_bool(enable_auto_tuner,
BoolFromEnv("FLAGS_enable_auto_tuner", false), BoolFromEnv("FLAGS_enable_auto_tuner", false),
"Whether enable auto tuner."); "Whether enable auto tuner.");
DEFINE_bool(auto_schedule_use_cost_model, PD_DEFINE_bool(auto_schedule_use_cost_model,
BoolFromEnv("FLAGS_auto_schedule_use_cost_model", true), BoolFromEnv("FLAGS_auto_schedule_use_cost_model", true),
"Whether to use cost model in auto schedule, this is an " "Whether to use cost model in auto schedule, this is an "
"on-developing flag and it will be removed when " "on-developing flag and it will be removed when "
"cost model is stable."); "cost model is stable.");
DEFINE_bool(enhance_vertical_fusion_with_recompute, PD_DEFINE_bool(
BoolFromEnv("FLAGS_enhance_vertical_fusion_with_recompute", true), enhance_vertical_fusion_with_recompute,
"Whether to enhance check logic on vertical fusion with recompute"); BoolFromEnv("FLAGS_enhance_vertical_fusion_with_recompute", true),
"Whether to enhance check logic on vertical fusion with recompute");
DEFINE_bool(verbose_function_register,
BoolFromEnv("FLAGS_verbose_function_register", false), PD_DEFINE_bool(verbose_function_register,
"Whether to verbose function regist log. This will only work if " BoolFromEnv("FLAGS_verbose_function_register", false),
"CINN build with flag -DWITH_DEBUG=ON."); "Whether to verbose function regist log. This will only work if "
"CINN build with flag -DWITH_DEBUG=ON.");
DEFINE_int32(cinn_profiler_state,
Int32FromEnv("FLAGS_cinn_profiler_state", -1), PD_DEFINE_int32(
"Specify the ProfilerState by Int in CINN, 0 for kDisabled, 1 for " cinn_profiler_state,
"kCPU, 2 for kCUDA, 3 for kAll, default 0."); Int32FromEnv("FLAGS_cinn_profiler_state", -1),
"Specify the ProfilerState by Int in CINN, 0 for kDisabled, 1 for "
DEFINE_int32(cinn_error_message_level, "kCPU, 2 for kCUDA, 3 for kAll, default 0.");
Int32FromEnv("FLAGS_cinn_error_message_level", 0),
"Specify the level of printing error message in the schedule." PD_DEFINE_int32(cinn_error_message_level,
"0 means short, 1 means detailed."); Int32FromEnv("FLAGS_cinn_error_message_level", 0),
"Specify the level of printing error message in the schedule."
DEFINE_double(cinn_infer_model_version, "0 means short, 1 means detailed.");
DoubleFromEnv("FLAGS_cinn_infer_model_version", 2.0),
"Paddle has different model format in inference model. We use " PD_DEFINE_double(cinn_infer_model_version,
"a flag to load different versions."); DoubleFromEnv("FLAGS_cinn_infer_model_version", 2.0),
"Paddle has different model format in inference model. We use "
"a flag to load different versions.");
namespace cinn { namespace cinn {
namespace runtime { namespace runtime {
......
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
#include "paddle/cinn/utils/profiler.h" #include "paddle/cinn/utils/profiler.h"
#include <gflags/gflags.h> #include "paddle/utils/flags.h"
#ifdef CINN_WITH_NVTX #ifdef CINN_WITH_NVTX
#include <nvToolsExt.h> #include <nvToolsExt.h>
...@@ -27,7 +27,7 @@ ...@@ -27,7 +27,7 @@
#endif #endif
#include <chrono> #include <chrono>
DECLARE_int32(cinn_profiler_state); PD_DECLARE_int32(cinn_profiler_state);
namespace cinn { namespace cinn {
namespace utils { namespace utils {
......
if(NOT WITH_GFLAGS)
cc_library(paddle_flags SRCS flags_native.cc)
if(CINN_ONLY)
return()
endif()
cc_test(
flags_native_test
SRCS flags_native_test.cc
DEPS paddle_flags)
endif()
add_subdirectory(string) add_subdirectory(string)
cc_test( cc_test(
...@@ -23,11 +34,3 @@ if(NOT ((NOT WITH_PYTHON) AND ON_INFER)) ...@@ -23,11 +34,3 @@ if(NOT ((NOT WITH_PYTHON) AND ON_INFER))
SRCS pybind.cc SRCS pybind.cc
DEPS phi) DEPS phi)
endif() endif()
if(NOT WITH_GFLAGS)
cc_library(paddle_flags SRCS flags_native.cc)
cc_test(
flags_native_test
SRCS flags_native_test.cc
DEPS paddle_flags)
endif()
...@@ -73,5 +73,31 @@ inline void AllowUndefinedFlags() { gflags::AllowCommandLineReparsing(); } ...@@ -73,5 +73,31 @@ inline void AllowUndefinedFlags() { gflags::AllowCommandLineReparsing(); }
using paddle::flags::AllowUndefinedFlags; using paddle::flags::AllowUndefinedFlags;
#endif #endif
#ifdef PADDLE_WITH_GFLAGS
using gflags::BoolFromEnv;
using gflags::DoubleFromEnv;
using gflags::Int32FromEnv;
using gflags::Int64FromEnv;
using gflags::StringFromEnv;
using gflags::UInt32FromEnv;
using gflags::UInt64FromEnv;
#else
#define DEFINE_FROM_ENV_FUNC(type, name) \
inline type name##FromEnv(const std::string& env_var_name, \
type default_val) { \
return GetFromEnv(env_var_name, default_val); \
}
DEFINE_FROM_ENV_FUNC(bool, Bool);
DEFINE_FROM_ENV_FUNC(int32_t, Int32);
DEFINE_FROM_ENV_FUNC(uint32_t, UInt32);
DEFINE_FROM_ENV_FUNC(int64_t, Int64);
DEFINE_FROM_ENV_FUNC(uint64_t, UInt64);
DEFINE_FROM_ENV_FUNC(double, Double);
DEFINE_FROM_ENV_FUNC(std::string, String);
#undef DEFINE_FROM_ENV_FUNC
#endif
} // namespace flags } // namespace flags
} // namespace paddle } // namespace paddle
...@@ -393,6 +393,10 @@ void ParseCommandLineFlags(int* pargc, char*** pargv) { ...@@ -393,6 +393,10 @@ void ParseCommandLineFlags(int* pargc, char*** pargv) {
for (size_t i = 0; i < argv_num; i++) { for (size_t i = 0; i < argv_num; i++) {
const std::string& argv = argvs[i]; const std::string& argv = argvs[i];
if (argv.empty()) {
continue;
}
if (argv.size() < 2 || argv[0] != '-') { if (argv.size() < 2 || argv[0] != '-') {
LOG_FLAG_FATAL_ERROR("invalid commandline argument: \"" + argv + "\", " + LOG_FLAG_FATAL_ERROR("invalid commandline argument: \"" + argv + "\", " +
arg_format_help); arg_format_help);
...@@ -480,5 +484,42 @@ void ParseCommandLineFlags(int* pargc, char*** pargv) { ...@@ -480,5 +484,42 @@ void ParseCommandLineFlags(int* pargc, char*** pargv) {
} }
} }
template <typename T>
T GetFromEnv(const std::string& name, const T& default_val) {
std::string value_str;
if (GetValueFromEnv(name, &value_str)) {
T value;
FlagType type = FlagTypeTraits<T>::Type;
Flag flag("tmp_" + name, "", "", type, &value, &value);
flag.SetValueFromString(value_str);
if (!ErrorStream().str().empty()) {
ErrorStream().str("");
LOG_FLAG_FATAL_ERROR("value \"" + value_str +
"\" of environment"
"variable \"" +
name +
"\" is invalid when "
"using GetFromEnv with " +
FlagType2String(type) + " type.");
}
return value;
} else {
return default_val;
}
}
#define INSTANTIATE_GET_FROM_ENV(type) \
template type GetFromEnv(const std::string& name, const type& default_val)
INSTANTIATE_GET_FROM_ENV(bool);
INSTANTIATE_GET_FROM_ENV(int32_t);
INSTANTIATE_GET_FROM_ENV(uint32_t);
INSTANTIATE_GET_FROM_ENV(int64_t);
INSTANTIATE_GET_FROM_ENV(uint64_t);
INSTANTIATE_GET_FROM_ENV(double);
INSTANTIATE_GET_FROM_ENV(std::string);
#undef INSTANTIATE_GET_FROM_ENV
} // namespace flags } // namespace flags
} // namespace paddle } // namespace paddle
...@@ -69,6 +69,12 @@ bool FindFlag(const std::string& name); ...@@ -69,6 +69,12 @@ bool FindFlag(const std::string& name);
*/ */
void PrintAllFlagHelp(bool to_file = false, void PrintAllFlagHelp(bool to_file = false,
const std::string& file_name = "all_flags.txt"); const std::string& file_name = "all_flags.txt");
/**
* @brief Get environment variable. If not found, return default value.
*/
template <typename T>
T GetFromEnv(const std::string& name, const T& default_val);
} // namespace flags } // namespace flags
} // namespace paddle } // namespace paddle
......
...@@ -34,6 +34,7 @@ void SplitCommandlineArg(const std::string& commandline, ...@@ -34,6 +34,7 @@ void SplitCommandlineArg(const std::string& commandline,
end_pos = commandline.find(' ', start_pos); end_pos = commandline.find(' ', start_pos);
args.push_back(commandline.substr(start_pos, end_pos - start_pos)); args.push_back(commandline.substr(start_pos, end_pos - start_pos));
} }
args.push_back(""); // test empty argument
*argc = args.size(); *argc = args.size();
*argv = new char*[*argc]; *argv = new char*[*argc];
for (size_t i = 0; i < args.size(); i++) { for (size_t i = 0; i < args.size(); i++) {
...@@ -88,6 +89,11 @@ TEST(flags_native_test, SetFlagsFromEnv) { ...@@ -88,6 +89,11 @@ TEST(flags_native_test, SetFlagsFromEnv) {
ASSERT_TRUE(SetEnvVar("FLAGS_paddle_test_env_bool", "true")); ASSERT_TRUE(SetEnvVar("FLAGS_paddle_test_env_bool", "true"));
ASSERT_TRUE(SetEnvVar("FLAGS_paddle_test_env_double", "2.71")); ASSERT_TRUE(SetEnvVar("FLAGS_paddle_test_env_double", "2.71"));
// test GetFromEnv
ASSERT_EQ(GetFromEnv<bool>("FLAGS_paddle_test_env_bool", false), true);
ASSERT_EQ(GetFromEnv<int32_t>("FLAGS_int32_not_defined", 34), 34);
// test SetFlagsFromEnv
std::string commandline = std::string commandline =
"test --fromenv=paddle_test_env_bool,paddle_test_env_double"; "test --fromenv=paddle_test_env_bool,paddle_test_env_double";
int argc; int argc;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册