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