From 51398d88f4ab8454251bb70c752aa6d92707804c Mon Sep 17 00:00:00 2001 From: tqchen Date: Wed, 7 May 2025 19:57:40 -0400 Subject: [PATCH] [REFACTOR][FFI] Cleanup container redirections This PR cleans up the container redirections and headers so the files directly points to new ones in ffi folder - runtime/shape_tuple.h => ffi/container/shape.h - for IntTuple alias, introduce runtime/int_tuple.h for now - runtime/container/array.h => ffi/container/array.h - runtime/container/map.h => ffi/container/map.h - runtime/container/optional.h => ffi/optional.h - runtime/container/string.h => ffi/string.h - runtime/container/variant.h => ffi/container/variant.h - runtime/container/tuple.h => ffi/container/tuple.h We also introduce limited number of tvm::ffi classes into tvm namespace, when they are commonly used and their is no ambiguity. --- ffi/include/tvm/ffi/cast.h | 5 + ffi/include/tvm/ffi/container/array.h | 4 + ffi/include/tvm/ffi/container/map.h | 6 +- ffi/include/tvm/ffi/container/tuple.h | 4 + ffi/include/tvm/ffi/container/variant.h | 4 + ffi/include/tvm/ffi/function.h | 1 + ffi/include/tvm/ffi/memory.h | 4 + ffi/include/tvm/ffi/optional.h | 3 + ffi/include/tvm/ffi/string.h | 5 + include/tvm/arith/int_set.h | 6 +- include/tvm/ir/analysis.h | 2 +- include/tvm/ir/attrs.h | 2 +- include/tvm/ir/expr.h | 4 +- include/tvm/ir/function.h | 6 +- include/tvm/ir/instrument.h | 2 +- include/tvm/ir/module.h | 6 +- include/tvm/ir/transform.h | 8 +- include/tvm/ir/type.h | 2 +- include/tvm/meta_schedule/arg_info.h | 6 +- include/tvm/meta_schedule/builder.h | 10 +- include/tvm/meta_schedule/cost_model.h | 4 +- include/tvm/meta_schedule/database.h | 16 +- include/tvm/meta_schedule/extracted_task.h | 4 +- include/tvm/meta_schedule/feature_extractor.h | 4 +- include/tvm/meta_schedule/measure_callback.h | 4 +- include/tvm/meta_schedule/measure_candidate.h | 2 +- include/tvm/meta_schedule/mutator.h | 2 +- include/tvm/meta_schedule/profiler.h | 6 +- include/tvm/meta_schedule/runner.h | 6 +- include/tvm/meta_schedule/schedule_rule.h | 57 ++-- include/tvm/meta_schedule/search_strategy.h | 4 +- include/tvm/meta_schedule/space_generator.h | 2 +- include/tvm/meta_schedule/task_scheduler.h | 10 +- include/tvm/meta_schedule/tune_context.h | 8 +- include/tvm/node/attr_registry_map.h | 2 +- include/tvm/node/node.h | 3 +- include/tvm/node/object_path.h | 8 +- include/tvm/node/reflection.h | 16 +- include/tvm/node/script_printer.h | 8 +- include/tvm/node/structural_equal.h | 30 +- include/tvm/relax/analysis.h | 2 +- include/tvm/relax/block_builder.h | 2 +- include/tvm/relax/dataflow_matcher.h | 8 +- include/tvm/relax/dataflow_pattern.h | 10 +- include/tvm/relax/distributed/global_info.h | 6 +- include/tvm/relax/expr.h | 8 +- include/tvm/relax/expr_functor.h | 6 +- include/tvm/relax/nested_msg.h | 10 +- include/tvm/relax/struct_info.h | 12 +- include/tvm/relax/transform.h | 16 +- include/tvm/runtime/container/array.h | 41 --- include/tvm/runtime/container/base.h | 278 ------------------ include/tvm/runtime/container/map.h | 40 --- include/tvm/runtime/container/optional.h | 39 --- include/tvm/runtime/container/shape_tuple.h | 53 ---- include/tvm/runtime/container/string.h | 41 --- include/tvm/runtime/container/variant.h | 39 --- include/tvm/runtime/contrib/papi.h | 4 +- include/tvm/runtime/disco/builtin.h | 2 +- include/tvm/runtime/disco/session.h | 2 +- include/tvm/runtime/{memory.h => int_tuple.h} | 19 +- include/tvm/runtime/memory/memory_manager.h | 12 +- include/tvm/runtime/module.h | 6 +- include/tvm/runtime/ndarray.h | 18 +- include/tvm/runtime/object.h | 13 +- include/tvm/runtime/profiling.h | 4 +- include/tvm/runtime/registry.h | 2 +- .../runtime/relax_vm/ndarray_cache_support.h | 4 +- include/tvm/script/ir_builder/base.h | 10 +- include/tvm/script/ir_builder/relax/frame.h | 2 +- include/tvm/script/ir_builder/relax/ir.h | 2 +- include/tvm/script/ir_builder/tir/ir.h | 39 +-- include/tvm/script/printer/doc.h | 16 +- include/tvm/script/printer/ir_docsifier.h | 2 +- include/tvm/target/target.h | 4 +- include/tvm/tir/analysis.h | 4 +- include/tvm/tir/buffer.h | 10 +- include/tvm/tir/expr.h | 8 +- include/tvm/tir/function.h | 4 +- include/tvm/tir/index_map.h | 6 +- include/tvm/tir/op_attr_types.h | 2 +- include/tvm/tir/schedule/schedule.h | 29 +- include/tvm/tir/schedule/trace.h | 2 +- include/tvm/tir/stmt.h | 16 +- include/tvm/tir/stmt_functor.h | 14 +- include/tvm/topi/nn/pooling.h | 8 +- python/setup.py | 2 - python/tvm/relax/expr_functor.py | 2 +- python/tvm/runtime/disco/session.py | 2 +- python/tvm/tir/schedule/trace.py | 2 +- python/tvm/tir/schedule/transform.py | 2 +- src/arith/canonical_simplify.cc | 2 +- src/arith/const_fold.h | 44 +-- src/arith/const_int_bound.cc | 2 +- src/arith/domain_touched.cc | 6 +- src/arith/int_set.cc | 8 +- src/arith/iter_affine_map.cc | 20 +- src/arith/rewrite_simplify.cc | 6 +- src/arith/scalable_expression.h | 2 +- src/contrib/msc/core/codegen/code_stack.cc | 10 +- src/contrib/msc/core/codegen/code_stack.h | 8 +- src/contrib/msc/core/ir/graph.cc | 2 +- src/contrib/msc/core/ir/graph_builder.cc | 22 +- src/contrib/msc/core/ir/graph_builder.h | 2 +- .../msc/core/printer/msc_base_printer.cc | 2 +- src/contrib/msc/core/printer/print_utils.cc | 8 +- src/contrib/msc/core/printer/print_utils.h | 8 +- .../msc/core/printer/prototxt_printer.cc | 10 +- src/contrib/msc/core/transform/fuse_tuple.cc | 21 +- .../msc/core/transform/inline_params.cc | 2 +- .../msc/core/transform/rewrite_utils.cc | 2 +- .../msc/core/transform/set_byoc_attrs.cc | 4 +- .../msc/core/transform/set_expr_name.cc | 8 +- src/contrib/msc/core/utils.cc | 4 +- .../msc/framework/tensorflow/tf_v1_opcode.cc | 2 +- src/contrib/msc/framework/tensorrt/codegen.cc | 36 +-- .../msc/framework/tensorrt/tensorrt_opcode.cc | 18 +- .../framework/tensorrt/transform_tensorrt.cc | 2 +- src/contrib/msc/plugin/tensorrt_codegen.cc | 8 +- src/contrib/msc/plugin/torch_codegen.cc | 2 +- src/ir/attr_functor.h | 4 +- src/ir/module.cc | 4 +- src/ir/replace_global_vars.cc | 2 +- src/ir/transform.cc | 7 +- src/meta_schedule/arg_info.cc | 14 +- src/meta_schedule/database/database.cc | 20 +- src/meta_schedule/database/database_utils.cc | 2 +- src/meta_schedule/database/json_database.cc | 2 +- .../database/ordered_union_database.cc | 2 +- .../database/schedule_fn_database.cc | 8 +- src/meta_schedule/database/union_database.cc | 2 +- .../mutator/mutate_compute_location.cc | 2 +- src/meta_schedule/mutator/mutate_parallel.cc | 4 +- .../mutator/mutate_thread_binding.cc | 2 +- src/meta_schedule/mutator/mutate_tile_size.cc | 4 +- src/meta_schedule/mutator/mutate_unroll.cc | 4 +- .../disallow_async_strided_mem_copy.cc | 4 +- .../postproc/rewrite_cooperative_fetch.cc | 20 +- src/meta_schedule/postproc/rewrite_layout.cc | 7 +- .../rewrite_parallel_vectorize_unroll.cc | 2 +- .../postproc/rewrite_reduction_block.cc | 2 +- src/meta_schedule/postproc/verify_gpu_code.cc | 4 +- src/meta_schedule/profiler.cc | 2 +- .../schedule/cuda/thread_bind.cc | 4 +- src/meta_schedule/schedule/cuda/winograd.cc | 4 +- .../schedule_rule/apply_custom_rule.cc | 2 +- .../schedule_rule/cross_thread_reduction.cc | 4 +- .../multi_level_tiling_tensor_core.cc | 8 +- .../multi_level_tiling_wide_vector.cc | 4 +- .../multi_level_tiling_with_intrin.cc | 2 +- .../schedule_rule/schedule_rule.cc | 50 ++-- .../search_strategy/evolutionary_search.cc | 8 +- .../search_strategy/replay_func.cc | 10 +- .../search_strategy/replay_trace.cc | 4 +- .../task_scheduler/task_scheduler.cc | 12 +- src/meta_schedule/utils.h | 10 +- src/node/container_printing.cc | 12 +- src/node/object_path.cc | 2 +- src/node/reflection.cc | 4 +- src/node/script_printer.cc | 6 +- src/node/serialization.cc | 24 +- src/node/structural_equal.cc | 6 +- src/node/structural_hash.cc | 60 ++-- src/relax/analysis/analysis.cc | 2 +- src/relax/analysis/struct_info_analysis.cc | 6 +- src/relax/analysis/tir_op_pattern_kind.cc | 2 +- src/relax/analysis/udchain.cc | 5 +- src/relax/analysis/var2value.cc | 10 +- src/relax/analysis/well_formed.cc | 4 +- .../backend/contrib/codegen_c/codegen_c.h | 10 +- .../contrib/codegen_json/codegen_json.h | 6 +- src/relax/backend/contrib/cutlass/codegen.cc | 2 +- src/relax/backend/pattern_registry.cc | 2 +- src/relax/backend/pattern_registry.h | 4 +- src/relax/backend/vm/codegen_vm.cc | 2 +- src/relax/backend/vm/codegen_vm_tir.cc | 10 +- src/relax/backend/vm/vm_shape_lower.cc | 4 +- src/relax/distributed/global_info.cc | 6 +- .../distributed/transform/lower_distir.cc | 4 +- .../transform/propagate_sharding.cc | 2 +- src/relax/distributed/transform/utils.h | 2 +- src/relax/ir/binding_rewrite.cc | 2 +- src/relax/ir/block_builder.cc | 10 +- src/relax/ir/dataflow_block_rewriter.cc | 8 +- src/relax/ir/dataflow_expr_rewriter.cc | 11 +- src/relax/ir/dataflow_matcher.cc | 8 +- src/relax/ir/dataflow_matcher.h | 2 +- src/relax/ir/dataflow_pattern.cc | 4 +- src/relax/ir/dataflow_rewriter.h | 6 +- src/relax/ir/emit_te.cc | 2 +- src/relax/ir/expr.cc | 14 +- src/relax/ir/expr_functor.cc | 2 +- src/relax/ir/struct_info.cc | 2 +- src/relax/op/memory/view.cc | 8 +- src/relax/op/nn/attention.cc | 4 +- src/relax/op/op.cc | 20 +- src/relax/op/op_common.cc | 2 +- src/relax/op/op_common.h | 10 +- src/relax/op/tensor/binary.cc | 4 +- src/relax/op/tensor/create.cc | 2 +- src/relax/op/tensor/create.h | 2 +- src/relax/op/tensor/index.cc | 34 +-- src/relax/op/tensor/index.h | 6 +- src/relax/op/tensor/manipulate.cc | 22 +- src/relax/op/tensor/manipulate.h | 10 +- src/relax/op/tensor/set.cc | 8 +- src/relax/op/tensor/statistical.h | 18 +- src/relax/training/utils.cc | 2 +- src/relax/training/utils.h | 2 +- src/relax/transform/adjust_matmul_order.cc | 10 +- src/relax/transform/canonicalize_bindings.cc | 18 +- .../transform/combine_parallel_matmul.cc | 4 +- src/relax/transform/convert_dataflow.cc | 2 +- src/relax/transform/convert_layout.cc | 6 +- src/relax/transform/dead_code_elimination.cc | 4 +- .../transform/eliminate_common_subexpr.cc | 2 +- src/relax/transform/expand_tuple_arguments.cc | 4 +- src/relax/transform/few_shot_tuning.cc | 12 +- src/relax/transform/fold_constant.cc | 24 +- src/relax/transform/fuse_ops.cc | 20 +- src/relax/transform/fuse_tir.cc | 4 +- src/relax/transform/gradient.cc | 2 +- src/relax/transform/infer_amp_utils.h | 5 +- src/relax/transform/inline_functions.cc | 2 +- src/relax/transform/lambda_lift.cc | 6 +- src/relax/transform/lazy_transform_params.cc | 2 +- src/relax/transform/legalize_ops.cc | 2 +- .../transform/merge_composite_functions.cc | 4 +- src/relax/transform/meta_schedule.cc | 7 +- src/relax/transform/normalize.cc | 4 +- src/relax/transform/realize_vdevice.cc | 6 +- src/relax/transform/remove_unused_outputs.cc | 2 +- src/relax/transform/rewrite_cuda_graph.cc | 8 +- .../transform/split_call_tir_by_pattern.cc | 12 +- .../transform/split_layout_rewrite_preproc.cc | 4 +- .../transform/static_plan_block_memory.cc | 11 +- src/relax/transform/to_mixed_precision.cc | 8 +- src/relax/transform/topological_sort.cc | 4 +- src/relax/transform/tuning_api/database.cc | 6 +- src/relax/transform/tuning_api/primitives.cc | 16 +- src/relax/transform/utils.h | 4 +- src/runtime/c_runtime_api.cc | 6 +- src/runtime/const_loader_module.cc | 6 +- src/runtime/container.cc | 25 +- src/runtime/contrib/clml/clml_runtime.cc | 2 +- src/runtime/contrib/cudnn/cudnn_utils.cc | 2 +- src/runtime/contrib/json/json_node.h | 2 +- src/runtime/contrib/nnapi/nnapi_ops.cc | 2 +- src/runtime/contrib/nvshmem/init.cc | 8 +- .../contrib/nvshmem/memory_allocator.cc | 4 +- src/runtime/debug_compile.cc | 10 +- src/runtime/disco/bcast_session.cc | 2 +- src/runtime/disco/builtin.cc | 20 +- src/runtime/disco/cuda_ipc/cuda_ipc_memory.cc | 2 +- src/runtime/disco/loader.cc | 18 +- src/runtime/disco/nccl/nccl.cc | 8 +- src/runtime/disco/process_session.cc | 2 +- src/runtime/disco/protocol.h | 30 +- src/runtime/disco/utils.h | 2 +- src/runtime/dso_library.cc | 2 +- src/runtime/file_utils.h | 4 +- src/runtime/memory/memory_manager.cc | 8 +- src/runtime/memory/naive_allocator.h | 2 +- src/runtime/memory/pooled_allocator.h | 2 +- src/runtime/ndarray.cc | 10 +- src/runtime/opencl/opencl_common.h | 10 +- src/runtime/opencl/opencl_device_api.cc | 6 +- src/runtime/profiling.cc | 8 +- src/runtime/registry.cc | 2 +- src/runtime/relax_vm/attn_backend.h | 3 +- src/runtime/relax_vm/attn_utils.h | 12 +- src/runtime/relax_vm/builtin.cc | 29 +- .../relax_vm/cuda/cuda_graph_builtin.cc | 12 +- src/runtime/relax_vm/executable.cc | 46 ++- src/runtime/relax_vm/kv_state.cc | 12 +- src/runtime/relax_vm/kv_state.h | 8 +- src/runtime/relax_vm/lm_support.cc | 18 +- src/runtime/relax_vm/ndarray_cache_support.cc | 8 +- src/runtime/relax_vm/paged_kv_cache.cc | 43 +-- src/runtime/relax_vm/rnn_state.cc | 14 +- src/runtime/relax_vm/vm.cc | 2 +- src/runtime/rpc/rpc_module.cc | 2 +- src/runtime/static_library.cc | 2 +- src/runtime/static_library.h | 2 +- src/runtime/system_library.cc | 2 +- src/runtime/thread_pool.cc | 2 +- src/runtime/threading_backend.cc | 2 +- src/script/ir_builder/base.cc | 4 +- src/script/ir_builder/ir/ir.cc | 2 +- src/script/ir_builder/relax/ir.cc | 6 +- src/script/ir_builder/tir/ir.cc | 24 +- src/script/printer/doc.cc | 6 +- src/script/printer/ir/distributed.cc | 19 +- src/script/printer/ir/ir.cc | 2 +- src/script/printer/ir/misc.cc | 2 +- src/script/printer/ir_docsifier.cc | 16 +- src/script/printer/legacy_repr.cc | 12 +- src/script/printer/relax/binding.cc | 4 +- src/script/printer/relax/call.cc | 10 +- src/script/printer/relax/expr.cc | 6 +- src/script/printer/relax/function.cc | 5 +- src/script/printer/relax/region.cc | 2 +- src/script/printer/relax/tir.cc | 4 +- src/script/printer/relax/utils.h | 10 +- src/script/printer/tir/block.cc | 17 +- src/script/printer/tir/buffer.cc | 20 +- src/script/printer/tir/expr.cc | 4 +- src/script/printer/tir/for_loop.cc | 8 +- src/script/printer/tir/function.cc | 12 +- src/script/printer/tir/stmt.cc | 34 +-- src/script/printer/tir/utils.h | 4 +- src/script/printer/utils.h | 7 +- src/support/array.h | 14 +- src/support/ffi_testing.cc | 2 +- src/support/utils.h | 2 +- src/target/codegen.cc | 2 +- src/target/llvm/codegen_amdgpu.cc | 4 +- src/target/llvm/codegen_hexagon.cc | 2 +- src/target/llvm/codegen_llvm.h | 2 +- src/target/llvm/codegen_nvptx.cc | 2 +- src/target/llvm/llvm_instance.cc | 8 +- src/target/llvm/llvm_instance.h | 6 +- src/target/llvm/llvm_module.cc | 4 +- src/target/llvm/llvm_module.h | 2 +- src/target/tag.cc | 2 +- src/target/target.cc | 28 +- src/target/target_kind.cc | 2 +- src/te/operation/create_primfunc.cc | 12 +- src/te/operation/create_primfunc.h | 2 +- src/te/operation/placeholder_op.cc | 2 +- .../analysis/buffer_access_lca_detector.cc | 3 +- .../analysis/calculate_allocated_memory.cc | 2 +- src/tir/analysis/control_flow_graph.cc | 14 +- src/tir/analysis/control_flow_graph.h | 2 +- src/tir/analysis/deep_equal.cc | 2 +- src/tir/analysis/identify_memcpy.cc | 2 +- src/tir/analysis/stmt_finding.cc | 2 +- src/tir/ir/block_dependence_info.cc | 2 +- src/tir/ir/data_type_rewriter.cc | 6 +- src/tir/ir/expr.cc | 61 ++-- src/tir/ir/function.cc | 2 +- src/tir/ir/functor_common.h | 2 +- src/tir/ir/index_map.cc | 6 +- src/tir/ir/script/script_complete.cc | 2 +- src/tir/ir/stmt_functor.cc | 4 +- src/tir/schedule/analysis.h | 12 +- src/tir/schedule/analysis/analysis.cc | 24 +- src/tir/schedule/analysis/layout.cc | 2 +- src/tir/schedule/analysis/verify.cc | 6 +- src/tir/schedule/concrete_schedule.cc | 8 +- src/tir/schedule/concrete_schedule.h | 10 +- src/tir/schedule/instruction.cc | 2 +- src/tir/schedule/instruction_traits.h | 10 +- src/tir/schedule/primitive/block_annotate.cc | 2 +- .../schedule/primitive/blockize_tensorize.cc | 10 +- src/tir/schedule/primitive/cache_index.cc | 2 +- .../schedule/primitive/cache_read_write.cc | 10 +- src/tir/schedule/primitive/compute_at.cc | 2 +- src/tir/schedule/primitive/for_kind.cc | 8 +- .../primitive/layout_transformation.cc | 14 +- .../schedule/primitive/loop_transformation.cc | 16 +- src/tir/schedule/primitive/pad_einsum.cc | 8 +- src/tir/schedule/primitive/read_write_at.cc | 2 +- src/tir/schedule/primitive/reduction.cc | 6 +- src/tir/schedule/primitive/rolling_buffer.cc | 6 +- src/tir/schedule/state.cc | 6 +- src/tir/schedule/trace.cc | 34 +-- src/tir/schedule/traced_schedule.cc | 2 +- src/tir/schedule/traced_schedule.h | 9 +- src/tir/schedule/transform.cc | 12 +- src/tir/schedule/transform.h | 2 +- src/tir/schedule/utils.h | 14 +- src/tir/transforms/common_subexpr_elim.cc | 4 +- .../transforms/common_subexpr_elim_tools.cc | 4 +- .../transforms/common_subexpr_elim_tools.h | 2 +- src/tir/transforms/compact_buffer_region.cc | 2 +- src/tir/transforms/default_gpu_schedule.cc | 10 +- src/tir/transforms/inject_permuted_layout.cc | 2 +- .../transforms/inject_software_pipeline.cc | 8 +- src/tir/transforms/inject_virtual_thread.cc | 2 +- .../transforms/inline_private_functions.cc | 12 +- src/tir/transforms/ir_utils.cc | 6 +- .../lower_cross_thread_reduction.cc | 12 +- .../transforms/lower_device_kernel_launch.cc | 4 +- src/tir/transforms/lower_init_block.cc | 2 +- src/tir/transforms/lower_intrin.cc | 2 +- src/tir/transforms/lower_opaque_block.cc | 2 +- src/tir/transforms/lower_thread_allreduce.cc | 12 +- src/tir/transforms/lower_tvm_builtin.cc | 9 +- src/tir/transforms/make_packed_api.cc | 8 +- src/tir/transforms/make_unpacked_api.cc | 2 +- src/tir/transforms/memhammer_coalesce.cc | 2 +- .../memhammer_intermediate_stage.cc | 2 +- .../memhammer_tensorcore_rewrite.cc | 10 +- .../plan_update_buffer_allocation_location.cc | 2 +- src/tir/transforms/remap_thread_axis.cc | 4 +- src/tir/transforms/renew_defs.cc | 2 +- src/tir/transforms/simplify.cc | 6 +- src/tir/transforms/unify_thread_binding.cc | 2 +- .../transforms/unsupported_dtype_legalize.cc | 3 +- .../using_assume_to_reduce_branches.cc | 2 +- src/tir/transforms/vectorize_loop.cc | 2 +- .../hexagon/hexagon_buffer_tests.cc | 3 +- .../hexagon/hexagon_device_api_tests.cc | 1 + .../hexagon/hexagon_user_dma_tests.cc | 1 + .../hexagon/hexagon_vtcm_pool_tests.cc | 1 + .../cpp-runtime/opencl/aa_opencl_qcom_extn.cc | 2 +- .../cpp-runtime/opencl/clml_memory_planner.cc | 2 +- .../opencl/opencl_compile_to_bin.cc | 12 +- tests/cpp-runtime/opencl/opencl_nativeptr.cc | 2 +- tests/cpp-runtime/opencl/texture_copy_test.cc | 24 +- tests/cpp/ir_functor_test.cc | 2 +- tests/cpp/nested_msg_test.cc | 51 ++-- tests/cpp/object_protocol_test.cc | 3 +- .../runtime/memory/memory_manager_tests.cc | 10 +- tests/cpp/tir_scalable_datatype.cc | 4 +- tests/python/runtime/test_runtime_rpc.py | 6 +- .../testing/test_type_annotation_checker.py | 2 +- web/emcc/wasm_runtime.cc | 2 +- 419 files changed, 1609 insertions(+), 2109 deletions(-) delete mode 100644 include/tvm/runtime/container/array.h delete mode 100644 include/tvm/runtime/container/base.h delete mode 100644 include/tvm/runtime/container/map.h delete mode 100644 include/tvm/runtime/container/optional.h delete mode 100644 include/tvm/runtime/container/shape_tuple.h delete mode 100644 include/tvm/runtime/container/string.h delete mode 100644 include/tvm/runtime/container/variant.h rename include/tvm/runtime/{memory.h => int_tuple.h} (73%) diff --git a/ffi/include/tvm/ffi/cast.h b/ffi/include/tvm/ffi/cast.h index 99069fb13b3c..5995abbf1516 100644 --- a/ffi/include/tvm/ffi/cast.h +++ b/ffi/include/tvm/ffi/cast.h @@ -156,5 +156,10 @@ inline OptionalType Downcast(const std::optional& ref) { } } // namespace ffi + +// Expose to the tvm namespace +// Rationale: convinience and no ambiguity +using ffi::Downcast; +using ffi::GetRef; } // namespace tvm #endif // TVM_FFI_CAST_H_ diff --git a/ffi/include/tvm/ffi/container/array.h b/ffi/include/tvm/ffi/container/array.h index 5922eacb10f5..ce004360434a 100644 --- a/ffi/include/tvm/ffi/container/array.h +++ b/ffi/include/tvm/ffi/container/array.h @@ -1031,5 +1031,9 @@ inline constexpr bool type_contains_v, Array> = type_contains_vend()); } /*! \return find the key and returns the associated iterator */ iterator find(const K& key) const { return iterator(GetMapObj()->find(key)); } - /*! \return The value associated with the key, NullOpt if not found */ + /*! \return The value associated with the key, std::nullopt if not found */ std::optional Get(const K& key) const { MapObj::iterator iter = GetMapObj()->find(key); if (iter == GetMapObj()->end()) { @@ -1602,5 +1602,9 @@ inline constexpr bool type_contains_v, Map> = } // namespace details } // namespace ffi + +// Expose to the tvm namespace +// Rationale: convinience and no ambiguity +using ffi::Map; } // namespace tvm #endif // TVM_FFI_CONTAINER_MAP_H_ diff --git a/ffi/include/tvm/ffi/container/tuple.h b/ffi/include/tvm/ffi/container/tuple.h index 63c36467fe3d..641d006a94ea 100644 --- a/ffi/include/tvm/ffi/container/tuple.h +++ b/ffi/include/tvm/ffi/container/tuple.h @@ -275,5 +275,9 @@ inline constexpr bool type_contains_v, Tuple> = (type_contains } // namespace details } // namespace ffi + +// Expose to the tvm namespace +// Rationale: convinience and no ambiguity +using ffi::Tuple; } // namespace tvm #endif // TVM_FFI_CONTAINER_TUPLE_H_ diff --git a/ffi/include/tvm/ffi/container/variant.h b/ffi/include/tvm/ffi/container/variant.h index c8b58ba49e39..f134be833193 100644 --- a/ffi/include/tvm/ffi/container/variant.h +++ b/ffi/include/tvm/ffi/container/variant.h @@ -194,5 +194,9 @@ template inline constexpr bool type_contains_v, T> = (type_contains_v || ...); } // namespace details } // namespace ffi + +// Expose to the tvm namespace +// Rationale: convinience and no ambiguity +using ffi::Variant; } // namespace tvm #endif // TVM_FFI_CONTAINER_VARIANT_H_ diff --git a/ffi/include/tvm/ffi/function.h b/ffi/include/tvm/ffi/function.h index bdcca7b73ead..2bf6b960d7c5 100644 --- a/ffi/include/tvm/ffi/function.h +++ b/ffi/include/tvm/ffi/function.h @@ -909,6 +909,7 @@ inline int32_t TypeKeyToIndex(std::string_view type_key) { */ #define TVM_FFI_REGISTER_GLOBAL(OpName) \ TVM_FFI_STR_CONCAT(TVM_FFI_FUNC_REG_VAR_DEF, __COUNTER__) = ::tvm::ffi::Function::Registry(OpName) + } // namespace ffi } // namespace tvm #endif // TVM_FFI_FUNCTION_H_ diff --git a/ffi/include/tvm/ffi/memory.h b/ffi/include/tvm/ffi/memory.h index d3af2dd49077..eb317d2bbd72 100644 --- a/ffi/include/tvm/ffi/memory.h +++ b/ffi/include/tvm/ffi/memory.h @@ -205,5 +205,9 @@ inline ObjectPtr make_inplace_array_object(size_t num_elems, Args&&.. } } // namespace ffi + +// Export the make_object function +// rationale: ease of use, and no ambiguity +using ffi::make_object; } // namespace tvm #endif // TVM_FFI_MEMORY_H_ diff --git a/ffi/include/tvm/ffi/optional.h b/ffi/include/tvm/ffi/optional.h index 7b3f69ef9919..9c73d6a5705d 100644 --- a/ffi/include/tvm/ffi/optional.h +++ b/ffi/include/tvm/ffi/optional.h @@ -295,5 +295,8 @@ class Optional>> : public Object } }; } // namespace ffi + +// Expose to the tvm namespace +using ffi::Optional; } // namespace tvm #endif // TVM_FFI_OPTIONAL_H_ diff --git a/ffi/include/tvm/ffi/string.h b/ffi/include/tvm/ffi/string.h index 1c22f10892ac..e0fa7dad8a42 100644 --- a/ffi/include/tvm/ffi/string.h +++ b/ffi/include/tvm/ffi/string.h @@ -641,6 +641,11 @@ inline int Bytes::memncmp(const char* lhs, const char* rhs, size_t lhs_count, si } } } // namespace ffi + +// Expose to the tvm namespace for usability +// Rationale: no ambiguity even in root +using ffi::Bytes; +using ffi::String; } // namespace tvm namespace std { diff --git a/include/tvm/arith/int_set.h b/include/tvm/arith/int_set.h index f09564d050ca..29d6282ca351 100644 --- a/include/tvm/arith/int_set.h +++ b/include/tvm/arith/int_set.h @@ -299,7 +299,8 @@ Map AsIntSet(const Map& var_dom); * \param var_dom The ranges of the variables * \param predicate The predicate for the affine map * \param analyzer The analyzer used - * \return NullOpt if the detection fails, or an array of arith::IntSet as the result of analysis + * \return std::nullopt if the detection fails, or an array of arith::IntSet as the result of + * analysis */ TVM_DLL Optional> EstimateRegionStrictBound(const Array& region, const Map& var_dom, @@ -313,7 +314,8 @@ TVM_DLL Optional> EstimateRegionStrictBound(const Array& re * \param var_dom The ranges of the variables * \param predicate The predicate for the affine map * \param analyzer The analyzer used - * \return NullOpt if the detection fails, or an array of arith::IntSet as the result of analysis + * \return std::nullopt if the detection fails, or an array of arith::IntSet as the result of + * analysis */ TVM_DLL Optional> EstimateRegionLowerBound(const Array& region, const Map& var_dom, diff --git a/include/tvm/ir/analysis.h b/include/tvm/ir/analysis.h index afe18792dee0..ad95f2f0ebb5 100644 --- a/include/tvm/ir/analysis.h +++ b/include/tvm/ir/analysis.h @@ -27,10 +27,10 @@ #ifndef TVM_IR_ANALYSIS_H_ #define TVM_IR_ANALYSIS_H_ +#include #include #include #include -#include namespace tvm { namespace ir { diff --git a/include/tvm/ir/attrs.h b/include/tvm/ir/attrs.h index 6e004415f8e9..510c5325f3c4 100644 --- a/include/tvm/ir/attrs.h +++ b/include/tvm/ir/attrs.h @@ -45,10 +45,10 @@ #define TVM_IR_ATTRS_H_ #include +#include #include #include #include -#include #include #include diff --git a/include/tvm/ir/expr.h b/include/tvm/ir/expr.h index a3defa592af6..974747c77416 100644 --- a/include/tvm/ir/expr.h +++ b/include/tvm/ir/expr.h @@ -24,10 +24,10 @@ #ifndef TVM_IR_EXPR_H_ #define TVM_IR_EXPR_H_ +#include #include #include #include -#include #include #include @@ -38,7 +38,7 @@ namespace tvm { -using tvm::runtime::String; +using tvm::String; // Forward-declare VirtualDevice to avoid circular imports. class VirtualDevice; diff --git a/include/tvm/ir/function.h b/include/tvm/ir/function.h index e19e3f3af124..fa51856a0104 100644 --- a/include/tvm/ir/function.h +++ b/include/tvm/ir/function.h @@ -24,11 +24,11 @@ #ifndef TVM_IR_FUNCTION_H_ #define TVM_IR_FUNCTION_H_ +#include +#include +#include #include #include -#include -#include -#include #include #include diff --git a/include/tvm/ir/instrument.h b/include/tvm/ir/instrument.h index 1b9eb9c1b7c8..b1ef86c12c58 100644 --- a/include/tvm/ir/instrument.h +++ b/include/tvm/ir/instrument.h @@ -26,8 +26,8 @@ #ifndef TVM_IR_INSTRUMENT_H_ #define TVM_IR_INSTRUMENT_H_ +#include #include -#include #include #include diff --git a/include/tvm/ir/module.h b/include/tvm/ir/module.h index 66637f67d948..994f3a4bb86a 100644 --- a/include/tvm/ir/module.h +++ b/include/tvm/ir/module.h @@ -24,14 +24,14 @@ #ifndef TVM_IR_MODULE_H_ #define TVM_IR_MODULE_H_ +#include +#include +#include #include #include #include #include #include -#include -#include -#include #include #include diff --git a/include/tvm/ir/transform.h b/include/tvm/ir/transform.h index 0da882f3884d..0cc9383bac3c 100644 --- a/include/tvm/ir/transform.h +++ b/include/tvm/ir/transform.h @@ -56,11 +56,11 @@ #ifndef TVM_IR_TRANSFORM_H_ #define TVM_IR_TRANSFORM_H_ +#include +#include #include #include #include -#include -#include #include #include @@ -365,7 +365,7 @@ class PassInfo : public ObjectRef { * \param required The passes that are required to perform the current pass. * \param traceable Boolean that tells whether the pass is traceable. */ - TVM_DLL PassInfo(int opt_level, String name, Array required, bool traceable); + TVM_DLL PassInfo(int opt_level, String name, Array required, bool traceable); TVM_DEFINE_OBJECT_REF_METHODS(PassInfo, ObjectRef, PassInfoNode); }; @@ -538,7 +538,7 @@ class Sequential : public Pass { * \return The created module pass. */ TVM_DLL Pass CreateModulePass(std::function pass_func, - int opt_level, String name, Array required, + int opt_level, String name, Array required, bool traceable = false); /* diff --git a/include/tvm/ir/type.h b/include/tvm/ir/type.h index 5faaa31ca23b..2e49a9c5185b 100644 --- a/include/tvm/ir/type.h +++ b/include/tvm/ir/type.h @@ -49,9 +49,9 @@ #ifndef TVM_IR_TYPE_H_ #define TVM_IR_TYPE_H_ +#include #include #include -#include #include #include diff --git a/include/tvm/meta_schedule/arg_info.h b/include/tvm/meta_schedule/arg_info.h index ccf093126232..2768ed2737dc 100644 --- a/include/tvm/meta_schedule/arg_info.h +++ b/include/tvm/meta_schedule/arg_info.h @@ -19,10 +19,10 @@ #ifndef TVM_META_SCHEDULE_ARG_INFO_H_ #define TVM_META_SCHEDULE_ARG_INFO_H_ +#include #include #include #include -#include #include #include #include @@ -81,7 +81,7 @@ class TensorInfoNode : public ArgInfoNode { /*! \brief The data type of the tensor. */ runtime::DataType dtype; /*! \brief The shape of the tensor. */ - runtime::ShapeTuple shape; + ffi::Shape shape; void VisitAttrs(tvm::AttrVisitor* v) { v->Visit("dtype", &dtype); @@ -106,7 +106,7 @@ class TensorInfo : public ArgInfo { * \param dtype The data type of the tensor argument. * \param shape The shape tuple of the tensor argument. */ - TVM_DLL explicit TensorInfo(runtime::DataType dtype, runtime::ShapeTuple shape); + TVM_DLL explicit TensorInfo(runtime::DataType dtype, ffi::Shape shape); /*! * \brief Parse the argument information from a JSON object. * \param json_obj The json object to parse. diff --git a/include/tvm/meta_schedule/builder.h b/include/tvm/meta_schedule/builder.h index 76883feda76c..5ac1fd1753f7 100644 --- a/include/tvm/meta_schedule/builder.h +++ b/include/tvm/meta_schedule/builder.h @@ -19,12 +19,12 @@ #ifndef TVM_META_SCHEDULE_BUILDER_H_ #define TVM_META_SCHEDULE_BUILDER_H_ +#include +#include +#include +#include #include #include -#include -#include -#include -#include #include #include #include @@ -66,7 +66,7 @@ class BuilderInput : public runtime::ObjectRef { * \param params Parameters for Relax build module. */ TVM_DLL explicit BuilderInput(IRModule mod, Target target, - Optional> params = NullOpt); + Optional> params = std::nullopt); TVM_DEFINE_NOTNULLABLE_OBJECT_REF_METHODS(BuilderInput, runtime::ObjectRef, BuilderInputNode); }; diff --git a/include/tvm/meta_schedule/cost_model.h b/include/tvm/meta_schedule/cost_model.h index 48a27340bff1..a3386df5e90e 100644 --- a/include/tvm/meta_schedule/cost_model.h +++ b/include/tvm/meta_schedule/cost_model.h @@ -20,12 +20,12 @@ #ifndef TVM_META_SCHEDULE_COST_MODEL_H_ #define TVM_META_SCHEDULE_COST_MODEL_H_ +#include +#include #include #include #include #include -#include -#include #include #include #include diff --git a/include/tvm/meta_schedule/database.h b/include/tvm/meta_schedule/database.h index 45c4a241e29d..15d92c4e3c2a 100644 --- a/include/tvm/meta_schedule/database.h +++ b/include/tvm/meta_schedule/database.h @@ -19,12 +19,12 @@ #ifndef TVM_META_SCHEDULE_DATABASE_H_ #define TVM_META_SCHEDULE_DATABASE_H_ +#include +#include #include #include #include #include -#include -#include #include #include #include @@ -238,7 +238,7 @@ class DatabaseNode : public runtime::Object { * \param mod The IRModule to be searched for. * \param target The target to be searched for. * \param workload_name The name of the workload to be searched for. - * \return The best record of the given workload; NullOpt if not found. + * \return The best record of the given workload; std::nullopt if not found. */ virtual Optional QueryTuningRecord(const IRModule& mod, const Target& target, const String& workload_name); @@ -247,7 +247,7 @@ class DatabaseNode : public runtime::Object { * \param mod The IRModule to be searched for. * \param target The target to be searched for. * \param workload_name The name of the workload to be searched for. - * \return The schedule in the best schedule of the given workload; NullOpt if not found. + * \return The schedule in the best schedule of the given workload; std::nullopt if not found. */ virtual Optional QuerySchedule(const IRModule& mod, const Target& target, const String& workload_name); @@ -256,7 +256,7 @@ class DatabaseNode : public runtime::Object { * \param mod The IRModule to be searched for. * \param target The target to be searched for. * \param workload_name The name of the workload to be searched for. - * \return The IRModule in the best IRModule of the given workload; NullOpt if not found. + * \return The IRModule in the best IRModule of the given workload; std::nullopt if not found. */ virtual Optional QueryIRModule(const IRModule& mod, const Target& target, const String& workload_name); @@ -330,7 +330,7 @@ class PyDatabaseNode : public DatabaseNode { * \param mod The IRModule to be searched for. * \param target The target to be searched for. * \param workload_name The name of the workload to be searched for. - * \return The best record of the given workload; NullOpt if not found. + * \return The best record of the given workload; std::nullopt if not found. */ using FQueryTuningRecord = ffi::TypedFunction(const IRModule&, const Target&, const String&)>; @@ -339,7 +339,7 @@ class PyDatabaseNode : public DatabaseNode { * \param mod The IRModule to be searched for. * \param target The target to be searched for. * \param workload_name The name of the workload to be searched for. - * \return The schedule in the best schedule of the given workload; NullOpt if not found. + * \return The schedule in the best schedule of the given workload; std::nullopt if not found. */ using FQuerySchedule = ffi::TypedFunction(const IRModule&, const Target&, const String&)>; @@ -348,7 +348,7 @@ class PyDatabaseNode : public DatabaseNode { * \param mod The IRModule to be searched for. * \param target The target to be searched for. * \param workload_name The name of the workload to be searched for. - * \return The IRModule in the best IRModule of the given workload; NullOpt if not found. + * \return The IRModule in the best IRModule of the given workload; std::nullopt if not found. */ using FQueryIRModule = ffi::TypedFunction(const IRModule&, const Target&, const String&)>; diff --git a/include/tvm/meta_schedule/extracted_task.h b/include/tvm/meta_schedule/extracted_task.h index 239bf0dc5777..cfc1f29e8efb 100644 --- a/include/tvm/meta_schedule/extracted_task.h +++ b/include/tvm/meta_schedule/extracted_task.h @@ -19,10 +19,10 @@ #ifndef TVM_META_SCHEDULE_EXTRACTED_TASK_H_ #define TVM_META_SCHEDULE_EXTRACTED_TASK_H_ +#include +#include #include #include -#include -#include #include #include diff --git a/include/tvm/meta_schedule/feature_extractor.h b/include/tvm/meta_schedule/feature_extractor.h index 3e01faccaf28..8eecb2e58245 100644 --- a/include/tvm/meta_schedule/feature_extractor.h +++ b/include/tvm/meta_schedule/feature_extractor.h @@ -20,10 +20,10 @@ #ifndef TVM_META_SCHEDULE_FEATURE_EXTRACTOR_H_ #define TVM_META_SCHEDULE_FEATURE_EXTRACTOR_H_ +#include +#include #include #include -#include -#include #include #include #include diff --git a/include/tvm/meta_schedule/measure_callback.h b/include/tvm/meta_schedule/measure_callback.h index 10356b6f5fb0..1b3bbb0f5c8a 100644 --- a/include/tvm/meta_schedule/measure_callback.h +++ b/include/tvm/meta_schedule/measure_callback.h @@ -20,14 +20,14 @@ #ifndef TVM_META_SCHEDULE_MEASURE_CALLBACK_H_ #define TVM_META_SCHEDULE_MEASURE_CALLBACK_H_ +#include +#include #include #include #include #include #include #include -#include -#include #include #include diff --git a/include/tvm/meta_schedule/measure_candidate.h b/include/tvm/meta_schedule/measure_candidate.h index f7257b56d206..9bfc9d0da954 100644 --- a/include/tvm/meta_schedule/measure_candidate.h +++ b/include/tvm/meta_schedule/measure_candidate.h @@ -20,9 +20,9 @@ #ifndef TVM_META_SCHEDULE_MEASURE_CANDIDATE_H_ #define TVM_META_SCHEDULE_MEASURE_CANDIDATE_H_ +#include #include #include -#include #include #include diff --git a/include/tvm/meta_schedule/mutator.h b/include/tvm/meta_schedule/mutator.h index f8bf69180db5..525c812f90d2 100644 --- a/include/tvm/meta_schedule/mutator.h +++ b/include/tvm/meta_schedule/mutator.h @@ -20,8 +20,8 @@ #ifndef TVM_META_SCHEDULE_MUTATOR_H_ #define TVM_META_SCHEDULE_MUTATOR_H_ +#include #include -#include #include #include #include diff --git a/include/tvm/meta_schedule/profiler.h b/include/tvm/meta_schedule/profiler.h index 91b7bfc45c09..b9905cf06fae 100644 --- a/include/tvm/meta_schedule/profiler.h +++ b/include/tvm/meta_schedule/profiler.h @@ -19,11 +19,11 @@ #ifndef TVM_META_SCHEDULE_PROFILER_H_ #define TVM_META_SCHEDULE_PROFILER_H_ +#include +#include +#include #include #include -#include -#include -#include #include #include #include diff --git a/include/tvm/meta_schedule/runner.h b/include/tvm/meta_schedule/runner.h index 0335f81cc16c..64974d16c6a6 100644 --- a/include/tvm/meta_schedule/runner.h +++ b/include/tvm/meta_schedule/runner.h @@ -19,12 +19,12 @@ #ifndef TVM_META_SCHEDULE_RUNNER_H_ #define TVM_META_SCHEDULE_RUNNER_H_ +#include +#include +#include #include #include #include -#include -#include -#include #include #include diff --git a/include/tvm/meta_schedule/schedule_rule.h b/include/tvm/meta_schedule/schedule_rule.h index 974254afc1b8..2d369656b026 100644 --- a/include/tvm/meta_schedule/schedule_rule.h +++ b/include/tvm/meta_schedule/schedule_rule.h @@ -20,12 +20,12 @@ #ifndef TVM_META_SCHEDULE_SCHEDULE_RULE_H_ #define TVM_META_SCHEDULE_SCHEDULE_RULE_H_ +#include +#include +#include +#include #include #include -#include -#include -#include -#include #include #include #include @@ -57,8 +57,7 @@ class ScheduleRuleNode : public runtime::Object { * \param block The specific block to apply the schedule rule. * \return The list of schedules generated by applying the schedule rule. */ - virtual runtime::Array Apply(const tir::Schedule& sch, - const tir::BlockRV& block) = 0; + virtual Array Apply(const tir::Schedule& sch, const tir::BlockRV& block) = 0; /*! * \brief Deep clone the schedule rule. @@ -141,13 +140,13 @@ class ScheduleRule : public runtime::ObjectRef { * - 'SSRSRS' on CPU * - 'SSSRRSRS' on GPU * \param tile_binds For each level of tiles, which thread axis it is bound to. Recommended: - * - NullOpt on CPU + * - std::nullopt on CPU * - [blockIdx.x, vthread.x, threadIdx.x] on GPU - * \param max_innermost_factor The maximum size of the innermost factor. NullOpt means no limit - * \param vector_load_lens The length of vector lane in vectorized cooperative fetching. - * NullOpt means disable vectorization - * \param reuse_read Data reuse configuration for reading. NullOpt means no reuse. - * \param reuse_write Data reuse configuration for writing. NullOpt means no reuse. + * \param max_innermost_factor The maximum size of the innermost factor. std::nullopt means no + * limit \param vector_load_lens The length of vector lane in vectorized cooperative fetching. + * std::nullopt means disable vectorization + * \param reuse_read Data reuse configuration for reading. std::nullopt means no reuse. + * \param reuse_write Data reuse configuration for writing. std::nullopt means no reuse. * \param filter_fn A function that can be passed to overwrite the default condition for applying * MultiLevelTiling to a block. Its signature must be (Schedule, BlockRV) -> bool. * This is useful if there is a need to apply MultiLevelTiling to an operation / block which is @@ -160,7 +159,7 @@ class ScheduleRule : public runtime::ObjectRef { Optional> vector_load_lens, // Optional> reuse_read, // Optional> reuse_write, - Optional filter_fn = NullOpt); + Optional filter_fn = std::nullopt); /*! * \brief Extension of MultiLevelTiling for auto-tensorization with a single intrinsic. @@ -170,13 +169,13 @@ class ScheduleRule : public runtime::ObjectRef { * - 'SSRSRS' on CPU * - 'SSSRRSRS' on GPU * \param tile_binds For each level of tiles, which thread axis it is bound to. Recommended: - * - NullOpt on CPU + * - std::nullopt on CPU * - [blockIdx.x, vthread.x, threadIdx.x] on GPU - * \param max_innermost_factor The maximum size of the innermost factor. NullOpt means no limit - * \param vector_load_lens The length of vector lane in vectorized cooperative fetching. - * NullOpt means disable vectorization - * \param reuse_read Data reuse configuration for reading. NullOpt means no reuse. - * \param reuse_write Data reuse configuration for writing. NullOpt means no reuse. + * \param max_innermost_factor The maximum size of the innermost factor. std::nullopt means no + * limit \param vector_load_lens The length of vector lane in vectorized cooperative fetching. + * std::nullopt means disable vectorization + * \param reuse_read Data reuse configuration for reading. std::nullopt means no reuse. + * \param reuse_write Data reuse configuration for writing. std::nullopt means no reuse. * \return The schedule rule created */ TVM_DLL static ScheduleRule MultiLevelTilingWithIntrin( @@ -196,11 +195,11 @@ class ScheduleRule : public runtime::ObjectRef { * - 'SSSRRSRS' on GPU * \param tile_binds For each level of tiles, which thread axis it is bound to. Recommended: * - [blockIdx.y, blockIdx.x, threadIdx.y] on GPU - * \param max_innermost_factor The maximum size of the innermost factor. NullOpt means no limit - * \param vector_load_lens The length of vector lane in vectorized cooperative fetching. - * NullOpt means disable vectorization - * \param reuse_read Data reuse configuration for reading. NullOpt means no reuse. - * \param reuse_write Data reuse configuration for writing. NullOpt means no reuse. + * \param max_innermost_factor The maximum size of the innermost factor. std::nullopt means no + * limit \param vector_load_lens The length of vector lane in vectorized cooperative fetching. + * std::nullopt means disable vectorization + * \param reuse_read Data reuse configuration for reading. std::nullopt means no reuse. + * \param reuse_write Data reuse configuration for writing. std::nullopt means no reuse. * \param use_software_pipeline Whether use the software pipeline. * \return The schedule rule created */ @@ -216,9 +215,9 @@ class ScheduleRule : public runtime::ObjectRef { * maximum vector length. * \param structure The tiling structure. 'SSRSRS' is recommended. * \param vector_length_in_bits The length of a vector register in bits. - * \param max_innermost_factor The maximum size of the innermost factor. NullOpt means no limit - * \param reuse_read Data reuse configuration for reading. NullOpt means no reuse. - * \param reuse_write Data reuse configuration for writing. NullOpt means no reuse. + * \param max_innermost_factor The maximum size of the innermost factor. std::nullopt means no + * limit \param reuse_read Data reuse configuration for reading. std::nullopt means no reuse. + * \param reuse_write Data reuse configuration for writing. std::nullopt means no reuse. * \return The schedule rule created */ TVM_DLL static ScheduleRule MultiLevelTilingWideVector( @@ -230,8 +229,8 @@ class ScheduleRule : public runtime::ObjectRef { * \param max_jobs_per_core The maximum number of jobs to be launched per CPU core. It sets the * uplimit of CPU parallelism, i.e. `num_cores * max_jobs_per_core`. Use -1 to disable * parallelism. - * \param max_innermost_factor The maximum size of the innermost factor. NullOpt means no limit - * \return The schedule rule created + * \param max_innermost_factor The maximum size of the innermost factor. std::nullopt means no + * limit \return The schedule rule created */ TVM_DLL static ScheduleRule AddRFactor(int max_jobs_per_core, // Optional max_innermost_factor); diff --git a/include/tvm/meta_schedule/search_strategy.h b/include/tvm/meta_schedule/search_strategy.h index ca7ee7ec8407..ed08f5729ec1 100644 --- a/include/tvm/meta_schedule/search_strategy.h +++ b/include/tvm/meta_schedule/search_strategy.h @@ -19,14 +19,14 @@ #ifndef TVM_META_SCHEDULE_SEARCH_STRATEGY_H_ #define TVM_META_SCHEDULE_SEARCH_STRATEGY_H_ +#include +#include #include #include #include #include #include #include -#include -#include #include #include #include diff --git a/include/tvm/meta_schedule/space_generator.h b/include/tvm/meta_schedule/space_generator.h index b626b3e7739f..efdca187ca46 100644 --- a/include/tvm/meta_schedule/space_generator.h +++ b/include/tvm/meta_schedule/space_generator.h @@ -19,12 +19,12 @@ #ifndef TVM_META_SCHEDULE_SPACE_GENERATOR_H_ #define TVM_META_SCHEDULE_SPACE_GENERATOR_H_ +#include #include #include #include #include #include -#include #include #include #include diff --git a/include/tvm/meta_schedule/task_scheduler.h b/include/tvm/meta_schedule/task_scheduler.h index e75059116dc2..8c0e35f6396f 100644 --- a/include/tvm/meta_schedule/task_scheduler.h +++ b/include/tvm/meta_schedule/task_scheduler.h @@ -19,14 +19,14 @@ #ifndef TVM_META_SCHEDULE_TASK_SCHEDULER_H_ #define TVM_META_SCHEDULE_TASK_SCHEDULER_H_ +#include +#include #include #include #include #include #include #include -#include -#include #include #include #include @@ -54,11 +54,11 @@ class TaskRecordNode : public runtime::Object { /*! \brief The latency of each run, in milliseconds. */ std::vector latency_ms = {}; /*! \brief The measure candidates. */ - Optional> measure_candidates = NullOpt; + Optional> measure_candidates = std::nullopt; /*! \brief The building results. */ - Optional> builder_results = NullOpt; + Optional> builder_results = std::nullopt; /*! \brief Packed functions to fetch the runner results asynchronously. */ - Optional> runner_futures = NullOpt; + Optional> runner_futures = std::nullopt; void VisitAttrs(tvm::AttrVisitor* v) { v->Visit("ctx", &ctx); diff --git a/include/tvm/meta_schedule/tune_context.h b/include/tvm/meta_schedule/tune_context.h index 9eacf499f405..24f06c9d5c53 100644 --- a/include/tvm/meta_schedule/tune_context.h +++ b/include/tvm/meta_schedule/tune_context.h @@ -19,6 +19,10 @@ #ifndef TVM_META_SCHEDULE_TUNE_CONTEXT_H_ #define TVM_META_SCHEDULE_TUNE_CONTEXT_H_ +#include +#include +#include +#include #include #include #include @@ -26,10 +30,6 @@ #include #include #include -#include -#include -#include -#include #include #include #include diff --git a/include/tvm/node/attr_registry_map.h b/include/tvm/node/attr_registry_map.h index 4e075c7e56da..37dc710ac161 100644 --- a/include/tvm/node/attr_registry_map.h +++ b/include/tvm/node/attr_registry_map.h @@ -23,7 +23,7 @@ #ifndef TVM_NODE_ATTR_REGISTRY_MAP_H_ #define TVM_NODE_ATTR_REGISTRY_MAP_H_ -#include +#include #include #include diff --git a/include/tvm/node/node.h b/include/tvm/node/node.h index 12598cb156c2..aebff220abbc 100644 --- a/include/tvm/node/node.h +++ b/include/tvm/node/node.h @@ -34,12 +34,12 @@ #ifndef TVM_NODE_NODE_H_ #define TVM_NODE_NODE_H_ +#include #include #include #include #include #include -#include #include #include @@ -60,7 +60,6 @@ using ffi::PackedArgs; using ffi::TypeIndex; using runtime::Downcast; using runtime::GetRef; -using runtime::make_object; } // namespace tvm #endif // TVM_NODE_NODE_H_ diff --git a/include/tvm/node/object_path.h b/include/tvm/node/object_path.h index b2bfa4f27379..9c17487a1d64 100644 --- a/include/tvm/node/object_path.h +++ b/include/tvm/node/object_path.h @@ -26,8 +26,8 @@ #ifndef TVM_NODE_OBJECT_PATH_H_ #define TVM_NODE_OBJECT_PATH_H_ -#include -#include +#include +#include #include #include @@ -122,7 +122,7 @@ class ObjectPathNode : public Object { class ObjectPath : public ObjectRef { public: /*! \brief Create a path that represents the root object itself. */ - static ObjectPath Root(Optional name = NullOpt); + static ObjectPath Root(Optional name = std::nullopt); TVM_DEFINE_NOTNULLABLE_OBJECT_REF_METHODS(ObjectPath, ObjectRef, ObjectPathNode); }; @@ -137,7 +137,7 @@ class RootPathNode final : public ObjectPathNode { public: Optional name; - explicit RootPathNode(Optional name = NullOpt); + explicit RootPathNode(Optional name = std::nullopt); static constexpr const char* _type_key = "RootPath"; TVM_DECLARE_FINAL_OBJECT_INFO(RootPathNode, ObjectPathNode); diff --git a/include/tvm/node/reflection.h b/include/tvm/node/reflection.h index 0938f2c56ad2..fb15ff4f81e5 100644 --- a/include/tvm/node/reflection.h +++ b/include/tvm/node/reflection.h @@ -23,12 +23,12 @@ #ifndef TVM_NODE_REFLECTION_H_ #define TVM_NODE_REFLECTION_H_ +#include +#include #include #include #include -#include #include -#include #include #include #include @@ -246,12 +246,12 @@ class ReflectionVTable::Registry { * struct StringObjTrait { * static constexpr const std::nullptr_t VisitAttrs = nullptr; * - * static void SHashReduce(const runtime::StringObj* key, SHashReducer hash_reduce) { - * hash_reduce->SHashReduceHashedValue(runtime::String::StableHashBytes(key->data, key->size)); + * static void SHashReduce(const StringObj* key, SHashReducer hash_reduce) { + * hash_reduce->SHashReduceHashedValue(String::StableHashBytes(key->data, key->size)); * } * - * static bool SEqualReduce(const runtime::StringObj* lhs, - * const runtime::StringObj* rhs, + * static bool SEqualReduce(const StringObj* lhs, + * const StringObj* rhs, * SEqualReducer equal) { * if (lhs == rhs) return true; * if (lhs->size != rhs->size) return false; @@ -260,7 +260,7 @@ class ReflectionVTable::Registry { * } * }; * - * TVM_REGISTER_REFLECTION_VTABLE(runtime::StringObj, StringObjTrait); + * TVM_REGISTER_REFLECTION_VTABLE(StringObj, StringObjTrait); * * \endcode * @@ -280,7 +280,7 @@ class ReflectionVTable::Registry { TVM_REGISTER_OBJECT_TYPE(TypeName); \ TVM_REGISTER_REFLECTION_VTABLE(TypeName, ::tvm::detail::ReflectionTrait) \ .set_creator([](const std::string&) -> ObjectPtr { \ - return ::tvm::runtime::make_object(); \ + return ::tvm::ffi::make_object(); \ }) // Implementation details diff --git a/include/tvm/node/script_printer.h b/include/tvm/node/script_printer.h index 9d2fa1023e92..5ee6b177f0f2 100644 --- a/include/tvm/node/script_printer.h +++ b/include/tvm/node/script_printer.h @@ -23,12 +23,12 @@ #ifndef TVM_NODE_SCRIPT_PRINTER_H_ #define TVM_NODE_SCRIPT_PRINTER_H_ +#include +#include +#include #include #include #include -#include -#include -#include #include #include @@ -168,7 +168,7 @@ class TVMScriptPrinter { }; #define TVM_OBJECT_ENABLE_SCRIPT_PRINTER() \ - std::string Script(const Optional& config = NullOpt) const { \ + std::string Script(const Optional& config = std::nullopt) const { \ return TVMScriptPrinter::Script(GetRef(this), config.value_or(PrinterConfig())); \ } diff --git a/include/tvm/node/structural_equal.h b/include/tvm/node/structural_equal.h index 7f56fd6ca961..372cbc52bcc8 100644 --- a/include/tvm/node/structural_equal.h +++ b/include/tvm/node/structural_equal.h @@ -23,9 +23,9 @@ #ifndef TVM_NODE_STRUCTURAL_EQUAL_H_ #define TVM_NODE_STRUCTURAL_EQUAL_H_ +#include #include #include -#include #include #include @@ -253,24 +253,26 @@ class SEqualReducer { * \return the immediate check result. */ bool operator()(const double& lhs, const double& rhs, - Optional paths = NullOpt) const; + Optional paths = std::nullopt) const; bool operator()(const int64_t& lhs, const int64_t& rhs, - Optional paths = NullOpt) const; + Optional paths = std::nullopt) const; bool operator()(const uint64_t& lhs, const uint64_t& rhs, - Optional paths = NullOpt) const; - bool operator()(const int& lhs, const int& rhs, Optional paths = NullOpt) const; - bool operator()(const bool& lhs, const bool& rhs, Optional paths = NullOpt) const; + Optional paths = std::nullopt) const; + bool operator()(const int& lhs, const int& rhs, + Optional paths = std::nullopt) const; + bool operator()(const bool& lhs, const bool& rhs, + Optional paths = std::nullopt) const; bool operator()(const std::string& lhs, const std::string& rhs, - Optional paths = NullOpt) const; + Optional paths = std::nullopt) const; bool operator()(const DataType& lhs, const DataType& rhs, - Optional paths = NullOpt) const; + Optional paths = std::nullopt) const; bool operator()(const Optional& lhs, const Optional& rhs, - Optional paths = NullOpt) const; + Optional paths = std::nullopt) const; bool operator()(const Optional& lhs, const Optional& rhs, - Optional paths = NullOpt) const; + Optional paths = std::nullopt) const; template ::value>::type> bool operator()(const ENum& lhs, const ENum& rhs, - Optional paths = NullOpt) const { + Optional paths = std::nullopt) const { using Underlying = typename std::underlying_type::type; static_assert(std::is_same::value, "Enum must have `int` as the underlying type"); @@ -327,7 +329,7 @@ class SEqualReducer { * \return the immediate check result. */ bool AnyEqual(const ffi::Any& lhs, const ffi::Any& rhs, - Optional paths = NullOpt) const; + Optional paths = std::nullopt) const; /*! * \brief Reduce condition to comparison of two definitions, @@ -401,7 +403,7 @@ class SEqualReducer { private: bool EnumAttrsEqual(int lhs, int rhs, const void* lhs_address, const void* rhs_address, - Optional paths = NullOpt) const; + Optional paths = std::nullopt) const; bool ObjectAttrsEqual(const ObjectRef& lhs, const ObjectRef& rhs, bool map_free_vars, const ObjectPathPair* paths) const; @@ -413,7 +415,7 @@ class SEqualReducer { template static bool CompareAttributeValues(const T& lhs, const T& rhs, const PathTracingData* tracing_data, - Optional paths = NullOpt); + Optional paths = std::nullopt); /*! \brief Internal class pointer. */ Handler* handler_ = nullptr; diff --git a/include/tvm/relax/analysis.h b/include/tvm/relax/analysis.h index 85a7d0eee356..267eb1b66eeb 100644 --- a/include/tvm/relax/analysis.h +++ b/include/tvm/relax/analysis.h @@ -536,7 +536,7 @@ TVM_DLL bool HasReshapePattern(const tir::PrimFunc& func); * the caller can pass the function's name so recursive calls * can be ignored in the check (must be a Var or GlobalVar). * \return The impure expression, if one exists within the given - * expression. Otherwise, NullOpt. + * expression. Otherwise, std::nullopt. * \note Relies on StructInfo annotations, so ensure that the module has been normalized first. * Also, an impure call in a *nested* function does *not* mean that the outer expression contains * an impure call--it only does if the nested function is *later called*. diff --git a/include/tvm/relax/block_builder.h b/include/tvm/relax/block_builder.h index 5efe91a5e437..c33d99b5f91f 100644 --- a/include/tvm/relax/block_builder.h +++ b/include/tvm/relax/block_builder.h @@ -126,7 +126,7 @@ class BlockBuilderNode : public Object { * \brief Lookup the binding value that var binds to in the current emitted sequences. * \param var The input var. * \return The Expr bound to the input \p var. - * \note For function parameters, this function returns NullOpt. + * \note For function parameters, this function returns std::nullopt. */ virtual Optional LookupBinding(const Var& var) = 0; diff --git a/include/tvm/relax/dataflow_matcher.h b/include/tvm/relax/dataflow_matcher.h index fd2fa72a2410..d5a0de049303 100644 --- a/include/tvm/relax/dataflow_matcher.h +++ b/include/tvm/relax/dataflow_matcher.h @@ -24,8 +24,8 @@ #ifndef TVM_RELAX_DATAFLOW_MATCHER_H_ #define TVM_RELAX_DATAFLOW_MATCHER_H_ +#include #include -#include #include #include @@ -44,11 +44,11 @@ namespace relax { * \return true if matched * \return false if unmatched */ -bool MatchExpr(DFPattern pattern, Expr expr, Optional> bindings = NullOpt); +bool MatchExpr(DFPattern pattern, Expr expr, Optional> bindings = std::nullopt); /* \brief Similar to above, but return pairs of a matching pattern and an expression. */ -Optional> ExtractMatchedExpr( - DFPattern pattern, Expr expr, Optional> bindings = NullOpt); +Optional> ExtractMatchedExpr(DFPattern pattern, Expr expr, + Optional> bindings = std::nullopt); /** * \brief Match a sub-graph in a DataflowBlock with a graph of patterns and return the mapping. diff --git a/include/tvm/relax/dataflow_pattern.h b/include/tvm/relax/dataflow_pattern.h index 36fac906c4de..987fe16207dc 100644 --- a/include/tvm/relax/dataflow_pattern.h +++ b/include/tvm/relax/dataflow_pattern.h @@ -24,11 +24,11 @@ #ifndef TVM_RELAX_DATAFLOW_PATTERN_H_ #define TVM_RELAX_DATAFLOW_PATTERN_H_ +#include +#include #include #include #include -#include -#include #include #include @@ -188,7 +188,7 @@ class DFConstraintNode : public Object { * \param match_state A function that can be called to check the * current state of the match. The function takes as argument a * pattern on which the constraint depends, and returns the relax - * variable matched by that pattern, or NullOpt if the pattern + * variable matched by that pattern, or std::nullopt if the pattern * has not yet been matched. * * \return A tuple of `PrimExpr` and `bool`. The first element is a @@ -946,11 +946,11 @@ ExprPattern IsExpr(const Expr& expr); ExprPattern IsOp(const String& op_name); /*! \brief Syntatic Sugar for call_tir (return a tensor) */ // Todo(relax-team): Dataflow pattern for StructInfo, and match out_sinfo -CallPattern IsCallTIR(const String& name, Optional args = NullOpt); +CallPattern IsCallTIR(const String& name, Optional args = std::nullopt); /*! \brief Syntatic Sugar for call_tir (return a tuple of tensor) */ CallPattern IsCallTIR(const String& name, TuplePattern var_args); /*! \brief Syntatic Sugar for call_dps_packed (return a tensor) */ -CallPattern IsCallDPSPacked(const String& name, Optional args = NullOpt); +CallPattern IsCallDPSPacked(const String& name, Optional args = std::nullopt); /*! \brief Syntatic Sugar for call_dps_packed (return a tuple of tensor) */ CallPattern IsCallDPSPacked(const String& name, TuplePattern var_args); /*! \brief Syntatic Sugar for creating TuplePattern or UnorderedTuplePattern (unordered=true) */ diff --git a/include/tvm/relax/distributed/global_info.h b/include/tvm/relax/distributed/global_info.h index 5ab5a0263591..67aeccd2970a 100644 --- a/include/tvm/relax/distributed/global_info.h +++ b/include/tvm/relax/distributed/global_info.h @@ -37,7 +37,7 @@ namespace distributed { class DeviceMeshNode : public GlobalInfoNode { public: /*! \brief logical shape of the mesh*/ - ShapeTuple shape; + ffi::Shape shape; /*! \brief device ids in the mesh*/ Array device_ids; @@ -80,8 +80,8 @@ class DeviceMeshNode : public GlobalInfoNode { */ class DeviceMesh : public GlobalInfo { public: - TVM_DLL DeviceMesh(ShapeTuple shape, Array device_ids); - TVM_DLL DeviceMesh(ShapeTuple shape, Range device_range); + TVM_DLL DeviceMesh(ffi::Shape shape, Array device_ids); + TVM_DLL DeviceMesh(ffi::Shape shape, Range device_range); TVM_DEFINE_OBJECT_REF_METHODS(DeviceMesh, GlobalInfo, DeviceMeshNode); }; diff --git a/include/tvm/relax/expr.h b/include/tvm/relax/expr.h index 330ff7e8dab0..08cbd1de538e 100644 --- a/include/tvm/relax/expr.h +++ b/include/tvm/relax/expr.h @@ -19,13 +19,13 @@ #ifndef TVM_RELAX_EXPR_H_ #define TVM_RELAX_EXPR_H_ +#include +#include #include #include #include #include #include -#include -#include #include #include #include @@ -520,7 +520,7 @@ class Constant : public LeafExpr { * \param span The source span of the expression. */ TVM_DLL explicit Constant(runtime::NDArray data, - Optional struct_info_annotation = NullOpt, + Optional struct_info_annotation = std::nullopt, Span span = Span()); TVM_DEFINE_OBJECT_REF_METHODS(Constant, LeafExpr, ConstantNode); @@ -1006,7 +1006,7 @@ class Function : public BaseFunc { * SeqExpr. * * \param ret_struct_info The StructInfo returned by the function. - * If NullOpt, will be inferred from the StructInfo of the + * If std::nullopt, will be inferred from the StructInfo of the * function's body. * * \param is_pure The purity of the function. diff --git a/include/tvm/relax/expr_functor.h b/include/tvm/relax/expr_functor.h index 96b5b20d1ef8..c77383bdbf3d 100644 --- a/include/tvm/relax/expr_functor.h +++ b/include/tvm/relax/expr_functor.h @@ -421,7 +421,7 @@ class ExprMutator : public ExprMutatorBase { public: using ExprMutatorBase::VisitExpr_; - ExprMutator(Optional mod = NullOpt) { builder_ = BlockBuilder::Create(mod); } + ExprMutator(Optional mod = std::nullopt) { builder_ = BlockBuilder::Create(mod); } Expr VisitExpr(const Expr& expr) override; Expr VisitExpr_(const VarNode* op) override; Expr VisitExpr_(const DataflowVarNode* op) override; @@ -502,7 +502,7 @@ class ExprMutator : public ExprMutatorBase { * * \note The body_expr must be an SeqExpr in the normal form. */ - Expr VisitWithNewScope(const Expr& body_expr, Optional> params = NullOpt); + Expr VisitWithNewScope(const Expr& body_expr, Optional> params = std::nullopt); /*! * \brief Rewrite the expr with a new scope, used in the branches of If. @@ -524,7 +524,7 @@ class ExprMutator : public ExprMutatorBase { * \brief Look up the value bound to a variable. * \param var The var to be looked up. * \return The value bound to the input \p var. - * \note For function parameters, this function returns NullOpt. + * \note For function parameters, this function returns std::nullopt. */ Optional LookupBinding(const Var& var); diff --git a/include/tvm/relax/nested_msg.h b/include/tvm/relax/nested_msg.h index 0ddcb271ab83..af2db582d604 100644 --- a/include/tvm/relax/nested_msg.h +++ b/include/tvm/relax/nested_msg.h @@ -28,10 +28,10 @@ #ifndef TVM_RELAX_NESTED_MSG_H_ #define TVM_RELAX_NESTED_MSG_H_ +#include +#include #include #include -#include -#include #include #include @@ -46,7 +46,7 @@ namespace relax { * message state in pass analysis so we can robustly handle message * passing with the presence of nested tuple types. * - * Under the hood, NestedMsg[T] = Union[T, NullOpt, Array[NestedMsg[T]]]. + * Under the hood, NestedMsg[T] = Union[T, std::nullopt, Array[NestedMsg[T]]]. * Each nested message corresponds to the same nesting structure as * the nested tuple types when we encounter them in analysis. * @@ -176,7 +176,7 @@ class NestedMsg : public ObjectRef { bool IsNull() const { return data_ == nullptr; } /*! \return Whether the nested message is nested */ - bool IsNested() const { return data_ != nullptr && data_->IsInstance(); } + bool IsNested() const { return data_ != nullptr && data_->IsInstance(); } /*! * \return The underlying leaf value. @@ -359,7 +359,7 @@ NestedMsg MapToNestedMsgBySInfo(Expr expr, FType fmapleaf) { template TargetType NestedMsgTo(NestedMsg msg, FMapLeaf fmapleaf, FCombine fcombine) { if (msg.IsNull()) { - return fmapleaf(NullOpt); + return fmapleaf(std::nullopt); } else if (msg.IsLeaf()) { return fmapleaf(msg.LeafValue()); } else { diff --git a/include/tvm/relax/struct_info.h b/include/tvm/relax/struct_info.h index 7c13fcc531a3..5c4e646351d3 100644 --- a/include/tvm/relax/struct_info.h +++ b/include/tvm/relax/struct_info.h @@ -164,7 +164,7 @@ class TensorStructInfoNode : public StructInfoNode { public: /*! * \brief optionally store the shape expression of the tensor. - * \note shape must be normalized: it can only be NullOpt or ShapeExpr or Var. + * \note shape must be normalized: it can only be std::nullopt or ShapeExpr or Var. */ Optional shape; /*! \brief The virtual device, indicates where the tensor @@ -231,7 +231,7 @@ class TensorStructInfo : public StructInfo { * * \note shape must already be normalized. */ - TVM_DLL TensorStructInfo(Expr shape, DataType dtype, Optional vdevice = NullOpt, + TVM_DLL TensorStructInfo(Expr shape, DataType dtype, Optional vdevice = std::nullopt, Span span = Span()); /*! @@ -241,7 +241,7 @@ class TensorStructInfo : public StructInfo { * \param vdevice The virtual device. * \param span The span of the AST. */ - TVM_DLL TensorStructInfo(DataType dtype, int ndim, Optional vdevice = NullOpt, + TVM_DLL TensorStructInfo(DataType dtype, int ndim, Optional vdevice = std::nullopt, Span span = Span()); TVM_DEFINE_OBJECT_REF_METHODS(TensorStructInfo, StructInfo, TensorStructInfoNode); @@ -304,7 +304,7 @@ class FuncStructInfoNode : public StructInfoNode { public: /*! * \brief The parameter struct info of the function. - * \note When params is NullOpt means the function can take arbitrary number of arguments. + * \note When params is std::nullopt means the function can take arbitrary number of arguments. * We define such functions as Opaque function. */ Optional> params; @@ -314,7 +314,7 @@ class FuncStructInfoNode : public StructInfoNode { StructInfo ret; /*! * \brief Derivation function of opaque functions that may take any number of parameters. - * \note When derive_func is not empty, then params should be NullOpt, + * \note When derive_func is not empty, then params should be std::nullopt, * ret should be ObjectStructInfo() */ Optional derive_func; @@ -418,7 +418,7 @@ inline Optional MatchStructInfo(const Expr& expr) { if (const TNode* ptr = expr->struct_info_.as()) { return GetRef(ptr); } else { - return NullOpt; + return std::nullopt; } } diff --git a/include/tvm/relax/transform.h b/include/tvm/relax/transform.h index 98aa2673c23b..b8ff0fa59dfe 100644 --- a/include/tvm/relax/transform.h +++ b/include/tvm/relax/transform.h @@ -206,13 +206,13 @@ TVM_DLL Pass BindParams(String func_name, Map params); * symbolic variable in each function where it is used. * * \param func_name The name of the function in which to bind shape - * values. If NullOpt, all functions in the module will be + * values. If std::nullopt, all functions in the module will be * updated. * * \return The Pass. */ TVM_DLL Pass BindSymbolicVars(Map binding_map, - Optional func_name = NullOpt); + Optional func_name = std::nullopt); /*! * \brief Fold constant expressions within dataflow blocks. @@ -378,7 +378,7 @@ class FusionPatternNode : public Object { /*! * \brief The function to determine whether the match result is accepted. This can be - * NullOpt if check function is not necessary for this pattern. + * std::nullopt if check function is not necessary for this pattern. * * It should have signature * bool(const PatternCheckContext& context) @@ -411,7 +411,7 @@ class FusionPattern : public ObjectRef { Optional check, Optional attrs_getter); FusionPattern(String name, DFPattern pattern) - : FusionPattern(name, pattern, {}, NullOpt, NullOpt) {} + : FusionPattern(name, pattern, {}, std::nullopt, std::nullopt) {} TVM_DEFINE_NOTNULLABLE_OBJECT_REF_METHODS(FusionPattern, ObjectRef, FusionPatternNode); }; @@ -497,7 +497,7 @@ class PatternCheckContext : public ObjectRef { * * \note ConvertToDataflow may need to be called first to provide dataflow blocks. */ -TVM_DLL Pass Gradient(String func_name, Optional> require_grads = NullOpt, +TVM_DLL Pass Gradient(String func_name, Optional> require_grads = std::nullopt, int target_index = 0); /*! @@ -548,7 +548,7 @@ TVM_DLL Pass FuseTIR(); * \return The Pass. */ TVM_DLL Pass RunCodegen(Optional>> target_options, - Array entry_functions); + Array entry_functions); /*! * \brief Decompose composite operators during inference. For example, The result of batch norm (a @@ -622,7 +622,7 @@ TVM_DLL Pass ConvertToDataflow(int min_size = 2); * * \return The Pass. */ -TVM_DLL Pass DeadCodeElimination(Array entry_functions = {}); +TVM_DLL Pass DeadCodeElimination(Array entry_functions = {}); /*! * \brief Pass that changes calls to operators that can be done in-place @@ -646,7 +646,7 @@ TVM_DLL Pass DataflowUseInplaceCalls(); * \note Mainly operates within dataflow blocks. ConvertToDataflow may need to be called first. */ TVM_DLL Pass ToMixedPrecision(const DataType& out_dtype, - Optional> fp16_input_names = NullOpt); + Optional> fp16_input_names = std::nullopt); /*! * \brief Rewrite a Relax module for executing with CUDA graph. This pass identifies diff --git a/include/tvm/runtime/container/array.h b/include/tvm/runtime/container/array.h deleted file mode 100644 index 7d8de1c23423..000000000000 --- a/include/tvm/runtime/container/array.h +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -/*! - * \file tvm/runtime/container/string.h - * \brief Runtime String container types. - */ -#ifndef TVM_RUNTIME_CONTAINER_ARRAY_H_ -#define TVM_RUNTIME_CONTAINER_ARRAY_H_ - -#include - -namespace tvm { -namespace runtime { - -using tvm::ffi::Array; -using tvm::ffi::ArrayObj; - -} // namespace runtime - -// expose class to root namespace -using tvm::ffi::Array; -using tvm::ffi::ArrayObj; -} // namespace tvm -#endif // TVM_RUNTIME_CONTAINER_ARRAY_H_ diff --git a/include/tvm/runtime/container/base.h b/include/tvm/runtime/container/base.h deleted file mode 100644 index b0295761f6a3..000000000000 --- a/include/tvm/runtime/container/base.h +++ /dev/null @@ -1,278 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -/*! - * \file tvm/runtime/container/base.h - * \brief Base utilities for common POD(plain old data) container types. - */ -#ifndef TVM_RUNTIME_CONTAINER_BASE_H_ -#define TVM_RUNTIME_CONTAINER_BASE_H_ - -#include -#include -#include - -#include -#include -#include - -namespace tvm { -namespace runtime { - -/*! - * \brief Base template for classes with array like memory layout. - * - * It provides general methods to access the memory. The memory - * layout is ArrayType + [ElemType]. The alignment of ArrayType - * and ElemType is handled by the memory allocator. - * - * \tparam ArrayType The array header type, contains object specific metadata. - * \tparam ElemType The type of objects stored in the array right after - * ArrayType. - * - * \code - * // Example usage of the template to define a simple array wrapper - * class ArrayObj : public InplaceArrayBase { - * public: - * // Wrap EmplaceInit to initialize the elements - * template - * void Init(Iterator begin, Iterator end) { - * size_t num_elems = std::distance(begin, end); - * auto it = begin; - * this->size = 0; - * for (size_t i = 0; i < num_elems; ++i) { - * InplaceArrayBase::EmplaceInit(i, *it++); - * this->size++; - * } - * } - * } - * - * void test_function() { - * vector fields; - * auto ptr = make_inplace_array_object(fields.size()); - * ptr->Init(fields.begin(), fields.end()); - * - * // Access the 0th element in the array. - * assert(ptr->operator[](0) == fields[0]); - * } - * - * \endcode - */ -template -class InplaceArrayBase { - public: - /*! - * \brief Access element at index - * \param idx The index of the element. - * \return Const reference to ElemType at the index. - */ - const ElemType& operator[](size_t idx) const { - size_t size = Self()->GetSize(); - ICHECK_LT(idx, size) << "Index " << idx << " out of bounds " << size << "\n"; - return *(reinterpret_cast(AddressOf(idx))); - } - - /*! - * \brief Access element at index - * \param idx The index of the element. - * \return Reference to ElemType at the index. - */ - ElemType& operator[](size_t idx) { - size_t size = Self()->GetSize(); - ICHECK_LT(idx, size) << "Index " << idx << " out of bounds " << size << "\n"; - return *(reinterpret_cast(AddressOf(idx))); - } - - /*! - * \brief Destroy the Inplace Array Base object - */ - ~InplaceArrayBase() { - if (!(std::is_standard_layout::value && std::is_trivial::value)) { - size_t size = Self()->GetSize(); - for (size_t i = 0; i < size; ++i) { - ElemType* fp = reinterpret_cast(AddressOf(i)); - fp->ElemType::~ElemType(); - } - } - } - - protected: - /*! - * \brief Construct a value in place with the arguments. - * - * \tparam Args Type parameters of the arguments. - * \param idx Index of the element. - * \param args Arguments to construct the new value. - * - * \note Please make sure ArrayType::GetSize returns 0 before first call of - * EmplaceInit, and increment GetSize by 1 each time EmplaceInit succeeds. - */ - template - void EmplaceInit(size_t idx, Args&&... args) { - void* field_ptr = AddressOf(idx); - new (field_ptr) ElemType(std::forward(args)...); - } - - /*! - * \brief Return the self object for the array. - * - * \return Pointer to ArrayType. - */ - inline ArrayType* Self() const { - return static_cast(const_cast(this)); - } - - /*! - * \brief Return the raw pointer to the element at idx. - * - * \param idx The index of the element. - * \return Raw pointer to the element. - */ - void* AddressOf(size_t idx) const { - static_assert( - alignof(ArrayType) % alignof(ElemType) == 0 && sizeof(ArrayType) % alignof(ElemType) == 0, - "The size and alignment of ArrayType should respect " - "ElemType's alignment."); - - size_t kDataStart = sizeof(ArrayType); - ArrayType* self = Self(); - char* data_start = reinterpret_cast(self) + kDataStart; - return data_start + idx * sizeof(ElemType); - } -}; - -/*! - * \brief iterator adapter that adapts TIter to return another type. - * \tparam Converter a struct that contains converting function - * \tparam TIter the content iterator type. - */ -template -class IterAdapter { - public: - using difference_type = typename std::iterator_traits::difference_type; - using value_type = typename Converter::ResultType; - using pointer = typename Converter::ResultType*; - using reference = typename Converter::ResultType&; - using iterator_category = typename std::iterator_traits::iterator_category; - - explicit IterAdapter(TIter iter) : iter_(iter) {} - IterAdapter& operator++() { - ++iter_; - return *this; - } - IterAdapter& operator--() { - --iter_; - return *this; - } - IterAdapter operator++(int) { - IterAdapter copy = *this; - ++iter_; - return copy; - } - IterAdapter operator--(int) { - IterAdapter copy = *this; - --iter_; - return copy; - } - - IterAdapter operator+(difference_type offset) const { return IterAdapter(iter_ + offset); } - - IterAdapter operator-(difference_type offset) const { return IterAdapter(iter_ - offset); } - - template - typename std::enable_if::value, - typename T::difference_type>::type inline - operator-(const IterAdapter& rhs) const { - return iter_ - rhs.iter_; - } - - bool operator==(IterAdapter other) const { return iter_ == other.iter_; } - bool operator!=(IterAdapter other) const { return !(*this == other); } - const value_type operator*() const { return Converter::convert(*iter_); } - - private: - TIter iter_; -}; - -/*! - * \brief iterator adapter that adapts TIter to return another type. - * \tparam Converter a struct that contains converting function - * \tparam TIter the content iterator type. - */ -template -class ReverseIterAdapter { - public: - using difference_type = typename std::iterator_traits::difference_type; - using value_type = typename Converter::ResultType; - using pointer = typename Converter::ResultType*; - using reference = typename Converter::ResultType&; // NOLINT(*) - using iterator_category = typename std::iterator_traits::iterator_category; - - explicit ReverseIterAdapter(TIter iter) : iter_(iter) {} - ReverseIterAdapter& operator++() { - --iter_; - return *this; - } - ReverseIterAdapter& operator--() { - ++iter_; - return *this; - } - ReverseIterAdapter operator++(int) { - ReverseIterAdapter copy = *this; - --iter_; - return copy; - } - ReverseIterAdapter operator--(int) { - ReverseIterAdapter copy = *this; - ++iter_; - return copy; - } - ReverseIterAdapter operator+(difference_type offset) const { - return ReverseIterAdapter(iter_ - offset); - } - - template - typename std::enable_if::value, - typename T::difference_type>::type inline - operator-(const ReverseIterAdapter& rhs) const { - return rhs.iter_ - iter_; - } - - bool operator==(ReverseIterAdapter other) const { return iter_ == other.iter_; } - bool operator!=(ReverseIterAdapter other) const { return !(*this == other); } - const value_type operator*() const { return Converter::convert(*iter_); } - - private: - TIter iter_; -}; - -} // namespace runtime - -// expose the functions to the root namespace. -using runtime::Downcast; -using runtime::IterAdapter; -using runtime::make_object; -using runtime::Object; -using runtime::ObjectPtr; -using runtime::ObjectPtrEqual; -using runtime::ObjectPtrHash; -using runtime::ObjectRef; -} // namespace tvm - -#endif // TVM_RUNTIME_CONTAINER_BASE_H_ diff --git a/include/tvm/runtime/container/map.h b/include/tvm/runtime/container/map.h deleted file mode 100644 index cd63cc94ada0..000000000000 --- a/include/tvm/runtime/container/map.h +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -/*! - * \file tvm/runtime/container/map.h - * \brief Runtime Map container types. - */ -#ifndef TVM_RUNTIME_CONTAINER_MAP_H_ -#define TVM_RUNTIME_CONTAINER_MAP_H_ - -#include - -namespace tvm { -namespace runtime { - -using tvm::ffi::Map; - -} // namespace runtime - -// expose the functions to the root namespace. -using tvm::ffi::Map; -using tvm::ffi::MapObj; -} // namespace tvm -#endif // TVM_RUNTIME_CONTAINER_MAP_H_ diff --git a/include/tvm/runtime/container/optional.h b/include/tvm/runtime/container/optional.h deleted file mode 100644 index 4dc3b680de7a..000000000000 --- a/include/tvm/runtime/container/optional.h +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -/*! - * \file tvm/runtime/container/string.h - * \brief Runtime String container types. - */ -#ifndef TVM_RUNTIME_CONTAINER_OPTIONAL_H_ -#define TVM_RUNTIME_CONTAINER_OPTIONAL_H_ - -#include - -namespace tvm { -namespace runtime { - -using tvm::ffi::Optional; -} // namespace runtime - -// expose class to root namespace -using tvm::ffi::Optional; -constexpr inline auto NullOpt = std::nullopt; -} // namespace tvm -#endif // TVM_RUNTIME_CONTAINER_OPTIONAL_H_ diff --git a/include/tvm/runtime/container/shape_tuple.h b/include/tvm/runtime/container/shape_tuple.h deleted file mode 100644 index c7a96b6623a6..000000000000 --- a/include/tvm/runtime/container/shape_tuple.h +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -/*! - * \file tvm/runtime/container/shape_tuple.h - * \brief Runtime ShapeTuple container types. - */ -#ifndef TVM_RUNTIME_CONTAINER_SHAPE_TUPLE_H_ -#define TVM_RUNTIME_CONTAINER_SHAPE_TUPLE_H_ - -#include - -#include -#include -#include - -#include "./base.h" - -namespace tvm { -namespace runtime { - -using Shape = tvm::ffi::Shape; -using ShapeTuple = tvm::ffi::Shape; -using ShapeTupleObj = tvm::ffi::ShapeObj; -using IntTuple = ShapeTuple; -using IntTupleObj = ShapeTupleObj; - -} // namespace runtime - -// expose the functions to the root namespace. -using runtime::IntTuple; -using runtime::IntTupleObj; -using runtime::ShapeTuple; -using runtime::ShapeTupleObj; -} // namespace tvm - -#endif // TVM_RUNTIME_CONTAINER_SHAPE_TUPLE_H_ diff --git a/include/tvm/runtime/container/string.h b/include/tvm/runtime/container/string.h deleted file mode 100644 index d55d9dbd7960..000000000000 --- a/include/tvm/runtime/container/string.h +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -/*! - * \file tvm/runtime/container/string.h - * \brief Runtime String container types. - */ -#ifndef TVM_RUNTIME_CONTAINER_STRING_H_ -#define TVM_RUNTIME_CONTAINER_STRING_H_ - -#include - -namespace tvm { -namespace runtime { - -using tvm::ffi::String; -using tvm::ffi::StringObj; - -} // namespace runtime - -using tvm::ffi::String; -using tvm::ffi::StringObj; - -} // namespace tvm -#endif // TVM_RUNTIME_CONTAINER_STRING_H_ diff --git a/include/tvm/runtime/container/variant.h b/include/tvm/runtime/container/variant.h deleted file mode 100644 index 9ba9a987115b..000000000000 --- a/include/tvm/runtime/container/variant.h +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -/*! - * \file tvm/runtime/container/variant.h - * \brief Runtime variant container. - */ -#ifndef TVM_RUNTIME_CONTAINER_VARIANT_H_ -#define TVM_RUNTIME_CONTAINER_VARIANT_H_ - -#include - -namespace tvm { -namespace runtime { - -using tvm::ffi::Variant; - -} // namespace runtime - -// expose class to root namespace -using tvm::ffi::Variant; -} // namespace tvm -#endif // TVM_RUNTIME_CONTAINER_VARIANT_H_ diff --git a/include/tvm/runtime/contrib/papi.h b/include/tvm/runtime/contrib/papi.h index ff2d75c483eb..93c1aa274bfd 100644 --- a/include/tvm/runtime/contrib/papi.h +++ b/include/tvm/runtime/contrib/papi.h @@ -22,8 +22,8 @@ #ifndef TVM_RUNTIME_CONTRIB_PAPI_H_ #define TVM_RUNTIME_CONTRIB_PAPI_H_ -#include -#include +#include +#include #include namespace tvm { diff --git a/include/tvm/runtime/disco/builtin.h b/include/tvm/runtime/disco/builtin.h index 4453d9737f89..93bf0084db87 100644 --- a/include/tvm/runtime/disco/builtin.h +++ b/include/tvm/runtime/disco/builtin.h @@ -70,7 +70,7 @@ TVM_DLL Module LoadVMModule(std::string path, Device device); * \param device The device the NDArray is created on. If None, use the thread local default device * \return The NDArray created */ -TVM_DLL NDArray DiscoEmptyNDArray(ShapeTuple shape, DataType dtype, Device device); +TVM_DLL NDArray DiscoEmptyNDArray(ffi::Shape shape, DataType dtype, Device device); /*! * \brief Perform an allreduce operation using the underlying communication library * \param send The array send to perform allreduce on diff --git a/include/tvm/runtime/disco/session.h b/include/tvm/runtime/disco/session.h index fb21f79882ad..9d213312c88c 100644 --- a/include/tvm/runtime/disco/session.h +++ b/include/tvm/runtime/disco/session.h @@ -72,7 +72,7 @@ #ifndef TVM_RUNTIME_DISCO_SESSION_H_ #define TVM_RUNTIME_DISCO_SESSION_H_ -#include +#include #include #include diff --git a/include/tvm/runtime/memory.h b/include/tvm/runtime/int_tuple.h similarity index 73% rename from include/tvm/runtime/memory.h rename to include/tvm/runtime/int_tuple.h index 96ca0c8d696a..032e8b9a328e 100644 --- a/include/tvm/runtime/memory.h +++ b/include/tvm/runtime/int_tuple.h @@ -16,22 +16,23 @@ * specific language governing permissions and limitations * under the License. */ + /*! - * \file tvm/runtime/object.h - * \brief A managed object in the TVM runtime. + * \file int_tuple.h + * \brief Defines tuple of integers. */ -#ifndef TVM_RUNTIME_MEMORY_H_ -#define TVM_RUNTIME_MEMORY_H_ +#ifndef TVM_RUNTIME_INT_TUPLE_H_ +#define TVM_RUNTIME_INT_TUPLE_H_ -#include +#include namespace tvm { namespace runtime { -using tvm::ffi::FObjectDeleter; -using tvm::ffi::make_inplace_array_object; -using tvm::ffi::make_object; +// We simply redirects to ffi::Shape, and ffi::ShapeObj +using IntTuple = ffi::Shape; +using IntTupleObj = ffi::ShapeObj; } // namespace runtime } // namespace tvm -#endif // TVM_RUNTIME_MEMORY_H_ +#endif // TVM_RUNTIME_INT_TUPLE_H_ diff --git a/include/tvm/runtime/memory/memory_manager.h b/include/tvm/runtime/memory/memory_manager.h index 537beeb8fa9d..7b19cdb1cea4 100644 --- a/include/tvm/runtime/memory/memory_manager.h +++ b/include/tvm/runtime/memory/memory_manager.h @@ -66,8 +66,8 @@ class Allocator { * \param mem_scope The device memory scope hint. * \return The empty NDArray. */ - TVM_DLL NDArray Empty(ShapeTuple shape, DLDataType dtype, Device dev, - Optional mem_scope = NullOpt); + TVM_DLL NDArray Empty(ffi::Shape shape, DLDataType dtype, Device dev, + Optional mem_scope = std::nullopt); /*! \brief Return the allocator type. */ inline AllocatorType type() const { return type_; } /*! \brief Allocate a buffer given a size, alignment and type. @@ -86,7 +86,7 @@ class Allocator { * \param mem_scope A memory scope of the buffer. * \return A sized allocation in the form of a buffer. */ - TVM_DLL virtual Buffer Alloc(Device dev, ShapeTuple shape, DLDataType type_hint, + TVM_DLL virtual Buffer Alloc(Device dev, ffi::Shape shape, DLDataType type_hint, const std::string& mem_scope = ""); /*! \brief Create a view for the buffer given a shape, type and scope. @@ -96,7 +96,7 @@ class Allocator { * \param mem_scope A memory scope of the view. * \return A device pointer to the created view. */ - TVM_DLL virtual void* CreateView(const Buffer& buffer, ShapeTuple shape, DLDataType type_hint, + TVM_DLL virtual void* CreateView(const Buffer& buffer, ffi::Shape shape, DLDataType type_hint, const std::string& mem_scope = "global") { return buffer.data; } @@ -164,10 +164,10 @@ class StorageObj : public Object { Allocator* allocator = nullptr; /*! \brief Allocate an NDArray from a given piece of storage. */ - TVM_DLL NDArray AllocNDArray(int64_t offset, ShapeTuple shape, DLDataType dtype); + TVM_DLL NDArray AllocNDArray(int64_t offset, ffi::Shape shape, DLDataType dtype); /*! \brief Allocate an NDArray with memory scope from a given piece of storage. */ - TVM_DLL NDArray AllocNDArrayScoped(int64_t offset, ShapeTuple shape, DLDataType dtype, + TVM_DLL NDArray AllocNDArrayScoped(int64_t offset, ffi::Shape shape, DLDataType dtype, String scope = "global"); ~StorageObj() { diff --git a/include/tvm/runtime/module.h b/include/tvm/runtime/module.h index 37ab906dd422..a4b192db8c1c 100644 --- a/include/tvm/runtime/module.h +++ b/include/tvm/runtime/module.h @@ -28,9 +28,9 @@ #include #include +#include +#include #include -#include -#include #include #include @@ -133,7 +133,7 @@ class Module : public ObjectRef { * // instace of MyModuleNode. * Module CreateMyModule() { * ObjectPtr n = - * tvm::runtime::make_object(); + * tvm::ffi::make_object(); * return Module(n); * } * diff --git a/include/tvm/runtime/ndarray.h b/include/tvm/runtime/ndarray.h index 82c9b229ab90..2b36306e5963 100644 --- a/include/tvm/runtime/ndarray.h +++ b/include/tvm/runtime/ndarray.h @@ -25,10 +25,10 @@ #define TVM_RUNTIME_NDARRAY_H_ #include +#include +#include +#include #include -#include -#include -#include #include #include #include @@ -62,7 +62,7 @@ class NDArray : public tvm::ffi::NDArray { NDArray(ffi::NDArray&& other) : tvm::ffi::NDArray(std::move(other)) {} // NOLINT(*) NDArray(const ffi::NDArray& other) : tvm::ffi::NDArray(other) {} // NOLINT(*) - ShapeTuple Shape() const { return this->shape(); } + ffi::Shape Shape() const { return this->shape(); } runtime::DataType DataType() const { return runtime::DataType(this->dtype()); } // DLPack handling @@ -112,7 +112,7 @@ class NDArray : public tvm::ffi::NDArray { * \return The array under another device. * \note The copy always triggers a TVMSynchronize. */ - TVM_DLL NDArray CopyTo(const Device& dev, Optional mem_scope = NullOpt) const; + TVM_DLL NDArray CopyTo(const Device& dev, Optional mem_scope = std::nullopt) const; /*! * \brief Load NDArray from stream * \param stream The input data stream @@ -145,7 +145,7 @@ class NDArray : public tvm::ffi::NDArray { * outside the bounds of the current array, this function will * raise an exception. */ - TVM_DLL NDArray CreateView(ShapeTuple shape, DLDataType dtype, + TVM_DLL NDArray CreateView(ffi::Shape shape, DLDataType dtype, uint64_t relative_byte_offset = 0) const; /*! * \brief Create an empty NDArray. @@ -155,8 +155,8 @@ class NDArray : public tvm::ffi::NDArray { * \param mem_scope The memory scope of the array. * \return The created Array */ - TVM_DLL static NDArray Empty(ShapeTuple shape, DLDataType dtype, Device dev, - Optional mem_scope = NullOpt); + TVM_DLL static NDArray Empty(ffi::Shape shape, DLDataType dtype, Device dev, + Optional mem_scope = std::nullopt); /*! * \brief Function to copy data from one array to another. * \param from The source array. @@ -301,7 +301,7 @@ inline bool NDArray::Load(dmlc::Stream* strm) { if (ndim != 0) { ICHECK(strm->ReadArray(&shape[0], ndim)) << "Invalid DLTensor file format"; } - NDArray ret = NDArray::Empty(ShapeTuple(shape), dtype, dev); + NDArray ret = NDArray::Empty(ffi::Shape(shape), dtype, dev); int64_t num_elems = 1; int elem_bytes = (ret->dtype.bits + 7) / 8; for (int i = 0; i < ret->ndim; ++i) { diff --git a/include/tvm/runtime/object.h b/include/tvm/runtime/object.h index 1c4dfb39e247..c686b54d096a 100644 --- a/include/tvm/runtime/object.h +++ b/include/tvm/runtime/object.h @@ -25,8 +25,8 @@ #include #include +#include #include -#include #include @@ -55,10 +55,11 @@ enum TypeIndex : int32_t { kRuntimeModule = TVMFFITypeIndex::kTVMFFIModule, /*! \brief runtime::NDArray. */ kRuntimeNDArray = TVMFFITypeIndex::kTVMFFINDArray, - /*! \brief runtime::ShapeTuple. */ - kRuntimeShapeTuple = TVMFFITypeIndex::kTVMFFIShape, + /*! \brief runtime::Shape. */ + kRuntimeShape = TVMFFITypeIndex::kTVMFFIShape, // Extra builtin static index here - kCustomStaticIndex = TVMFFITypeIndex::kTVMFFIStaticObjectEnd, + // We reserve 16 extra static indices for custom types + kCustomStaticIndex = TVMFFITypeIndex::kTVMFFIDynObjectBegin - 16, /*! \brief ffi::Function. */ kRuntimePackedFunc = kCustomStaticIndex + 1, /*! \brief runtime::DRef for disco distributed runtime */ @@ -73,6 +74,10 @@ enum TypeIndex : int32_t { kStaticIndexEnd, }; +static_assert(static_cast(TypeIndex::kCustomStaticIndex) >= + static_cast(TVMFFITypeIndex::kTVMFFIStaticObjectEnd), + "Static slot overflows to custom indices"); + /* * \brief Define the default copy/move constructor and assign operator * \param TypeName The class typename. diff --git a/include/tvm/runtime/profiling.h b/include/tvm/runtime/profiling.h index 9d6623d9ad95..63814a637592 100644 --- a/include/tvm/runtime/profiling.h +++ b/include/tvm/runtime/profiling.h @@ -24,9 +24,9 @@ #ifndef TVM_RUNTIME_PROFILING_H_ #define TVM_RUNTIME_PROFILING_H_ +#include +#include #include -#include -#include #include #include #include diff --git a/include/tvm/runtime/registry.h b/include/tvm/runtime/registry.h index c5c124dd6fb8..94463dc7255f 100644 --- a/include/tvm/runtime/registry.h +++ b/include/tvm/runtime/registry.h @@ -24,7 +24,7 @@ #ifndef TVM_RUNTIME_REGISTRY_H_ #define TVM_RUNTIME_REGISTRY_H_ -#include +#include #include #include diff --git a/include/tvm/runtime/relax_vm/ndarray_cache_support.h b/include/tvm/runtime/relax_vm/ndarray_cache_support.h index cf428b62a1f3..f595d81ffe7e 100644 --- a/include/tvm/runtime/relax_vm/ndarray_cache_support.h +++ b/include/tvm/runtime/relax_vm/ndarray_cache_support.h @@ -19,7 +19,7 @@ #ifndef TVM_RUNTIME_RELAX_VM_NDARRAY_CACHE_SUPPORT_H_ #define TVM_RUNTIME_RELAX_VM_NDARRAY_CACHE_SUPPORT_H_ -#include +#include #include #include @@ -52,7 +52,7 @@ struct NDArrayCacheMetadata { /*! \brief Name of the parameter */ std::string name; /*! \brief Shape of the parameter */ - ShapeTuple shape; + ffi::Shape shape; /*! \brief Data type of the parameter */ DataType dtype; /*! \brief Format of the parameter */ diff --git a/include/tvm/script/ir_builder/base.h b/include/tvm/script/ir_builder/base.h index e50c67a37664..85d6dcce5e1b 100644 --- a/include/tvm/script/ir_builder/base.h +++ b/include/tvm/script/ir_builder/base.h @@ -154,7 +154,7 @@ class IRBuilderFrame : public runtime::ObjectRef { class IRBuilderNode : public runtime::Object { public: /*! \brief A stack of context frames in the IRBuilder */ - runtime::Array frames; + Array frames; /*! \brief The outcome of IR construction */ Optional result; @@ -170,7 +170,7 @@ class IRBuilderNode : public runtime::Object { /*! * \brief Find a frame of the given type in the stack `this->frames` from top to bottom. * \tparam T The type of the frame to find. - * \return The frame if found, otherwise NullOpt. + * \return The frame if found, otherwise std::nullopt. */ template inline Optional FindFrame() const; @@ -178,7 +178,7 @@ class IRBuilderNode : public runtime::Object { * \brief Get the frame on top of the stack `this->frames` if its type is `TFrame`. * \tparam TFrame The assumed type of the last frame on stack. * \return The frame if the stack is non-empty and the top of the stack is of type `TFrame`. - * Otherwise NullOpt. + * Otherwise std::nullopt. */ template inline Optional GetLastFrame() const; @@ -274,7 +274,7 @@ inline Optional IRBuilderNode::FindFrame() const { return GetRef(p); } } - return NullOpt; + return std::nullopt; } template @@ -283,7 +283,7 @@ inline Optional IRBuilderNode::GetLastFrame() const { if (!frames.empty() && frames.back()->IsInstance()) { return Downcast(frames.back()); } - return NullOpt; + return std::nullopt; } template diff --git a/include/tvm/script/ir_builder/relax/frame.h b/include/tvm/script/ir_builder/relax/frame.h index 47c058d76a83..98a51fcb7829 100644 --- a/include/tvm/script/ir_builder/relax/frame.h +++ b/include/tvm/script/ir_builder/relax/frame.h @@ -54,7 +54,7 @@ class SeqExprFrameNode : public RelaxFrameNode { public: /*! \brief The binding blocks inside the frame. */ Array binding_blocks; - /*! \brief The frame output expr. `NullOpt` when undefined. */ + /*! \brief The frame output expr. `std::nullopt` when undefined. */ Optional output; void VisitAttrs(tvm::AttrVisitor* v) { diff --git a/include/tvm/script/ir_builder/relax/ir.h b/include/tvm/script/ir_builder/relax/ir.h index c931a09d1f72..49bc1a2851d3 100644 --- a/include/tvm/script/ir_builder/relax/ir.h +++ b/include/tvm/script/ir_builder/relax/ir.h @@ -101,7 +101,7 @@ TVM_DLL void DataflowBlockOutput(const Array& vars); */ TVM_DLL tvm::relax::Var Emit( const tvm::relax::Expr& value, - const Optional& annotate_struct_info = NullOpt); + const Optional& annotate_struct_info = std::nullopt); /*! * \brief Emit a match_cast binding to the last binding block frame. diff --git a/include/tvm/script/ir_builder/tir/ir.h b/include/tvm/script/ir_builder/tir/ir.h index 5927a0a284f8..d3eb8ac435d5 100644 --- a/include/tvm/script/ir_builder/tir/ir.h +++ b/include/tvm/script/ir_builder/tir/ir.h @@ -109,7 +109,7 @@ Type FuncRet(Type ret_type); * \return The matched buffer. */ Buffer MatchBuffer(ObjectRef param, Array shape, DataType dtype = DataType::Float(32), - Optional data = NullOpt, Array strides = {}, + Optional data = std::nullopt, Array strides = {}, PrimExpr elem_offset = PrimExpr(), String storage_scope = "global", int align = -1, int offset_factor = 0, String buffer_type = "default", Optional> axis_separators = std::nullopt); @@ -167,7 +167,7 @@ void BlockAttrs(Map attrs); * \return The allocated buffer. */ Buffer AllocBuffer(Array shape, DataType dtype = DataType::Float(32), - Optional data = NullOpt, Array strides = {}, + Optional data = std::nullopt, Array strides = {}, PrimExpr elem_offset = PrimExpr(), String storage_scope = "", int align = -1, int offset_factor = 0, String buffer_type = "default", Optional> axis_separators = std::nullopt); @@ -227,7 +227,8 @@ Array Remap(String kinds, Array bindings, DataType dtype = DataTy * \param annotations The optional annotations of the For statement. * \return The ForFrame. */ -ForFrame Serial(PrimExpr start, PrimExpr stop, Optional> annotations = NullOpt); +ForFrame Serial(PrimExpr start, PrimExpr stop, + Optional> annotations = std::nullopt); /*! * \brief The parallel For statement. * \param start The minimum value of iteration. @@ -235,7 +236,8 @@ ForFrame Serial(PrimExpr start, PrimExpr stop, Optional> annota * \param annotations The optional annotations of the For statement. * \return The ForFrame. */ -ForFrame Parallel(PrimExpr start, PrimExpr stop, Optional> annotations = NullOpt); +ForFrame Parallel(PrimExpr start, PrimExpr stop, + Optional> annotations = std::nullopt); /*! * \brief The vectorized For statement. * \param start The minimum value of iteration. @@ -244,7 +246,7 @@ ForFrame Parallel(PrimExpr start, PrimExpr stop, Optional> anno * \return The ForFrame. */ ForFrame Vectorized(PrimExpr start, PrimExpr stop, - Optional> annotations = NullOpt); + Optional> annotations = std::nullopt); /*! * \brief The unrolled For statement. * \param start The minimum value of iteration. @@ -252,7 +254,8 @@ ForFrame Vectorized(PrimExpr start, PrimExpr stop, * \param annotations The optional annotations of the For statement. * \return The ForFrame. */ -ForFrame Unroll(PrimExpr start, PrimExpr stop, Optional> annotations = NullOpt); +ForFrame Unroll(PrimExpr start, PrimExpr stop, + Optional> annotations = std::nullopt); /*! * \brief The thread-binding For statement. * \param start The minimum value of iteration. @@ -262,7 +265,7 @@ ForFrame Unroll(PrimExpr start, PrimExpr stop, Optional> annota * \return The ForFrame. */ ForFrame ThreadBinding(PrimExpr start, PrimExpr stop, String thread, - Optional> annotations = NullOpt); + Optional> annotations = std::nullopt); /*! * \brief The grid For statement. * \param extents The extents of the iteration. @@ -287,8 +290,8 @@ AssertFrame Assert(PrimExpr condition, String message); * \param var The variable to be bound. If not specified, a new variable will be created. * \return The created LetFrame. */ -LetFrame LetStmt(PrimExpr value, Optional type_annotation = NullOpt, - Optional var = NullOpt); +LetFrame LetStmt(PrimExpr value, Optional type_annotation = std::nullopt, + Optional var = std::nullopt); /*! * \brief The realization. @@ -309,8 +312,8 @@ RealizeFrame Realize(tvm::tir::BufferRegion buffer_slice, String storage_scope, * \return The created AllocateFrame. */ AllocateFrame Allocate(Array extents, DataType dtype, String storage_scope = "", - Optional condition = NullOpt, - Optional> annotations = NullOpt); + Optional condition = std::nullopt, + Optional> annotations = std::nullopt); /*! * \brief The allocate constant node. @@ -321,7 +324,7 @@ AllocateFrame Allocate(Array extents, DataType dtype, String storage_s * \return The created AllocateConstFrame. */ AllocateConstFrame AllocateConst(NDArray data, DataType dtype, Array extents, - Optional> annotations = NullOpt); + Optional> annotations = std::nullopt); /*! * \brief Create an attribute. @@ -456,12 +459,12 @@ inline Var Handle(runtime::DataType dtype = runtime::DataType::Void(), return is_size_var ? tvm::tir::SizeVar("", type_annotation) : tvm::tir::Var("", type_annotation); } -#define TVM_TIR_IR_BUILDER_DEF_DTYPE_CAST(FuncName, DType) \ - inline PrimExpr FuncName(Optional expr = NullOpt, bool is_size_var = false) { \ - DataType dtype = DType; \ - return expr.defined() \ - ? tvm::cast(dtype, expr.value()) \ - : (is_size_var ? tvm::tir::SizeVar("", dtype) : tvm::tir::Var("", dtype)); \ +#define TVM_TIR_IR_BUILDER_DEF_DTYPE_CAST(FuncName, DType) \ + inline PrimExpr FuncName(Optional expr = std::nullopt, bool is_size_var = false) { \ + DataType dtype = DType; \ + return expr.defined() \ + ? tvm::cast(dtype, expr.value()) \ + : (is_size_var ? tvm::tir::SizeVar("", dtype) : tvm::tir::Var("", dtype)); \ } #define TVM_TIR_IR_BUILDER_DEF_DTYPE_CAST_SIZES(DType, FDType) \ diff --git a/include/tvm/script/printer/doc.h b/include/tvm/script/printer/doc.h index 18d7a8194efc..b9a21b126c4f 100644 --- a/include/tvm/script/printer/doc.h +++ b/include/tvm/script/printer/doc.h @@ -161,7 +161,7 @@ class StmtDocNode : public DocNode { * line as the statement, or the line above, or inside the statement * if it spans over multiple lines. * */ - mutable Optional comment{NullOpt}; + mutable Optional comment{std::nullopt}; void VisitAttrs(AttrVisitor* v) { DocNode::VisitAttrs(v); @@ -634,7 +634,7 @@ class TupleDoc : public ExprDoc { /*! * \brief Create an empty TupleDoc */ - TupleDoc() : TupleDoc(runtime::make_object()) {} + TupleDoc() : TupleDoc(ffi::make_object()) {} /*! * \brief Constructor of TupleDoc * \param elements Elements of tuple. @@ -672,7 +672,7 @@ class ListDoc : public ExprDoc { /*! * \brief Create an empty ListDoc */ - ListDoc() : ListDoc(runtime::make_object()) {} + ListDoc() : ListDoc(ffi::make_object()) {} /*! * \brief Constructor of ListDoc * \param elements Elements of list. @@ -718,7 +718,7 @@ class DictDoc : public ExprDoc { /*! * \brief Create an empty dictionary */ - DictDoc() : DictDoc(runtime::make_object()) {} + DictDoc() : DictDoc(ffi::make_object()) {} /*! * \brief Constructor of DictDoc * \param keys Keys of dictionary. @@ -957,7 +957,7 @@ class ForDoc : public StmtDoc { class ScopeDocNode : public StmtDocNode { public: /*! \brief The name of the scoped variable. */ - Optional lhs{NullOpt}; + Optional lhs{std::nullopt}; /*! \brief The value of the scoped variable. */ ExprDoc rhs{nullptr}; /*! \brief The body of the scope doc. */ @@ -1043,7 +1043,7 @@ class AssertDocNode : public StmtDocNode { /*! \brief The expression to test. */ ExprDoc test{nullptr}; /*! \brief The optional error message when assertion failed. */ - Optional msg{NullOpt}; + Optional msg{std::nullopt}; void VisitAttrs(AttrVisitor* v) { StmtDocNode::VisitAttrs(v); @@ -1067,7 +1067,7 @@ class AssertDoc : public StmtDoc { * \param test The expression to test. * \param msg The optional error message when assertion failed. */ - explicit AssertDoc(ExprDoc test, Optional msg = NullOpt); + explicit AssertDoc(ExprDoc test, Optional msg = std::nullopt); TVM_DEFINE_NOTNULLABLE_OBJECT_REF_METHODS(AssertDoc, StmtDoc, AssertDocNode); }; @@ -1125,7 +1125,7 @@ class FunctionDocNode : public StmtDocNode { /*! \brief Decorators of function. */ Array decorators; /*! \brief The return type of function. */ - Optional return_type{NullOpt}; + Optional return_type{std::nullopt}; /*! \brief The body of function. */ Array body; diff --git a/include/tvm/script/printer/ir_docsifier.h b/include/tvm/script/printer/ir_docsifier.h index db94064d538c..9211064526ed 100644 --- a/include/tvm/script/printer/ir_docsifier.h +++ b/include/tvm/script/printer/ir_docsifier.h @@ -203,7 +203,7 @@ class IRDocsifierNode : public Object { * \brief Get the doc for variable. * \param obj The variable object. * - * \return The doc for variable, if it exists in the table. Otherwise it returns NullOpt. + * \return The doc for variable, if it exists in the table. Otherwise it returns std::nullopt. */ Optional GetVarDoc(const ObjectRef& obj) const; /*! \brief Add a TVM object to the metadata section*/ diff --git a/include/tvm/target/target.h b/include/tvm/target/target.h index b851d1a8780d..86e90a7ce2db 100644 --- a/include/tvm/target/target.h +++ b/include/tvm/target/target.h @@ -103,7 +103,7 @@ class TargetNode : public Object { * \tparam TObjectRef Type of the attribute * \param attr_key The name of the attribute key * \param default_value The value returned if the key is not present - * \return An optional, NullOpt if not found, otherwise the value found + * \return An optional, std::nullopt if not found, otherwise the value found */ template Optional GetAttr( @@ -121,7 +121,7 @@ class TargetNode : public Object { * \tparam TObjectRef Type of the attribute * \param attr_key The name of the attribute key * \param default_value The value returned if the key is not present - * \return An optional, NullOpt if not found, otherwise the value found + * \return An optional, std::nullopt if not found, otherwise the value found */ template Optional GetAttr(const std::string& attr_key, TObjectRef default_value) const { diff --git a/include/tvm/tir/analysis.h b/include/tvm/tir/analysis.h index 32b3231781f4..a21112b7d6f6 100644 --- a/include/tvm/tir/analysis.h +++ b/include/tvm/tir/analysis.h @@ -314,7 +314,7 @@ TVM_DLL tvm::Map> CalculateAllocatedBytes(cons * The LCA may be a For loop or a Block. * \param func The PrimFunc to be detected. * \return The Map from buffer to the LCA of all access to it. The lca is function root if the - * return stmt is NullOpt. + * return stmt is std::nullopt. */ TVM_DLL Map> DetectBufferAccessLCA(const PrimFunc& func); @@ -421,7 +421,7 @@ TVM_DLL Pass VerifyGPUCode(Map constraints); * \returns The pass. * \sa tvm::tir::CalculateAllocatedBytes */ -TVM_DLL Pass VerifyVTCMLimit(Optional target = NullOpt); +TVM_DLL Pass VerifyVTCMLimit(Optional target = std::nullopt); /*! * \brief Statically check TIR code for out of bounds array access. diff --git a/include/tvm/tir/buffer.h b/include/tvm/tir/buffer.h index 65bb88082a49..e0a197d41ff8 100644 --- a/include/tvm/tir/buffer.h +++ b/include/tvm/tir/buffer.h @@ -24,10 +24,10 @@ #ifndef TVM_TIR_BUFFER_H_ #define TVM_TIR_BUFFER_H_ +#include +#include #include #include -#include -#include #include #include @@ -204,7 +204,7 @@ class Buffer : public ObjectRef { */ TVM_DLL PrimExpr access_ptr(int access_mask, DataType ptr_type = DataType::Handle(), int content_lanes = 1, PrimExpr offset = IntImm(DataType::Int(32), 0), - Optional input_extent = NullOpt) const; + Optional input_extent = std::nullopt) const; /*! * \brief Create an Expr that does a vector load at begin index. * \param begin The beginning index @@ -213,7 +213,7 @@ class Buffer : public ObjectRef { * loaded. The number lanes of the mask must be equal to the number of lanes in being loaded. */ TVM_DLL PrimExpr vload(Array begin, DataType dtype, - Optional predicate = NullOpt) const; + Optional predicate = std::nullopt) const; /*! * \brief Create a Stmt that does a vector store at begin index. * \param begin The beginning index @@ -222,7 +222,7 @@ class Buffer : public ObjectRef { * stored. The number lanes of the mask must be equal to the number of lanes in value. */ TVM_DLL Stmt vstore(Array begin, PrimExpr value, - Optional predicate = NullOpt) const; + Optional predicate = std::nullopt) const; /*! * \brief Get a flattened version of the buffer diff --git a/include/tvm/tir/expr.h b/include/tvm/tir/expr.h index d2b674a80139..078b41e32798 100644 --- a/include/tvm/tir/expr.h +++ b/include/tvm/tir/expr.h @@ -25,13 +25,13 @@ #ifndef TVM_TIR_EXPR_H_ #define TVM_TIR_EXPR_H_ +#include +#include +#include #include #include #include #include -#include -#include -#include #include #include #include @@ -681,7 +681,7 @@ class BufferLoadNode : public PrimExprNode { class BufferLoad : public PrimExpr { public: TVM_DLL explicit BufferLoad(Buffer buffer, Array indices, - Optional predicate = NullOpt, Span span = Span()); + Optional predicate = std::nullopt, Span span = Span()); TVM_DEFINE_OBJECT_REF_METHODS(BufferLoad, PrimExpr, BufferLoadNode); TVM_DEFINE_OBJECT_REF_COW_METHOD(BufferLoadNode); }; diff --git a/include/tvm/tir/function.h b/include/tvm/tir/function.h index f85c0ed706ef..edb88bcafe55 100644 --- a/include/tvm/tir/function.h +++ b/include/tvm/tir/function.h @@ -24,9 +24,9 @@ #ifndef TVM_TIR_FUNCTION_H_ #define TVM_TIR_FUNCTION_H_ +#include +#include #include -#include -#include #include #include #include diff --git a/include/tvm/tir/index_map.h b/include/tvm/tir/index_map.h index 319b5193e8f6..1a5bdd8e4018 100644 --- a/include/tvm/tir/index_map.h +++ b/include/tvm/tir/index_map.h @@ -26,8 +26,8 @@ #ifndef TVM_TIR_INDEX_MAP_H_ #define TVM_TIR_INDEX_MAP_H_ +#include #include -#include #include #include @@ -182,7 +182,7 @@ class IndexMap : public ObjectRef { * \param inverse_index_map The optional pre-defined inverse index map */ IndexMap(Array initial_indices, Array final_indices, - Optional inverse_index_map = NullOpt); + Optional inverse_index_map = std::nullopt); /*! * \brief Create an index map from a packed function @@ -192,7 +192,7 @@ class IndexMap : public ObjectRef { * \return The created index map */ static IndexMap FromFunc(int ndim, ffi::TypedFunction(Array)> func, - Optional inverse_index_map = NullOpt); + Optional inverse_index_map = std::nullopt); /*! \brief Generate the inverse mapping. * diff --git a/include/tvm/tir/op_attr_types.h b/include/tvm/tir/op_attr_types.h index 59d4cbbcd507..29877b145802 100644 --- a/include/tvm/tir/op_attr_types.h +++ b/include/tvm/tir/op_attr_types.h @@ -28,8 +28,8 @@ #ifndef TVM_TIR_OP_ATTR_TYPES_H_ #define TVM_TIR_OP_ATTR_TYPES_H_ +#include #include -#include #include #include diff --git a/include/tvm/tir/schedule/schedule.h b/include/tvm/tir/schedule/schedule.h index f869a4840ce9..1a24644b5202 100644 --- a/include/tvm/tir/schedule/schedule.h +++ b/include/tvm/tir/schedule/schedule.h @@ -225,7 +225,7 @@ class ScheduleNode : public runtime::Object { * \return The random variable sampled from candidates */ virtual ExprRV SampleCategorical(const Array& candidates, const Array& probs, - Optional decision = NullOpt) = 0; + Optional decision = std::nullopt) = 0; /*! * \brief Sample the factors to perfect tile a specific loop * \param loop_rv The loop to be tiled @@ -235,7 +235,7 @@ class ScheduleNode : public runtime::Object { * \return A list of length `n`, the random perfect tile sizes sampled */ virtual Array SamplePerfectTile(const LoopRV& loop_rv, int n, int max_innermost_factor, - Optional> decision = NullOpt) = 0; + Optional> decision = std::nullopt) = 0; /*! * \brief Sample the factors to a partitioned tile for a specific loop * @@ -253,7 +253,7 @@ class ScheduleNode : public runtime::Object { */ virtual Array SamplePartitionedTile(const LoopRV& loop_rv, int n, int partition_pos, int innerpart_factor, - Optional> decision = NullOpt) = 0; + Optional> decision = std::nullopt) = 0; /*! * \brief Sample a compute-at location of the given block * \param block_rv The block whose compute-at location is to be sampled @@ -261,7 +261,7 @@ class ScheduleNode : public runtime::Object { * \return The sampled loop where the input block is to be computed at */ virtual LoopRV SampleComputeLocation(const BlockRV& block_rv, - Optional decision = NullOpt) = 0; + Optional decision = std::nullopt) = 0; /******** Schedule: Get blocks & loops ********/ /*! @@ -278,7 +278,8 @@ class ScheduleNode : public runtime::Object { * * \sa WorkOn */ - virtual BlockRV GetBlock(const String& name, const Optional& func_name = NullOpt) = 0; + virtual BlockRV GetBlock(const String& name, + const Optional& func_name = std::nullopt) = 0; /*! * \brief Get the parent loops of the block in its scope, from outer to inner * \param block_rv The query block @@ -347,14 +348,12 @@ class ScheduleNode : public runtime::Object { * 1) The loop can't have annotation or thread binding. * 2) The loop must start with 0. * \param loop_rv The loop to be split - * \param factors The positive tiling factors, and at most one of which is `NullOpt`, which means - * that factor is inferred. - * \param preserve_unit_iters Whether or not to preserve unit iterators in block bindings. - * \param disable_predication If enabled, don't create a predicate for guarding the - * loop. This can be useful when splitting with scalable factors that the schedule writer - * knows are divisible by the loop bound. - * Warning: enabling this feature may result in incorrect code generation if not used carefully. - * \return The new loops after split. + * \param factors The positive tiling factors, and at most one of which is `std::nullopt`, which + * means that factor is inferred. \param preserve_unit_iters Whether or not to preserve unit + * iterators in block bindings. \param disable_predication If enabled, don't create a predicate + * for guarding the loop. This can be useful when splitting with scalable factors that the + * schedule writer knows are divisible by the loop bound. Warning: enabling this feature may + * result in incorrect code generation if not used carefully. \return The new loops after split. */ virtual Array Split(const LoopRV& loop_rv, const Array>& factors, bool preserve_unit_iters = true, @@ -363,7 +362,7 @@ class ScheduleNode : public runtime::Object { * \brief Partition the loops into sequence of multiple loops * 1) The loop can't have annotation or thread binding. * \param loop_rv The loop to be partition - * \param factors The positive integers, and at most one of which is `NullOpt`, which means + * \param factors The positive integers, and at most one of which is `std::nullopt`, which means * that factor is inferred. * \param preserve_unit_iters Whether or not to preserve unit iterators in block bindings * \return The new loops after partition @@ -761,7 +760,7 @@ class ScheduleNode : public runtime::Object { */ virtual void TransformLayout(const BlockRV& block_rv, int buffer_index, BufferIndexType buffer_index_type, const IndexMap& index_map, - const Optional& pad_value = NullOpt, + const Optional& pad_value = std::nullopt, bool assume_injective_transform = false) = 0; /*! diff --git a/include/tvm/tir/schedule/trace.h b/include/tvm/tir/schedule/trace.h index 79a2f8b2a08e..fca5966e198b 100644 --- a/include/tvm/tir/schedule/trace.h +++ b/include/tvm/tir/schedule/trace.h @@ -92,7 +92,7 @@ class TraceNode : public runtime::Object { void Append(Instruction inst, Any decision); /*! * \brief Remove the last instruction, along with the decision made on that instruction, if any - * \return The instruction removed; NullOpt if the trace is empty + * \return The instruction removed; std::nullopt if the trace is empty */ Optional Pop(); /*! diff --git a/include/tvm/tir/stmt.h b/include/tvm/tir/stmt.h index efcf4a47d61c..6d93a3a153ad 100644 --- a/include/tvm/tir/stmt.h +++ b/include/tvm/tir/stmt.h @@ -265,7 +265,7 @@ class BufferStoreNode : public StmtNode { class BufferStore : public Stmt { public: TVM_DLL explicit BufferStore(Buffer buffer, PrimExpr value, Array indices, - Optional predicate = NullOpt, Span span = Span()); + Optional predicate = std::nullopt, Span span = Span()); TVM_DEFINE_OBJECT_REF_METHODS(BufferStore, Stmt, BufferStoreNode); TVM_DEFINE_OBJECT_REF_COW_METHOD(BufferStoreNode); @@ -818,16 +818,16 @@ class SeqStmt : public Stmt { return t; } if constexpr (!std::is_base_of_v) { - return NullOpt; + return std::nullopt; } if constexpr (std::is_base_of_v) { if (const SeqStmtNode* ptr = t.template as()) { return GetRef(ptr); } else { - return NullOpt; + return std::nullopt; } } - return NullOpt; + return std::nullopt; } template @@ -925,7 +925,7 @@ class IfThenElseNode : public StmtNode { */ class IfThenElse : public Stmt { public: - TVM_DLL IfThenElse(PrimExpr condition, Stmt then_case, Optional else_case = NullOpt, + TVM_DLL IfThenElse(PrimExpr condition, Stmt then_case, Optional else_case = std::nullopt, Span span = Span()); TVM_DEFINE_OBJECT_REF_METHODS(IfThenElse, Stmt, IfThenElseNode); @@ -1035,7 +1035,7 @@ class ForNode : public StmtNode { class For : public Stmt { public: TVM_DLL For(Var loop_var, PrimExpr min, PrimExpr extent, ForKind kind, Stmt body, - Optional thread_binding = NullOpt, + Optional thread_binding = std::nullopt, Map annotations = Map(), Span span = Span()); TVM_DEFINE_OBJECT_REF_METHODS(For, Stmt, ForNode); @@ -1280,7 +1280,7 @@ class BlockNode : public StmtNode { * reduction block. The optional init field allows us to represent initialization and * reduction update in a single block and transform them collectively. * We also provide primitives to decompose the init into a separate block during scheduling. - * Init field is `NullOpt` if there is no reduction iter_vars + * Init field is `std::nullopt` if there is no reduction iter_vars */ Optional init; /*! \brief The buffer allocated in the block. */ @@ -1334,7 +1334,7 @@ class Block : public Stmt { public: TVM_DLL explicit Block(Array iter_vars, Array reads, Array writes, String name_hint, Stmt body, - Optional init = NullOpt, + Optional init = std::nullopt, Array alloc_buffers = Array(), Array match_buffers = Array(), Map annotations = Map(), diff --git a/include/tvm/tir/stmt_functor.h b/include/tvm/tir/stmt_functor.h index 9ce49610ee34..141fe710b371 100644 --- a/include/tvm/tir/stmt_functor.h +++ b/include/tvm/tir/stmt_functor.h @@ -226,7 +226,7 @@ class TVM_DLL StmtMutator : protected StmtFunctor { } else { // Make a new copy of the node. // need to rely on the default copy constructor - return runtime::make_object(*node); + return ffi::make_object(*node); } } /*! @@ -331,13 +331,13 @@ class StmtExprMutator : public StmtMutator, public ExprMutator { * won't do further recursion. * \param postorder The function called after recursive mutation. * The recursive mutation result is passed to postorder for further mutation. - * \param only_enable List of runtime::String. + * \param only_enable List of String. * If it is null, all IRNode will call preorder/postorder * If it is not null, preorder/postorder will only be called * when the IRNode's type key is in the list. */ TVM_DLL Stmt IRTransform(Stmt stmt, const ffi::Function& preorder, const ffi::Function& postorder, - Optional> only_enable = NullOpt); + Optional> only_enable = std::nullopt); /*! * \brief Recursively visit the ir in post DFS order node, apply fvisit @@ -418,7 +418,7 @@ auto Substitute(Obj&& obj, const Map& vmap) { if (auto opt = vmap.Get(var)) { return opt.value(); } else { - return NullOpt; + return std::nullopt; } }; return Substitute(std::forward(obj), func); @@ -440,7 +440,7 @@ auto Substitute(Obj&& obj, const std::unordered_map& vmap) if (auto it = vmap.find(var.get()); it != vmap.end()) { return it->second; } else { - return NullOpt; + return std::nullopt; } }; return Substitute(std::forward(obj), func); @@ -462,7 +462,7 @@ auto Substitute(Obj&& obj, const std::unordered_mapsecond; } else { - return NullOpt; + return std::nullopt; } }; return Substitute(std::forward(obj), func); @@ -489,7 +489,7 @@ auto Substitute(Obj&& obj, const std::unordered_map& iter_vmap) { if (auto it = vmap.find(var.get()); it != vmap.end()) { return it->second; } else { - return NullOpt; + return std::nullopt; } }; return Substitute(std::forward(obj), func); diff --git a/include/tvm/topi/nn/pooling.h b/include/tvm/topi/nn/pooling.h index 6e2edb3f304a..abe26b6c6727 100644 --- a/include/tvm/topi/nn/pooling.h +++ b/include/tvm/topi/nn/pooling.h @@ -352,7 +352,7 @@ inline Tensor adaptive_pool_impl(const Tensor& x, const Array& output_ Map attrs; if (pool_type == kMaxPool) { - attrs.Set("schedule_rule", tvm::runtime::String("meta_schedule.adaptive_pool_max")); + attrs.Set("schedule_rule", tvm::String("meta_schedule.adaptive_pool_max")); return tvm::te::compute( out_shape, [&](const Array& output) { @@ -363,7 +363,7 @@ inline Tensor adaptive_pool_impl(const Tensor& x, const Array& output_ }, "adaptive_pool_max", "adaptive_pool_max", attrs); } else if (pool_type == kAvgPool) { - attrs.Set("schedule_rule", tvm::runtime::String("meta_schedule.adaptive_pool_avg")); + attrs.Set("schedule_rule", tvm::String("meta_schedule.adaptive_pool_avg")); auto pool_sum = tvm::te::compute( out_shape, [&](const Array& output) { @@ -566,7 +566,7 @@ inline Tensor pool_impl_nd(const Tensor& x, const Array& kernel_size, Map attrs; if (pool_type == kMaxPool) { auto temp = do_pad ? pad(x, pad_before, pad_after, tvm::min_value(x->dtype), "pad_temp") : x; - attrs.Set("schedule_rule", tvm::runtime::String("meta_schedule.pool_max")); + attrs.Set("schedule_rule", tvm::String("meta_schedule.pool_max")); return tvm::te::compute( out_shape, [&](const Array& output) { @@ -581,7 +581,7 @@ inline Tensor pool_impl_nd(const Tensor& x, const Array& kernel_size, }, "pool_max", "pool_max", attrs); } else if (pool_type == kAvgPool) { - attrs.Set("schedule_rule", tvm::runtime::String("meta_schedule.pool_avg")); + attrs.Set("schedule_rule", tvm::String("meta_schedule.pool_avg")); // Pad the inputs auto temp = do_pad ? pad(x, pad_before, pad_after, 0, "pad_temp") : x; diff --git a/python/setup.py b/python/setup.py index 3900e5b3d02d..ffa8c2bbd433 100644 --- a/python/setup.py +++ b/python/setup.py @@ -242,7 +242,6 @@ def long_description_contents(): license="Apache", # See https://pypi.org/classifiers/ classifiers=[ - "License :: OSI Approved :: Apache Software License", "Development Status :: 4 - Beta", "Intended Audience :: Developers", "Intended Audience :: Education", @@ -250,7 +249,6 @@ def long_description_contents(): ], keywords="machine learning", zip_safe=False, - entry_points={"console_scripts": ["tvmc = tvm.driver.tvmc.main:main"]}, install_requires=requirements["core"][1], extras_require=extras_require, packages=find_packages(), diff --git a/python/tvm/relax/expr_functor.py b/python/tvm/relax/expr_functor.py index a0bb6df84373..12647733cbd7 100644 --- a/python/tvm/relax/expr_functor.py +++ b/python/tvm/relax/expr_functor.py @@ -1503,7 +1503,7 @@ def visit_with_new_scope(self, expr: Expr) -> Expr: def lookup_binding(self, var: Var) -> Optional[Expr]: """Look up the value bound to a variable. - Note: For function parameters, this function returns NullOpt. + Note: For function parameters, this function returns std::nullopt. Parameters ---------- diff --git a/python/tvm/runtime/disco/session.py b/python/tvm/runtime/disco/session.py index 3ebb6dbdb611..719e399b597f 100644 --- a/python/tvm/runtime/disco/session.py +++ b/python/tvm/runtime/disco/session.py @@ -271,7 +271,7 @@ def copy_to_worker_0(self, host_array: NDArray, remote_array: Optional[DRef] = N output_array: DRef The DRef containing the copied data on worker0, and - NullOpt on all other workers. If `remote_array` was + std::nullopt on all other workers. If `remote_array` was provided, this return value is the same as `remote_array`. Otherwise, it is the newly allocated space. diff --git a/python/tvm/tir/schedule/trace.py b/python/tvm/tir/schedule/trace.py index f1f6bdaa5743..25cf5244addf 100644 --- a/python/tvm/tir/schedule/trace.py +++ b/python/tvm/tir/schedule/trace.py @@ -139,7 +139,7 @@ def pop(self) -> Optional[Instruction]: Returns ------- popped_inst : Instruction - Returns the instruction removed; NullOpt if the trace is empty + Returns the instruction removed; std::nullopt if the trace is empty """ return _ffi_api.TracePop(self) # type: ignore # pylint: disable=no-member diff --git a/python/tvm/tir/schedule/transform.py b/python/tvm/tir/schedule/transform.py index e40b55d4d6b2..fbaca81197e5 100644 --- a/python/tvm/tir/schedule/transform.py +++ b/python/tvm/tir/schedule/transform.py @@ -41,6 +41,6 @@ def tile_with_tensor_intrin( ------- tiled_loop_rv : Optional[LoopRV] LoopRV corresponding to the outermost loop of a block tiled according to the given intrin - NullOpt if no valid loop mapping is found + std::nullopt if no valid loop mapping is found """ return _ffi_api.TileWithTensorIntrin(sch, block, intrin_name, allow_padding) # type: ignore diff --git a/src/arith/canonical_simplify.cc b/src/arith/canonical_simplify.cc index b11708398fe9..06f181030ee0 100644 --- a/src/arith/canonical_simplify.cc +++ b/src/arith/canonical_simplify.cc @@ -921,7 +921,7 @@ bool CanonicalSimplifier::Impl::ProdDivSimplify(PrimExpr* plhs, PrimExpr* prhs, // try eliminate from lhs for (size_t i = 0; i < lhs_prods.size(); ++i) { if (lhs_prods[i].defined() && deep_equal(value, lhs_prods[i].value())) { - lhs_prods.Set(i, NullOpt); + lhs_prods.Set(i, std::nullopt); ++num_elimination; new_common_scale = new_common_scale * value; return; diff --git a/src/arith/const_fold.h b/src/arith/const_fold.h index 65ac749d45e7..2c905dd563ef 100644 --- a/src/arith/const_fold.h +++ b/src/arith/const_fold.h @@ -24,7 +24,7 @@ #ifndef TVM_ARITH_CONST_FOLD_H_ #define TVM_ARITH_CONST_FOLD_H_ -#include +#include #include #include @@ -45,7 +45,7 @@ namespace arith { * \tparam Op The operator type. * * \note a and b Must already matched data types with each other. - * \return NullOpt if constant fold fails, otherwise return folded result. + * \return std::nullopt if constant fold fails, otherwise return folded result. */ template inline Optional TryConstFold(PrimExpr a, PrimExpr b); @@ -57,7 +57,7 @@ inline Optional TryConstFold(PrimExpr a, PrimExpr b); * \tparam Op The operator type. * * \note a and b Must already matched data types with each other. - * \return NullOpt if constant fold fails, otherwise return folded result. + * \return std::nullopt if constant fold fails, otherwise return folded result. */ template inline Optional TryConstFold(PrimExpr a); @@ -148,7 +148,7 @@ inline Optional TryConstFold(PrimExpr a, PrimExpr b) { if (fa && fa->value == 0) return b; if (fb && fb->value == 0) return a; }); - return NullOpt; + return std::nullopt; } template <> @@ -174,7 +174,7 @@ inline Optional TryConstFold(PrimExpr a, PrimExpr b) { } if (fb && fb->value == 0) return a; }); - return NullOpt; + return std::nullopt; } template <> @@ -210,7 +210,7 @@ inline Optional TryConstFold(PrimExpr a, PrimExpr b) { if (fb->value == 0) return b; } }); - return NullOpt; + return std::nullopt; } template <> @@ -246,7 +246,7 @@ inline Optional TryConstFold(PrimExpr a, PrimExpr b) { ICHECK_NE(fb->value, 0) << "Divide by zero"; } }); - return NullOpt; + return std::nullopt; } template <> @@ -266,7 +266,7 @@ inline Optional TryConstFold(PrimExpr a, PrimExpr b) { ICHECK_NE(pb->value, 0) << "Divide by zero"; } }); - return NullOpt; + return std::nullopt; } template <> @@ -292,7 +292,7 @@ inline Optional TryConstFold(PrimExpr a, PrimExpr b) { } else if (rtype.bits() == 64) { return FloatImm(rtype, std::floor(fa->value / fb->value)); } else { - return NullOpt; + return std::nullopt; } } if (fa && fa->value == 0) return a; @@ -301,7 +301,7 @@ inline Optional TryConstFold(PrimExpr a, PrimExpr b) { ICHECK_NE(fb->value, 0) << "Divide by zero"; } }); - return NullOpt; + return std::nullopt; } template <> @@ -321,7 +321,7 @@ inline Optional TryConstFold(PrimExpr a, PrimExpr b) { ICHECK_NE(pb->value, 0) << "Divide by zero"; } }); - return NullOpt; + return std::nullopt; } template <> @@ -332,7 +332,7 @@ inline Optional TryConstFold(PrimExpr a, PrimExpr b) { if (fa && fb) return FloatImm(rtype, std::min(fa->value, fb->value)); }); if (a.same_as(b)) return a; - return NullOpt; + return std::nullopt; } template <> @@ -343,7 +343,7 @@ inline Optional TryConstFold(PrimExpr a, PrimExpr b) { if (fa && fb) return FloatImm(rtype, std::max(fa->value, fb->value)); }); if (a.same_as(b)) return a; - return NullOpt; + return std::nullopt; } template <> @@ -352,7 +352,7 @@ inline Optional TryConstFold(PrimExpr a, PrimExpr b) { if (pa && pb) return IntImm(DataType::UInt(1), pa->value > pb->value); if (fa && fb) return IntImm(DataType::UInt(1), fa->value > fb->value); }); - return NullOpt; + return std::nullopt; } template <> @@ -361,7 +361,7 @@ inline Optional TryConstFold(PrimExpr a, PrimExpr b) { if (pa && pb) return IntImm(DataType::UInt(1), pa->value >= pb->value); if (fa && fb) return IntImm(DataType::UInt(1), fa->value >= fb->value); }); - return NullOpt; + return std::nullopt; } template <> @@ -370,7 +370,7 @@ inline Optional TryConstFold(PrimExpr a, PrimExpr b) { if (pa && pb) return IntImm(DataType::UInt(1), pa->value < pb->value); if (fa && fb) return IntImm(DataType::UInt(1), fa->value < fb->value); }); - return NullOpt; + return std::nullopt; } template <> @@ -379,7 +379,7 @@ inline Optional TryConstFold(PrimExpr a, PrimExpr b) { if (pa && pb) return IntImm(DataType::UInt(1), pa->value <= pb->value); if (fa && fb) return IntImm(DataType::UInt(1), fa->value <= fb->value); }); - return NullOpt; + return std::nullopt; } template <> @@ -388,7 +388,7 @@ inline Optional TryConstFold(PrimExpr a, PrimExpr b) { if (pa && pb) return IntImm(DataType::UInt(1), pa->value == pb->value); if (fa && fb) return IntImm(DataType::UInt(1), fa->value == fb->value); }); - return NullOpt; + return std::nullopt; } template <> @@ -397,7 +397,7 @@ inline Optional TryConstFold(PrimExpr a, PrimExpr b) { if (pa && pb) return IntImm(DataType::UInt(1), pa->value != pb->value); if (fa && fb) return IntImm(DataType::UInt(1), fa->value != fb->value); }); - return NullOpt; + return std::nullopt; } template <> @@ -408,7 +408,7 @@ inline Optional TryConstFold(PrimExpr a, PrimExpr b) { if (pa && !pa->value) return a; if (pb && pb->value) return a; if (pb && !pb->value) return b; - return NullOpt; + return std::nullopt; } template <> @@ -419,7 +419,7 @@ inline Optional TryConstFold(PrimExpr a, PrimExpr b) { if (pa && !pa->value) return b; if (pb && pb->value) return b; if (pb && !pb->value) return a; - return NullOpt; + return std::nullopt; } template <> @@ -428,7 +428,7 @@ inline Optional TryConstFold(PrimExpr a) { if (pa) { return IntImm(DataType::UInt(1), !(pa->value)); } - return NullOpt; + return std::nullopt; } /*! \brief Helper namespace for symbolic value limits */ diff --git a/src/arith/const_int_bound.cc b/src/arith/const_int_bound.cc index ecd3b25bfc67..ac8ac917114a 100644 --- a/src/arith/const_int_bound.cc +++ b/src/arith/const_int_bound.cc @@ -751,7 +751,7 @@ class ConstIntBoundAnalyzer::Impl } } } - return NullOpt; + return std::nullopt; } /*! \brief Propagate constraints through ceil(log2(arg)) diff --git a/src/arith/domain_touched.cc b/src/arith/domain_touched.cc index 8c7c33bcc3ee..13243ddb5e44 100644 --- a/src/arith/domain_touched.cc +++ b/src/arith/domain_touched.cc @@ -135,9 +135,9 @@ Region DomainTouched(const Stmt& stmt, const Buffer& buffer, bool consider_loads return BufferTouchedDomain(stmt).FindUnion(buffer, consider_loads, consider_stores); } -Map> DomainTouchedAccessMap(const PrimFunc& func) { +Map> DomainTouchedAccessMap(const PrimFunc& func) { auto buffer_access_map = BufferTouchedDomain(func->body).GetAccessedBufferRegions(); - Map> ret; + Map> ret; auto& buffer_map = func->buffer_map; for (auto& var : func->params) { auto& buffer = buffer_map[var]; @@ -153,7 +153,7 @@ Map> DomainTouchedAccessMap(const PrimFunc& fu combined.push_back(Array(touch)); } - runtime::Array fields; + Array fields; fields.push_back(loads); fields.push_back(stores); fields.push_back(combined); diff --git a/src/arith/int_set.cc b/src/arith/int_set.cc index 587e0121f057..94a2a369a664 100644 --- a/src/arith/int_set.cc +++ b/src/arith/int_set.cc @@ -1080,7 +1080,7 @@ static Optional EvalIterSum(const IterSumExpr& iter_min, const PrimExpr& return IntSet::Nothing(); } if (!analyzer->CanProve(extent >= split->scale)) { - return NullOpt; + return std::nullopt; } const PrimExpr& base = iter_min->base; @@ -1110,7 +1110,7 @@ Optional> EstimateRegionStrictBound(const Array& region, for (const Range& range : region) { if (!is_const_number(range->extent)) { // dynamic extent is not supported yet. - return NullOpt; + return std::nullopt; } affine_indices.push_back(range->min); } @@ -1120,7 +1120,7 @@ Optional> EstimateRegionStrictBound(const Array& region, iter_sum_exprs = res->indices; } if (iter_sum_exprs.empty()) { - return NullOpt; + return std::nullopt; } ICHECK_EQ(iter_sum_exprs.size(), ndim); Array result; @@ -1132,7 +1132,7 @@ Optional> EstimateRegionStrictBound(const Array& region, if (int_set.defined()) { result.push_back(int_set.value()); } else { - return NullOpt; + return std::nullopt; } } return result; diff --git a/src/arith/iter_affine_map.cc b/src/arith/iter_affine_map.cc index d24c278f1048..5b1feef4e608 100644 --- a/src/arith/iter_affine_map.cc +++ b/src/arith/iter_affine_map.cc @@ -985,7 +985,7 @@ class IterMapRewriter : public ExprMutator { * \return The sum with the fused IterMark and extra offset if succeed. */ Optional TryCombineSplitFromSameSource(IterSumExpr expr) { - if (expr->args.size() <= 1) return NullOpt; + if (expr->args.size() <= 1) return std::nullopt; std::unordered_map hit_count; // most iter map are small n < 5 // so we can afford N^2 complexity @@ -1000,7 +1000,7 @@ class IterMapRewriter : public ExprMutator { hit_count[expr->args[i]->source] = 1; } } - if (!has_overlap) return NullOpt; + if (!has_overlap) return std::nullopt; std::vector visited(expr->args.size(), false); std::vector reverse_flattened_iters; @@ -1096,8 +1096,8 @@ class IterMapRewriter : public ExprMutator { } // select the iterators in order std::vector visited(expr->args.size(), false); - int base_index = FindBaseIter(expr, visited, NullOpt); - if (base_index == -1) return NullOpt; + int base_index = FindBaseIter(expr, visited, std::nullopt); + if (base_index == -1) return std::nullopt; PrimExpr base_scale = expr->args[base_index]->scale; std::vector flattened_iters, grouped_iters; @@ -1114,8 +1114,8 @@ class IterMapRewriter : public ExprMutator { // find position such that expr->args[j] match expected scale // if it is first step, we can simply start with base index int matched_pos = i == 0 ? base_index - : FindIterWithExactScale(expr, visited, expected_scale, NullOpt, -1, - first_possible_unit_extent_pos); + : FindIterWithExactScale(expr, visited, expected_scale, std::nullopt, + -1, first_possible_unit_extent_pos); if (matched_pos != -1) { matched_scale = expected_scale; is_exact_match = true; @@ -1129,7 +1129,7 @@ class IterMapRewriter : public ExprMutator { } } if (matched_pos == -1) { - return NullOpt; + return std::nullopt; } ICHECK(matched_scale.defined()); // look for the longest constrained iter started from expr->args[j] @@ -1163,7 +1163,7 @@ class IterMapRewriter : public ExprMutator { } } if (k == expr->args.size()) { - return NullOpt; + return std::nullopt; } visited[k] = true; flattened_iters.push_back(expr->args[k]); @@ -1209,7 +1209,7 @@ class IterMapRewriter : public ExprMutator { // old iter if (!analyzer_->CanProveEqual(expected_extra_base, it->second.offset * base_scale)) { // the extra offset is not consistent with old - return NullOpt; + return std::nullopt; } return IterSumExpr({IterSplitExpr(it->second.mark, base_scale)}, expr->base + expected_extra_base); @@ -1372,7 +1372,7 @@ bool MatchBoundConstraints(PrimExpr pred, Map* input_iters, lhs_expr = analyzer.Simplify(lhs_expr); rhs_expr = analyzer.Simplify(rhs_expr); } - Optional lower_bound = NullOpt, upper_bound = NullOpt; + Optional lower_bound = std::nullopt, upper_bound = std::nullopt; PrimExpr iter; if (is_greater) { if (bound_at_left) { diff --git a/src/arith/rewrite_simplify.cc b/src/arith/rewrite_simplify.cc index 3682054e8e4b..cda27663520e 100644 --- a/src/arith/rewrite_simplify.cc +++ b/src/arith/rewrite_simplify.cc @@ -1662,7 +1662,7 @@ Optional RewriteSimplifier::Impl::TryMatchLiteralConstraint(const Prim return make_const(expr->dtype, false); } } - return NullOpt; + return std::nullopt; } PrimExpr RewriteSimplifier::Impl::VisitExpr_(const EQNode* op) { @@ -1948,7 +1948,7 @@ PrimExpr RewriteSimplifier::Impl::ApplyRewriteRules(LT ret) { auto [lhs, lhs_offset] = ExtractConstantOffset(ret->a); auto [rhs, rhs_offset] = ExtractConstantOffset(ret->b); if (lhs_offset == 0 && rhs_offset == 0) { - return NullOpt; + return std::nullopt; } int64_t diff = rhs_offset - lhs_offset; @@ -1962,7 +1962,7 @@ PrimExpr RewriteSimplifier::Impl::ApplyRewriteRules(LT ret) { return lhs < rhs + make_const(rhs.dtype(), diff); } - return NullOpt; + return std::nullopt; }(); if (merge_constants) { return RecursiveRewrite(merge_constants.value()); diff --git a/src/arith/scalable_expression.h b/src/arith/scalable_expression.h index d31e81fffc97..70d753a299ef 100644 --- a/src/arith/scalable_expression.h +++ b/src/arith/scalable_expression.h @@ -83,7 +83,7 @@ bool CanProveVscaleExpressionFromKnownValues(arith::Analyzer* analyzer, const Pr * \param target The target to check. * \return Whether SVE is supported */ -bool TargetHasSVE(Optional target = NullOpt); +bool TargetHasSVE(Optional target = std::nullopt); } // namespace arith } // namespace tvm diff --git a/src/contrib/msc/core/codegen/code_stack.cc b/src/contrib/msc/core/codegen/code_stack.cc index 4b1c1850e76e..041ffe7091b2 100644 --- a/src/contrib/msc/core/codegen/code_stack.cc +++ b/src/contrib/msc/core/codegen/code_stack.cc @@ -64,7 +64,7 @@ void BaseStack::FuncDef(const String& func_name, const String& ret_type) { PushDoc(FunctionDoc(IdDoc(func_name), Array(), Array(), IdDoc(ret_type), Array())); } else { - PushDoc(FunctionDoc(IdDoc(func_name), Array(), Array(), NullOpt, + PushDoc(FunctionDoc(IdDoc(func_name), Array(), Array(), std::nullopt, Array())); } } @@ -214,13 +214,13 @@ void BaseStack::FuncCall(const String& callee, Optional assign_to, void BaseStack::FuncCall(const String& callee, const String& assign_to, const String& caller) { Optional assign_doc; if (assign_to.size() == 0) { - assign_doc = NullOpt; + assign_doc = std::nullopt; } else { assign_doc = IdDoc(assign_to); } Optional caller_doc; if (caller.size() == 0) { - caller_doc = NullOpt; + caller_doc = std::nullopt; } else { caller_doc = IdDoc(caller); } @@ -231,7 +231,7 @@ void BaseStack::MethodCall(const String& callee, bool new_line) { const auto& host = PopDoc(); if (host->IsInstance()) { const auto& v_callee = callee + (new_line ? DocSymbol::NextLine() : ""); - FuncCall(v_callee, NullOpt, Downcast(host)); + FuncCall(v_callee, std::nullopt, Downcast(host)); } else if (const auto* a_node = host.as()) { ICHECK(a_node->rhs.defined()) << "Can not find rhs for inplace host"; FuncCall(callee, DeclareDoc(a_node->annotation, a_node->lhs, Array(), true), @@ -411,7 +411,7 @@ void BaseStack::ScopeStart(const String& scope_def, const String& scope_ref) { if (scope_ref.size() > 0) { PushDoc(ScopeDoc(IdDoc(scope_ref), IdDoc(scope_def), Array())); } else { - PushDoc(ScopeDoc(NullOpt, IdDoc(scope_def), Array())); + PushDoc(ScopeDoc(std::nullopt, IdDoc(scope_def), Array())); } BlockStart(); } diff --git a/src/contrib/msc/core/codegen/code_stack.h b/src/contrib/msc/core/codegen/code_stack.h index e348bcdab1bf..ff4e6b58247a 100644 --- a/src/contrib/msc/core/codegen/code_stack.h +++ b/src/contrib/msc/core/codegen/code_stack.h @@ -157,7 +157,7 @@ class BaseStack { /*! \brief Push call and maybe assign Doc*/ void FuncCall(const String& callee, Optional assign_to, - Optional caller = NullOpt); + Optional caller = std::nullopt); void FuncCall(const String& callee, const String& assign_to = "", const String& caller = ""); /*! \brief Push method call Doc*/ @@ -165,7 +165,7 @@ class BaseStack { /*! \brief Push inplace call and maybe assign Doc*/ void InplaceStart(const String& callee, Optional assign_to, - Optional caller = NullOpt); + Optional caller = std::nullopt); void InplaceStart(const String& callee, const String& assign_to = "", const String& caller = ""); /*! \brief End inplace call*/ @@ -355,7 +355,7 @@ class BaseStack { return *this; \ } \ Stack& func_call(const String& callee, Optional assign_to, \ - Optional caller = NullOpt) { \ + Optional caller = std::nullopt) { \ FuncCall(callee, assign_to, caller); \ return *this; \ } \ @@ -369,7 +369,7 @@ class BaseStack { return *this; \ } \ Stack& inplace_start(const String& callee, Optional assign_to, \ - Optional caller = NullOpt) { \ + Optional caller = std::nullopt) { \ InplaceStart(callee, assign_to, caller); \ return *this; \ } \ diff --git a/src/contrib/msc/core/ir/graph.cc b/src/contrib/msc/core/ir/graph.cc index 14b2114236e5..26f46bd032af 100644 --- a/src/contrib/msc/core/ir/graph.cc +++ b/src/contrib/msc/core/ir/graph.cc @@ -78,7 +78,7 @@ const JsonMSCTensor MSCTensorNode::ToJson() const { void MSCTensorNode::FromJson(const JsonMSCTensor& j_tensor) { name = j_tensor.name; alias = j_tensor.alias; - dtype = DataType(runtime::StringToDLDataType(j_tensor.dtype)); + dtype = DataType(ffi::StringToDLDataType(j_tensor.dtype)); if (j_tensor.layout.size() > 0) { layout = tvm::tir::Layout(j_tensor.layout); } diff --git a/src/contrib/msc/core/ir/graph_builder.cc b/src/contrib/msc/core/ir/graph_builder.cc index 853f75216f1c..030df82dc6ee 100644 --- a/src/contrib/msc/core/ir/graph_builder.cc +++ b/src/contrib/msc/core/ir/graph_builder.cc @@ -124,7 +124,7 @@ void LayoutsFinder::VisitExpr_(const CallNode* call_node) { func = local_funcs_[call_node->op]; } if (func.defined()) { - const auto& layouts_opt = func->GetAttr>(msc_attr::kInputLayouts); + const auto& layouts_opt = func->GetAttr>(msc_attr::kInputLayouts); if (layouts_opt.defined()) { for (const auto& pair : layouts_opt.value()) { layouts_.Set(pair.first, pair.second); @@ -172,7 +172,7 @@ const MSCGraph GraphBuilder::Build(const Function& func) { if (expr_tensor_map_.count(f)) { LOG_INFO << "Replica tuple input " << f; } else if (const auto* f_node = f.as()) { - AddNode(f, NullOpt, f_node->name_hint()); + AddNode(f, std::nullopt, f_node->name_hint()); } else { LOG_FATAL << "Unexpected tuple input " << f << "(" << f->GetTypeKey() << ")"; } @@ -183,7 +183,7 @@ const MSCGraph GraphBuilder::Build(const Function& func) { } expr_tensor_map_.Set(p, tuple_names); } else { - AddNode(p, NullOpt, p->name_hint()); + AddNode(p, std::nullopt, p->name_hint()); } ICHECK(expr_tensor_map_.count(p)) << "Can not find func param " << p; for (const auto& name : expr_tensor_map_[p]) { @@ -339,7 +339,7 @@ const MSCJoint GraphBuilder::AddNode(const Expr& expr, const Optional& bin } else if (const auto* call_node = expr.as()) { if (const auto* v_node = call_node->op.as()) { const auto& func = Downcast(ref_module_->Lookup(v_node->name_hint)); - const auto& name_opt = func->GetAttr(relax::attr::kComposite); + const auto& name_opt = func->GetAttr(relax::attr::kComposite); if (name_opt.defined()) { attrs = FuncAttrGetter().GetAttrs(func); } @@ -553,7 +553,7 @@ const MSCJoint GraphBuilder::AddNode(const Expr& expr, const Optional& bin } else if (const auto* s_sinfo = sinfo.as()) { Array shape{s_sinfo->ndim}; const auto& t_name = node_name + ":" + std::to_string(0); - const auto& dtype = DataType(runtime::StringToDLDataType("int32")); + const auto& dtype = DataType(ffi::StringToDLDataType("int32")); outputs.push_back(MSCTensor(t_name, dtype, layouts[0], shape)); } else if (const auto* tuple_sinfo = sinfo.as()) { size_t field_size = optype == "nn.batch_norm" ? 1 : num_output; @@ -757,7 +757,7 @@ void GraphBuilder::VisitBinding_(const VarBindingNode* binding, const DataflowVa } void GraphBuilder::VisitBinding_(const VarBindingNode* binding, const FunctionNode* val) { - const auto& name_opt = val->GetAttr(relax::attr::kComposite); + const auto& name_opt = val->GetAttr(relax::attr::kComposite); ICHECK(name_opt.defined()) << "Unexpected target func without composite"; ICHECK(config_.target.size() > 0 && StringUtils::StartsWith(name_opt.value(), config_.target)) << "Target should be given for target function"; @@ -766,15 +766,15 @@ void GraphBuilder::VisitBinding_(const VarBindingNode* binding, const FunctionNo const std::tuple GraphBuilder::ParseFunc(const Function& func) { String node_name, optype, layout; - const auto& name_opt = func->GetAttr(msc_attr::kUnique); + const auto& name_opt = func->GetAttr(msc_attr::kUnique); // get node_name if (name_opt.defined()) { node_name = name_opt.value(); } // get optype - const auto& codegen_opt = func->GetAttr(relax::attr::kCodegen); - const auto& optype_opt = func->GetAttr(msc_attr::kOptype); - const auto& composite_opt = func->GetAttr(relax::attr::kComposite); + const auto& codegen_opt = func->GetAttr(relax::attr::kCodegen); + const auto& optype_opt = func->GetAttr(msc_attr::kOptype); + const auto& composite_opt = func->GetAttr(relax::attr::kComposite); if (codegen_opt.defined()) { optype = codegen_opt.value(); } else if (optype_opt.defined()) { @@ -786,7 +786,7 @@ const std::tuple GraphBuilder::ParseFunc(const Function& } } // get layout - const auto& layout_opt = func->GetAttr(msc_attr::kLayout); + const auto& layout_opt = func->GetAttr(msc_attr::kLayout); if (layout_opt.defined()) { layout = layout_opt.value(); } diff --git a/src/contrib/msc/core/ir/graph_builder.h b/src/contrib/msc/core/ir/graph_builder.h index 00582fab4b00..4eac04349728 100644 --- a/src/contrib/msc/core/ir/graph_builder.h +++ b/src/contrib/msc/core/ir/graph_builder.h @@ -273,7 +273,7 @@ class GraphBuilder : public ExprVisitor { const MSCRBuildConfig config() { return config_; } /*! \brief Create and add MSCJoint from expr*/ - const MSCJoint AddNode(const Expr& expr, const Optional& binding_var = NullOpt, + const MSCJoint AddNode(const Expr& expr, const Optional& binding_var = std::nullopt, const String& name = ""); /*! \brief Create and add MSCPrim from prim*/ diff --git a/src/contrib/msc/core/printer/msc_base_printer.cc b/src/contrib/msc/core/printer/msc_base_printer.cc index 838d284d131f..0f0b24fd3a28 100644 --- a/src/contrib/msc/core/printer/msc_base_printer.cc +++ b/src/contrib/msc/core/printer/msc_base_printer.cc @@ -113,7 +113,7 @@ void MSCBasePrinter::PrintTypedDoc(const LiteralDoc& doc) { } else { output_ << float_imm->value; } - } else if (const auto* string_obj = value.as()) { + } else if (const auto* string_obj = value.as()) { output_ << "\"" << tvm::support::StrEscape(string_obj->data, string_obj->size) << "\""; } else { LOG(FATAL) << "TypeError: Unsupported literal value type: " << value.GetTypeKey(); diff --git a/src/contrib/msc/core/printer/print_utils.cc b/src/contrib/msc/core/printer/print_utils.cc index 95df8da85cb2..234ca3aec9c3 100644 --- a/src/contrib/msc/core/printer/print_utils.cc +++ b/src/contrib/msc/core/printer/print_utils.cc @@ -32,7 +32,7 @@ const String DocSymbol::Empty() { return "::EMPTY"; } const String DocSymbol::NextLine() { return "::NEXT_LINE"; } -const ExprDoc DocUtils::ToDoc(int64_t val) { return LiteralDoc::Int(val, NullOpt); } +const ExprDoc DocUtils::ToDoc(int64_t val) { return LiteralDoc::Int(val, std::nullopt); } const ExprDoc DocUtils::ToDoc(int val) { return ToDoc(static_cast(val)); } @@ -42,7 +42,7 @@ const ExprDoc DocUtils::ToDoc(const IntImm& val) { return ToDoc(val->value); } const ExprDoc DocUtils::ToDoc(const Integer& val) { return ToDoc(val->value); } -const ExprDoc DocUtils::ToDoc(double val) { return LiteralDoc::Float(val, NullOpt); } +const ExprDoc DocUtils::ToDoc(double val) { return LiteralDoc::Float(val, std::nullopt); } const ExprDoc DocUtils::ToDoc(float val) { return ToDoc(static_cast(val)); } @@ -52,11 +52,11 @@ const ExprDoc DocUtils::ToDoc(const char* val) { return IdDoc(std::string(val)); const ExprDoc DocUtils::ToDoc(const String& val) { return IdDoc(val); } -const ExprDoc DocUtils::ToDoc(bool val) { return LiteralDoc::Boolean(val, NullOpt); } +const ExprDoc DocUtils::ToDoc(bool val) { return LiteralDoc::Boolean(val, std::nullopt); } const ExprDoc DocUtils::ToDoc(const ExprDoc& val) { return val; } -const ExprDoc DocUtils::ToStr(const String& val) { return LiteralDoc::Str(val, NullOpt); } +const ExprDoc DocUtils::ToStr(const String& val) { return LiteralDoc::Str(val, std::nullopt); } const PointerDoc DocUtils::ToPtr(const String& val) { return PointerDoc(val); } diff --git a/src/contrib/msc/core/printer/print_utils.h b/src/contrib/msc/core/printer/print_utils.h index 17d4b0b077a6..b3949d54a762 100644 --- a/src/contrib/msc/core/printer/print_utils.h +++ b/src/contrib/msc/core/printer/print_utils.h @@ -83,7 +83,7 @@ class DocUtils { bool use_constructor = true) { Optional type_doc; if (type.size() == 0) { - type_doc = NullOpt; + type_doc = std::nullopt; } else { type_doc = IdDoc(type); } @@ -103,7 +103,7 @@ class DocUtils { TVM_DLL static const AssignDoc ToAssign(const LT& lhs, const RT& rhs, const String& annotation = "") { if (annotation.size() == 0) { - return AssignDoc(ToDoc(lhs), ToDoc(rhs), NullOpt); + return AssignDoc(ToDoc(lhs), ToDoc(rhs), std::nullopt); } return AssignDoc(ToDoc(lhs), ToDoc(rhs), IdDoc(annotation)); } @@ -114,13 +114,13 @@ class DocUtils { if (rhs.size() > 0) { rhs_doc = IdDoc(rhs); } else { - rhs_doc = NullOpt; + rhs_doc = std::nullopt; } Optional annotation_doc; if (annotation.size() > 0) { annotation_doc = IdDoc(annotation); } else { - annotation_doc = NullOpt; + annotation_doc = std::nullopt; } return AssignDoc(ToDoc(lhs), rhs_doc, annotation_doc); } diff --git a/src/contrib/msc/core/printer/prototxt_printer.cc b/src/contrib/msc/core/printer/prototxt_printer.cc index 06a70a5498c1..44a915ae7b8d 100644 --- a/src/contrib/msc/core/printer/prototxt_printer.cc +++ b/src/contrib/msc/core/printer/prototxt_printer.cc @@ -31,16 +31,16 @@ namespace contrib { namespace msc { LiteralDoc PrototxtPrinter::ToLiteralDoc(const ObjectRef& obj) { - if (obj.as()) { - return LiteralDoc::Str(Downcast(obj), NullOpt); + if (obj.as()) { + return LiteralDoc::Str(Downcast(obj), std::nullopt); } else if (obj.as()) { - return LiteralDoc::Int(Downcast(obj)->value, NullOpt); + return LiteralDoc::Int(Downcast(obj)->value, std::nullopt); } else if (obj.as()) { - return LiteralDoc::Float(Downcast(obj)->value, NullOpt); + return LiteralDoc::Float(Downcast(obj)->value, std::nullopt); } std::ostringstream obj_des; obj_des << obj; - return LiteralDoc::Str(obj_des.str(), NullOpt); + return LiteralDoc::Str(obj_des.str(), std::nullopt); } DictDoc PrototxtPrinter::ToDictDoc(const Map& dict) { diff --git a/src/contrib/msc/core/transform/fuse_tuple.cc b/src/contrib/msc/core/transform/fuse_tuple.cc index ef7fafbe164c..1bcbe076fc59 100644 --- a/src/contrib/msc/core/transform/fuse_tuple.cc +++ b/src/contrib/msc/core/transform/fuse_tuple.cc @@ -53,7 +53,7 @@ class TupleFuser : public ExprMutator { if (gv->name_hint == entry_name_) { main_var = gv; } else { - const auto& name_opt = func->GetAttr(attr::kComposite); + const auto& name_opt = func->GetAttr(attr::kComposite); if (name_opt.defined() && StringUtils::StartsWith(name_opt.value(), target_)) { target_funcs_.Set(gv, Downcast(func)); } @@ -74,8 +74,7 @@ class TupleFuser : public ExprMutator { const auto& arg = val->args[i]; if (arg->IsInstance()) { String tuple_name; - const auto& name_opt = - target_funcs_[val->op]->GetAttr(msc_attr::kUnique); + const auto& name_opt = target_funcs_[val->op]->GetAttr(msc_attr::kUnique); if (name_opt.defined()) { if (val->args.size() == 1) { tuple_name = name_opt.value() + "_input"; @@ -185,19 +184,19 @@ class TupleFuser : public ExprMutator { func_attrs.Set(attr::kComposite, target_ + func_name); func_attrs.Set(msc_attr::kUnique, SpanUtils::GetAttr(expr_span, msc_attr::kName)); - Function function = Function(/*params=*/params, // - /*body=*/body, // - /*ret_struct_info=*/NullOpt, // - /*is_pure=*/true, // + Function function = Function(/*params=*/params, // + /*body=*/body, // + /*ret_struct_info=*/std::nullopt, // + /*is_pure=*/true, // /*attrs=*/DictAttrs(func_attrs)); Array free_vars = FreeSymbolicVars(function).Map([](const tir::Var& var) -> PrimExpr { return var; }); if (!free_vars.empty()) { params.push_back(Var("tir_vars", ShapeStructInfo(free_vars))); - function = Function(/*params=*/params, // - /*body=*/body, // - /*ret_struct_info=*/NullOpt, // - /*is_pure=*/true, // + function = Function(/*params=*/params, // + /*body=*/body, // + /*ret_struct_info=*/std::nullopt, // + /*is_pure=*/true, // /*attrs=*/DictAttrs(func_attrs)); } function = SymbolicVarRenewMutator::Renew(function); diff --git a/src/contrib/msc/core/transform/inline_params.cc b/src/contrib/msc/core/transform/inline_params.cc index aa07c4b66631..e892d3b36a42 100644 --- a/src/contrib/msc/core/transform/inline_params.cc +++ b/src/contrib/msc/core/transform/inline_params.cc @@ -61,7 +61,7 @@ class ParamsInliner : public ExprMutator { continue; } if (struct_info->IsInstance()) { - const auto& optype_opt = func->GetAttr(msc_attr::kOptype); + const auto& optype_opt = func->GetAttr(msc_attr::kOptype); ICHECK(optype_opt.defined()) << "Can not find attr " << msc_attr::kOptype << " form extern func"; extern_types_.Set(p, optype_opt.value()); diff --git a/src/contrib/msc/core/transform/rewrite_utils.cc b/src/contrib/msc/core/transform/rewrite_utils.cc index 20e4821e6fa7..9cbc7c1a8c51 100644 --- a/src/contrib/msc/core/transform/rewrite_utils.cc +++ b/src/contrib/msc/core/transform/rewrite_utils.cc @@ -44,7 +44,7 @@ Expr RewriteUtils::MakeConstant(BlockBuilder builder, const String& name, double const DataType& dtype, size_t ndim) { const auto& data = support::FloatImmToNDArray(FloatImm(dtype, value)); Span span = SpanUtils::CreateWithAttr(msc_attr::kName, name); - const auto& constant = Constant(data, NullOpt, span); + const auto& constant = Constant(data, std::nullopt, span); if (ndim == 0) { return constant; } diff --git a/src/contrib/msc/core/transform/set_byoc_attrs.cc b/src/contrib/msc/core/transform/set_byoc_attrs.cc index b7bbbcac46c5..6f3a29346bfd 100644 --- a/src/contrib/msc/core/transform/set_byoc_attrs.cc +++ b/src/contrib/msc/core/transform/set_byoc_attrs.cc @@ -53,7 +53,7 @@ class ByocNameSetter : public ExprMutator { if (gv->name_hint == entry_name_) { continue; } - const auto& name_opt = func->GetAttr(attr::kCodegen); + const auto& name_opt = func->GetAttr(attr::kCodegen); if (name_opt.defined() && name_opt.value() == target_) { const String& func_name = target_ + "_" + std::to_string(func_cnt); const auto& new_func = Downcast(VisitExpr(func)); @@ -73,7 +73,7 @@ class ByocNameSetter : public ExprMutator { ExprMutator::VisitBinding_(binding, val); if (val->op->IsInstance()) { ICHECK(local_funcs_.count(val->op)) << "Can not find local func " << val->op; - const auto& name_opt = local_funcs_[val->op]->GetAttr(msc_attr::kUnique); + const auto& name_opt = local_funcs_[val->op]->GetAttr(msc_attr::kUnique); if (name_opt.defined()) { val->span = SpanUtils::SetAttr(val->span, "name", name_opt.value()); } diff --git a/src/contrib/msc/core/transform/set_expr_name.cc b/src/contrib/msc/core/transform/set_expr_name.cc index b3b9fbaa2400..4c36e2ba2754 100644 --- a/src/contrib/msc/core/transform/set_expr_name.cc +++ b/src/contrib/msc/core/transform/set_expr_name.cc @@ -158,7 +158,7 @@ class RelaxExprNameSetter : public ExprVisitor { void VisitBinding_(const VarBindingNode* binding, const FunctionNode* val) { ExprVisitor::VisitBinding_(binding, val); - const auto& name_opt = val->GetAttr(attr::kComposite); + const auto& name_opt = val->GetAttr(attr::kComposite); if (name_opt.defined()) { local_funcs_.Set(binding->var, GetRef(val)); } @@ -257,8 +257,8 @@ class RelaxExprNameSetter : public ExprVisitor { const String GetFuncType(const Function& func) { String optype; - const auto& comp_opt = func->GetAttr(attr::kComposite); - const auto& code_opt = func->GetAttr(attr::kCodegen); + const auto& comp_opt = func->GetAttr(attr::kComposite); + const auto& code_opt = func->GetAttr(attr::kCodegen); if (comp_opt.defined()) { optype = comp_opt.value(); } else if (code_opt.defined()) { @@ -275,7 +275,7 @@ class RelaxExprNameSetter : public ExprVisitor { const String GetFuncName(const Call& call, const Function& func) { String name; // get from unique - const auto& name_opt = func->GetAttr(msc_attr::kUnique); + const auto& name_opt = func->GetAttr(msc_attr::kUnique); if (name_opt.defined()) { return name_opt.value(); } diff --git a/src/contrib/msc/core/utils.cc b/src/contrib/msc/core/utils.cc index ff2cb30c3b6a..3c53e32170c3 100644 --- a/src/contrib/msc/core/utils.cc +++ b/src/contrib/msc/core/utils.cc @@ -263,13 +263,13 @@ const String StringUtils::ToString(const runtime::ObjectRef& obj) { String obj_string; if (!obj.defined()) { obj_string = ""; - } else if (obj.as()) { + } else if (obj.as()) { obj_string = Downcast(obj); } else if (const auto* n = obj.as()) { obj_string = std::to_string(n->value); } else if (const auto* n = obj.as()) { obj_string = std::to_string(n->value); - } else if (const auto* n = obj.as()) { + } else if (const auto* n = obj.as()) { for (size_t i = 0; i < n->size(); i++) { obj_string = obj_string + ToString((*n)[i].cast()); if (n->size() == 1 || i < n->size() - 1) { diff --git a/src/contrib/msc/framework/tensorflow/tf_v1_opcode.cc b/src/contrib/msc/framework/tensorflow/tf_v1_opcode.cc index 9c8f0aeb860a..570088ee35c2 100644 --- a/src/contrib/msc/framework/tensorflow/tf_v1_opcode.cc +++ b/src/contrib/msc/framework/tensorflow/tf_v1_opcode.cc @@ -173,7 +173,7 @@ class TFV1BatchnormCodeGen : public TFV1OpCode { for (size_t i = 0; i < weight_names.size(); i++) { const auto& w_doc = DocUtils::ToStr(node()->WeightAt(weight_names[i])->name); stack_.inplace_start("tf_v1.constant_initializer", init_names[i] + "_initializer") - .inplace_start("asnumpy", NullOpt, DocUtils::ToIndex("weights", w_doc)) + .inplace_start("asnumpy", std::nullopt, DocUtils::ToIndex("weights", w_doc)) .inplace_end() .inplace_end(); } diff --git a/src/contrib/msc/framework/tensorrt/codegen.cc b/src/contrib/msc/framework/tensorrt/codegen.cc index 8992d3713aa6..0271b63112c9 100644 --- a/src/contrib/msc/framework/tensorrt/codegen.cc +++ b/src/contrib/msc/framework/tensorrt/codegen.cc @@ -136,7 +136,7 @@ void TensorRTCodeGen::CodeGenClassDefine() { stack_.comment("Mark outputs"); for (const auto& o : graph()->GetOutputs()) { const auto& pair = graph()->FindProducerAndIdx(o); - stack_.func_call("markOutput", NullOpt, DocUtils::ToPtr("network")) + stack_.func_call("markOutput", std::nullopt, DocUtils::ToPtr("network")) .call_arg("*" + IdxOutputBase(pair.first, pair.second)); } // mark batch_size @@ -146,7 +146,7 @@ void TensorRTCodeGen::CodeGenClassDefine() { Array batch_flags{"MIN", "MAX", "OPT"}; for (const auto& i : graph()->GetInputs()) { for (const auto& f : batch_flags) { - stack_.func_call("setDimensions", NullOpt, DocUtils::ToPtr("profile")) + stack_.func_call("setDimensions", std::nullopt, DocUtils::ToPtr("profile")) .call_arg(DocUtils::ToStr(i->name)) .call_arg("OptProfileSelector::k" + f) .call_arg(ToDims(i->shape)); @@ -155,10 +155,10 @@ void TensorRTCodeGen::CodeGenClassDefine() { // set max workspace stack_.comment("Set max worksapce"); if (CompareVersion(6, 0, 0) >= 0) { - stack_.func_call("setMaxWorkspaceSize", NullOpt, DocUtils::ToPtr("config")) + stack_.func_call("setMaxWorkspaceSize", std::nullopt, DocUtils::ToPtr("config")) .call_arg(config()->max_workspace); } else { - stack_.func_call("setMaxWorkspaceSize", NullOpt, DocUtils::ToPtr("builder")) + stack_.func_call("setMaxWorkspaceSize", std::nullopt, DocUtils::ToPtr("builder")) .call_arg(config()->max_workspace); } // set data type @@ -169,10 +169,10 @@ void TensorRTCodeGen::CodeGenClassDefine() { .call_arg("ILogger::Severity::kINTERNAL_ERROR") .call_arg(DocUtils::ToStr("platform do not support float16, fallback to float32")) .cond_else() - .func_call("setFlag", NullOpt, DocUtils::ToPtr("config")) + .func_call("setFlag", std::nullopt, DocUtils::ToPtr("config")) .call_arg("BuilderFlag::kFP16"); if (config()->precision_mode == "strict") { - stack_.func_call("setFlag", NullOpt, DocUtils::ToPtr("config")) + stack_.func_call("setFlag", std::nullopt, DocUtils::ToPtr("config")) .call_arg("BuilderFlag::kSTRICT_TYPES"); } stack_.func_call("log", "", "logger") @@ -186,16 +186,16 @@ void TensorRTCodeGen::CodeGenClassDefine() { .call_arg("ILogger::Severity::kINTERNAL_ERROR") .call_arg(DocUtils::ToStr("platform do not support int8, fallback to float32")) .cond_else() - .func_call("setFlag", NullOpt, DocUtils::ToPtr("config")) + .func_call("setFlag", std::nullopt, DocUtils::ToPtr("config")) .call_arg("BuilderFlag::kINT8"); if (config()->precision_mode == "strict") { - stack_.func_call("setFlag", NullOpt, DocUtils::ToPtr("config")) + stack_.func_call("setFlag", std::nullopt, DocUtils::ToPtr("config")) .call_arg("BuilderFlag::kSTRICT_TYPES"); } else if (config()->precision_mode == "prefer") { - stack_.func_call("setFlag", NullOpt, DocUtils::ToPtr("config")) + stack_.func_call("setFlag", std::nullopt, DocUtils::ToPtr("config")) .call_arg("BuilderFlag::kPREFER_PRECISION_CONSTRAINTS"); } else if (config()->precision_mode == "obey") { - stack_.func_call("setFlag", NullOpt, DocUtils::ToPtr("config")) + stack_.func_call("setFlag", std::nullopt, DocUtils::ToPtr("config")) .call_arg("BuilderFlag::kOBEY_PRECISION_CONSTRAINTS"); } stack_.func_call("log", "", "logger") @@ -219,7 +219,7 @@ void TensorRTCodeGen::CodeGenClassDefine() { .func_start(); stack_.comment("Create context") .func_call("TRTPtr", DocUtils::ToDeclare("auto", "context")) - .func_call("createExecutionContext", NullOpt, DocUtils::ToPtr("engine")) + .func_call("createExecutionContext", std::nullopt, DocUtils::ToPtr("engine")) .pop_nest(); ReturnOnFail("context", "Failed to create the context"); // prepare variables @@ -262,7 +262,7 @@ void TensorRTCodeGen::CodeGenClassDefine() { stack_.func_call("cudaStreamSynchronize") .call_arg("stream") .comment("enquque with gpu buffers") - .func_call("enqueueV2", NullOpt, DocUtils::ToPtr("context")) + .func_call("enqueueV2", std::nullopt, DocUtils::ToPtr("context")) .call_arg("gpu_buffers") .call_arg("stream") .call_arg("nullptr") @@ -350,18 +350,18 @@ void TensorRTCodeGen::CodeGenMain() { "1U << static_cast(NetworkDefinitionCreationFlag::kEXPLICIT_BATCH)", "uint32_t") .func_call("TRTPtr", DocUtils::ToDeclare("auto", "network")) - .func_call("createNetworkV2", NullOpt, DocUtils::ToPtr("builder")) + .func_call("createNetworkV2", std::nullopt, DocUtils::ToPtr("builder")) .call_arg("flags") .pop_nest(); } else { stack_.func_call("TRTPtr", DocUtils::ToDeclare("auto", "network")) - .func_call("createNetwork", NullOpt, DocUtils::ToPtr("builder")) + .func_call("createNetwork", std::nullopt, DocUtils::ToPtr("builder")) .pop_nest(); } ReturnOnFail("network", "Failed to create network"); // create config stack_.func_call("TRTPtr", DocUtils::ToDeclare("auto", "config")) - .func_call("createBuilderConfig", NullOpt, DocUtils::ToPtr("builder")) + .func_call("createBuilderConfig", std::nullopt, DocUtils::ToPtr("builder")) .pop_nest(); ReturnOnFail("config", "Failed to create config"); // add codegen before build @@ -395,7 +395,7 @@ void TensorRTCodeGen::CodeGenMain() { .assign("profile_verbose", "ProfilingVerbosity::kNONE") .cond_end() .cond_end() - .func_call("setProfilingVerbosity", NullOpt, DocUtils::ToPtr("config")) + .func_call("setProfilingVerbosity", std::nullopt, DocUtils::ToPtr("config")) .call_arg("profile_verbose"); // Serialize engine stack_.comment("Serialize engine") @@ -422,7 +422,7 @@ void TensorRTCodeGen::CodeGenMain() { stack_.comment("Dump info by inspector") .cond_if("profile_level > 0") .func_call("TRTPtr", DocUtils::ToDeclare("auto", "inspector")) - .func_call("createEngineInspector", NullOpt, DocUtils::ToPtr("engine")) + .func_call("createEngineInspector", std::nullopt, DocUtils::ToPtr("engine")) .pop_nest() .func_call("getEngineInformation", DocUtils::ToDeclare("std::string", "result"), DocUtils::ToPtr("inspector")) @@ -601,7 +601,7 @@ Array MSCTensorRTCompiler(Array functions, Array compiled_functions; for (const auto& func : functions) { VLOG(1) << "MSC.TensorRT partition:" << std::endl << func; - const auto& name_opt = func->GetAttr(msc_attr::kUnique); + const auto& name_opt = func->GetAttr(msc_attr::kUnique); ICHECK(name_opt.defined()) << "Can not find " << msc_attr::kUnique << " from attrs"; const auto& name = name_opt.value(); std::string func_name = GetExtSymbol(func); diff --git a/src/contrib/msc/framework/tensorrt/tensorrt_opcode.cc b/src/contrib/msc/framework/tensorrt/tensorrt_opcode.cc index d90cdc35d17d..5a63ecbc7d06 100644 --- a/src/contrib/msc/framework/tensorrt/tensorrt_opcode.cc +++ b/src/contrib/msc/framework/tensorrt/tensorrt_opcode.cc @@ -36,16 +36,16 @@ const Array TensorRTOpCode::GetDocs() { CodeGenBuild(); if (node()->optype == "tuple") { for (size_t i = 0; i < node()->outputs.size(); i++) { - stack_.func_call("setName", NullOpt, DocUtils::ToPtr(IdxOutput(i))) + stack_.func_call("setName", std::nullopt, DocUtils::ToPtr(IdxOutput(i))) .call_arg(DocUtils::ToStr(node()->OutputAt(i)->name)); } } else if (node()->optype == "get_item") { - stack_.func_call("setName", NullOpt, DocUtils::ToPtr(IdxNode())) + stack_.func_call("setName", std::nullopt, DocUtils::ToPtr(IdxNode())) .call_arg(DocUtils::ToStr(node()->OutputAt(0)->name)); } else if (node()->optype != "input") { SetLayerByValue("Name", DocUtils::ToStr(node()->name)); for (size_t i = 0; i < node()->outputs.size(); i++) { - stack_.func_call("setName", NullOpt, DocUtils::ToPtr(IdxOutput(i))) + stack_.func_call("setName", std::nullopt, DocUtils::ToPtr(IdxOutput(i))) .call_arg(DocUtils::ToStr(node()->OutputAt(i)->name)); } } @@ -157,29 +157,29 @@ const size_t TensorRTOpCode::AttrToAxis(const String& key, size_t ndim) { template void TensorRTOpCode::SetLayerByAttr(const String& method, const String& key) { - stack_.func_call("set" + method, NullOpt, DocUtils::ToPtr(IdxNode())).op_arg(key, ""); + stack_.func_call("set" + method, std::nullopt, DocUtils::ToPtr(IdxNode())).op_arg(key, ""); } template void TensorRTOpCode::SetLayerByValue(const String& method, const T& value) { - stack_.func_call("set" + method, NullOpt, DocUtils::ToPtr(IdxNode())).call_arg(value); + stack_.func_call("set" + method, std::nullopt, DocUtils::ToPtr(IdxNode())).call_arg(value); } void TensorRTOpCode::SetLayerByDimsAttr(const String& method, const String& key, bool use_ndim) { - stack_.func_call("set" + method, NullOpt, DocUtils::ToPtr(IdxNode())) + stack_.func_call("set" + method, std::nullopt, DocUtils::ToPtr(IdxNode())) .call_arg(AttrToDims(key, use_ndim)); } template void TensorRTOpCode::SetLayerByDimsValue(const String& method, const std::vector& value, bool use_ndim) { - stack_.func_call("set" + method, NullOpt, DocUtils::ToPtr(IdxNode())) + stack_.func_call("set" + method, std::nullopt, DocUtils::ToPtr(IdxNode())) .call_arg(ToDims(value, use_ndim)); } void TensorRTOpCode::SetLayerByDimsValue(const String& method, const Array& value, bool use_ndim) { - stack_.func_call("set" + method, NullOpt, DocUtils::ToPtr(IdxNode())) + stack_.func_call("set" + method, std::nullopt, DocUtils::ToPtr(IdxNode())) .call_arg(ToDims(value, use_ndim)); } @@ -269,7 +269,7 @@ class TensorRTAstypeCodeGen : public TensorRTOpCode { void CodeGenBuild() final { stack_.op_call() .op_input_arg() - .func_call("setOutputType", NullOpt, DocUtils::ToPtr(IdxNode())) + .func_call("setOutputType", std::nullopt, DocUtils::ToPtr(IdxNode())) .call_arg(0) .op_dtype_arg(node()->OutputAt(0)->dtype); } diff --git a/src/contrib/msc/framework/tensorrt/transform_tensorrt.cc b/src/contrib/msc/framework/tensorrt/transform_tensorrt.cc index 1131b82172a0..fc0e538252ca 100644 --- a/src/contrib/msc/framework/tensorrt/transform_tensorrt.cc +++ b/src/contrib/msc/framework/tensorrt/transform_tensorrt.cc @@ -795,7 +795,7 @@ Expr RewriteSplit(BlockBuilder builder, const Var& var, const Call& src_call, split_begins.push_back(i * size); split_ends.push_back(i * size + size); } - } else if (src_attrs->indices_or_sections->IsInstance()) { + } else if (src_attrs->indices_or_sections->IsInstance()) { const auto& indices = Downcast>(src_attrs->indices_or_sections); int64_t last_index = 0; for (size_t i = 0; i < indices.size(); ++i) { diff --git a/src/contrib/msc/plugin/tensorrt_codegen.cc b/src/contrib/msc/plugin/tensorrt_codegen.cc index e54b9eedfea8..d16bb5d92440 100644 --- a/src/contrib/msc/plugin/tensorrt_codegen.cc +++ b/src/contrib/msc/plugin/tensorrt_codegen.cc @@ -769,8 +769,8 @@ void TensorRTPluginCodeGen::CodegenCreator(const Plugin& plugin, bool dynamic, b stack_.call_arg(DocUtils::ToAttrAccess("meta_attr", a->name)); } stack_.call_arg("layouts") - .func_call("setPluginNamespace", NullOpt, DocUtils::ToPtr("plugin")) - .inplace_start("c_str", NullOpt, DocUtils::ToDoc("name_space_")) + .func_call("setPluginNamespace", std::nullopt, DocUtils::ToPtr("plugin")) + .inplace_start("c_str", std::nullopt, DocUtils::ToDoc("name_space_")) .inplace_end() .func_end("plugin"); // deserializePlugin @@ -784,8 +784,8 @@ void TensorRTPluginCodeGen::CodegenCreator(const Plugin& plugin, bool dynamic, b .call_arg("name") .call_arg("data") .call_arg("length") - .func_call("setPluginNamespace", NullOpt, DocUtils::ToPtr("plugin")) - .inplace_start("c_str", NullOpt, DocUtils::ToDoc("name_space_")) + .func_call("setPluginNamespace", std::nullopt, DocUtils::ToPtr("plugin")) + .inplace_start("c_str", std::nullopt, DocUtils::ToDoc("name_space_")) .inplace_end() .func_end("plugin"); } diff --git a/src/contrib/msc/plugin/torch_codegen.cc b/src/contrib/msc/plugin/torch_codegen.cc index 75471d85db0d..215341af0133 100644 --- a/src/contrib/msc/plugin/torch_codegen.cc +++ b/src/contrib/msc/plugin/torch_codegen.cc @@ -430,7 +430,7 @@ void TorchPluginCodeGen::CodeGenMalloc(const Plugin& plugin, const ArrayFindDeviceRefIdx(tensors[i]); if (device_idx >= 0) { const auto& input_doc = DocUtils::ToIndex("input_tensors", device_idx); - stack_.inplace_start("device", NullOpt, input_doc).inplace_end(); + stack_.inplace_start("device", std::nullopt, input_doc).inplace_end(); } else { stack_.inplace_start("TorchUtils::ToTorchDevice") .call_arg(DocUtils::ToStr(tensors[i]->device)) diff --git a/src/ir/attr_functor.h b/src/ir/attr_functor.h index ae2675643113..ecabc9bfb2cc 100644 --- a/src/ir/attr_functor.h +++ b/src/ir/attr_functor.h @@ -75,7 +75,7 @@ class AttrFunctor { } } virtual R VisitAttrDefault_(const Object* node, Args... args) = 0; - virtual R VisitAttr_(const ArrayObj* op, Args... args) ATTR_FUNCTOR_DEFAULT; + virtual R VisitAttr_(const ffi::ArrayObj* op, Args... args) ATTR_FUNCTOR_DEFAULT; virtual R VisitAttr_(const tir::IntImmNode* op, Args... args) ATTR_FUNCTOR_DEFAULT; virtual R VisitAttr_(const tir::FloatImmNode* op, Args... args) ATTR_FUNCTOR_DEFAULT; virtual R VisitAttr_(const tir::StringImmNode* op, Args... args) ATTR_FUNCTOR_DEFAULT; @@ -112,7 +112,7 @@ class AttrFunctor { using namespace tir; FType vtable; // Set dispatch - ATTR_FUNCTOR_DISPATCH(ArrayObj); + ATTR_FUNCTOR_DISPATCH(ffi::ArrayObj); ATTR_FUNCTOR_DISPATCH(IntImmNode); ATTR_FUNCTOR_DISPATCH(FloatImmNode); ATTR_FUNCTOR_DISPATCH(StringImmNode); diff --git a/src/ir/module.cc b/src/ir/module.cc index 02e353c8a6c6..0223aef4d15b 100644 --- a/src/ir/module.cc +++ b/src/ir/module.cc @@ -20,12 +20,12 @@ * \file module.cc * \brief The global module in TVM. */ +#include #include #include #include #include #include -#include #include #include @@ -250,7 +250,7 @@ TVM_REGISTER_GLOBAL("ir.IRModule") return DictAttrs(); } else if (auto* as_dict_attrs = attrs.as()) { return GetRef(as_dict_attrs); - } else if (attrs.as()) { + } else if (attrs.as()) { return tvm::DictAttrs(Downcast>(attrs)); } else { LOG(FATAL) << "Expected attrs argument to be either DictAttrs or Map"; diff --git a/src/ir/replace_global_vars.cc b/src/ir/replace_global_vars.cc index 48e7abe5618a..44a6a22db7a0 100644 --- a/src/ir/replace_global_vars.cc +++ b/src/ir/replace_global_vars.cc @@ -22,8 +22,8 @@ * \brief IRModule transform to replace GlobalVar instances across any IR type. */ +#include #include -#include #include diff --git a/src/ir/transform.cc b/src/ir/transform.cc index 0730faa7b4d7..44dafcbf1d9e 100644 --- a/src/ir/transform.cc +++ b/src/ir/transform.cc @@ -87,7 +87,7 @@ PassContext PassContext::Current() { } // linearly scan the pass array to match pass_name -bool PassArrayContains(const Array& pass_array, const std::string& pass_name) { +bool PassArrayContains(const Array& pass_array, const std::string& pass_name) { for (auto x : pass_array) { if (x == pass_name) return true; } @@ -378,8 +378,7 @@ class ModulePass : public Pass { TVM_DEFINE_OBJECT_REF_METHODS(ModulePass, Pass, ModulePassNode); }; -PassInfo::PassInfo(int opt_level, String name, tvm::Array required, - bool traceable) { +PassInfo::PassInfo(int opt_level, String name, tvm::Array required, bool traceable) { auto pass_info = make_object(); pass_info->opt_level = opt_level; pass_info->name = std::move(name); @@ -591,7 +590,7 @@ TVM_REGISTER_GLOBAL("transform.Sequential") auto passes = args[0].cast>(); int opt_level = args[1].cast(); std::string name = args[2].cast(); - auto required = args[3].cast>(); + auto required = args[3].cast>(); bool traceable = args[4].cast(); PassInfo pass_info = PassInfo(opt_level, name, required, /* traceable */ traceable); *ret = Sequential(passes, pass_info); diff --git a/src/meta_schedule/arg_info.cc b/src/meta_schedule/arg_info.cc index ad3966ed1e72..bc0fef1ff4a7 100644 --- a/src/meta_schedule/arg_info.cc +++ b/src/meta_schedule/arg_info.cc @@ -67,9 +67,9 @@ ArgInfo ArgInfo::FromJSON(const ObjectRef& json_obj) { // The JSON object is always an array whose first element is a tag. For example: // `['TENSOR', 'float32', [1, 224, 224, 3]] // Step 1. Extract the tag - String tag{runtime::ObjectPtr(nullptr)}; + String tag{ffi::ObjectPtr(nullptr)}; try { - const ArrayObj* json_array = json_obj.as(); + const ffi::ArrayObj* json_array = json_obj.as(); CHECK(json_array && json_array->size() >= 1); tag = json_array->at(0).cast(); } catch (const std::runtime_error& e) { // includes tvm::Error and dmlc::Error @@ -111,7 +111,7 @@ Array ArgInfo::FromEntryFunc(const IRModule& mod, bool remove_preproc) /******** TensorInfo ********/ -TensorInfo::TensorInfo(runtime::DataType dtype, runtime::ShapeTuple shape) { +TensorInfo::TensorInfo(runtime::DataType dtype, ffi::Shape shape) { ObjectPtr n = make_object(); n->dtype = dtype; n->shape = shape; @@ -129,12 +129,12 @@ TensorInfo TensorInfo::FromJSON(const ObjectRef& json_obj) { DLDataType dtype; Array shape; try { - const ArrayObj* json_array = json_obj.as(); + const ffi::ArrayObj* json_array = json_obj.as(); CHECK(json_array && json_array->size() == 3); // Load json[1] => dtype { String dtype_str = json_array->at(1).cast(); - dtype = runtime::StringToDLDataType(dtype_str); + dtype = StringToDLDataType(dtype_str); } // Load json[2] => shape shape = AsIntArray(json_array->at(2).cast()); @@ -145,7 +145,7 @@ TensorInfo TensorInfo::FromJSON(const ObjectRef& json_obj) { std::vector s; std::transform(shape.begin(), shape.end(), std::back_inserter(s), [](Integer i) { return i.IntValue(); }); - return TensorInfo(DataType(dtype), ShapeTuple(s.begin(), s.end())); + return TensorInfo(DataType(dtype), ffi::Shape(s.begin(), s.end())); } /******** Repr ********/ @@ -167,7 +167,7 @@ TVM_REGISTER_GLOBAL("meta_schedule.ArgInfoFromPrimFunc").set_body_typed(ArgInfo: TVM_REGISTER_GLOBAL("meta_schedule.ArgInfoFromEntryFunc").set_body_typed(ArgInfo::FromEntryFunc); TVM_REGISTER_GLOBAL("meta_schedule.ArgInfoFromJSON").set_body_typed(ArgInfo::FromJSON); TVM_REGISTER_GLOBAL("meta_schedule.TensorInfo") - .set_body_typed([](runtime::DataType dtype, runtime::ShapeTuple shape) -> TensorInfo { + .set_body_typed([](runtime::DataType dtype, ffi::Shape shape) -> TensorInfo { return TensorInfo(dtype, shape); }); diff --git a/src/meta_schedule/database/database.cc b/src/meta_schedule/database/database.cc index f859648464d4..9c23d9e845e6 100644 --- a/src/meta_schedule/database/database.cc +++ b/src/meta_schedule/database/database.cc @@ -25,14 +25,14 @@ namespace meta_schedule { /******** Workload ********/ Workload::Workload(IRModule mod) { - ObjectPtr n = runtime::make_object(); + ObjectPtr n = ffi::make_object(); n->mod = mod; n->shash = ModuleEquality::Create("structural")->Hash(mod); data_ = std::move(n); } Workload::Workload(IRModule mod, Workload::THashCode shash) { - ObjectPtr n = runtime::make_object(); + ObjectPtr n = ffi::make_object(); n->mod = mod; n->shash = shash; data_ = std::move(n); @@ -51,7 +51,7 @@ Workload Workload::FromJSON(const ObjectRef& json_obj) { IRModule mod{nullptr}; THashCode shash = 0; try { - const ArrayObj* json_array = json_obj.as(); + const ffi::ArrayObj* json_array = json_obj.as(); CHECK(json_array && json_array->size() == 2); // Load json[0] => shash String str_shash = json_array->at(0).cast(); @@ -134,7 +134,7 @@ TuningRecord TuningRecord::FromJSON(const ObjectRef& json_obj, const Workload& w Optional target; Optional> args_info; try { - const ArrayObj* json_array = json_obj.as(); + const ffi::ArrayObj* json_array = json_obj.as(); CHECK(json_array && json_array->size() == 4); // Load json[1] => run_secs if (json_array->at(1) != nullptr) { @@ -146,7 +146,7 @@ TuningRecord TuningRecord::FromJSON(const ObjectRef& json_obj, const Workload& w } // Load json[3] => args_info if (json_array->at(3) != nullptr) { - const ArrayObj* json_args_info = json_array->at(3).cast(); + const ffi::ArrayObj* json_args_info = json_array->at(3).cast(); Array info; info.reserve(json_args_info->size()); for (Any json_arg_info : *json_args_info) { @@ -177,11 +177,11 @@ DatabaseNode::~DatabaseNode() = default; Optional DatabaseNode::QueryTuningRecord(const IRModule& mod, const Target& target, const String& workload_name) { if (!this->HasWorkload(mod)) { - return NullOpt; + return std::nullopt; } Array records = this->GetTopK(this->CommitWorkload(mod), 1); if (records.empty()) { - return NullOpt; + return std::nullopt; } ICHECK_EQ(records.size(), 1); return records[0]; @@ -197,7 +197,7 @@ Optional DatabaseNode::QuerySchedule(const IRModule& mod, const T record->trace->ApplyToSchedule(sch, false); return sch; } else { - return NullOpt; + return std::nullopt; } } @@ -206,7 +206,7 @@ Optional DatabaseNode::QueryIRModule(const IRModule& mod, const Target if (Optional opt_sch = this->QuerySchedule(mod, target, workload_name)) { return opt_sch.value()->mod(); } else { - return NullOpt; + return std::nullopt; } } @@ -245,7 +245,7 @@ void Database::ExitWithScope() { ThreadLocalDatabases()->pop_back(); } Optional Database::Current() { std::vector* tls = ThreadLocalDatabases(); if (tls->empty()) { - return NullOpt; + return std::nullopt; } else { return tls->back(); } diff --git a/src/meta_schedule/database/database_utils.cc b/src/meta_schedule/database/database_utils.cc index badba34bcab0..75253a3680a5 100644 --- a/src/meta_schedule/database/database_utils.cc +++ b/src/meta_schedule/database/database_utils.cc @@ -43,7 +43,7 @@ void JSONDumps(Any json_obj, std::ostringstream& os) { } else if (auto opt_float_imm = json_obj.as()) { FloatImm float_imm = *std::move(opt_float_imm); os << std::setprecision(20) << float_imm->value; - } else if (const auto* str = json_obj.as()) { + } else if (const auto* str = json_obj.as()) { os << '"' << support::StrEscape(str->data, str->size) << '"'; } else if (const auto* array = json_obj.as()) { os << "["; diff --git a/src/meta_schedule/database/json_database.cc b/src/meta_schedule/database/json_database.cc index facfc9b8809d..a59b334b221f 100644 --- a/src/meta_schedule/database/json_database.cc +++ b/src/meta_schedule/database/json_database.cc @@ -189,7 +189,7 @@ Database Database::JSONDatabase(String path_workload, String path_tuning_record, auto json_obj = json_objs[task_id].cast(); Workload workload{nullptr}; try { - const ArrayObj* arr = json_obj.as(); + const ffi::ArrayObj* arr = json_obj.as(); ICHECK_EQ(arr->size(), 2); int64_t workload_index = arr->at(0).cast()->value; ICHECK(workload_index >= 0 && static_cast(workload_index) < workloads.size()); diff --git a/src/meta_schedule/database/ordered_union_database.cc b/src/meta_schedule/database/ordered_union_database.cc index 3aaee2112c0c..df151764a6ed 100644 --- a/src/meta_schedule/database/ordered_union_database.cc +++ b/src/meta_schedule/database/ordered_union_database.cc @@ -38,7 +38,7 @@ class OrderedUnionDatabaseNode : public DatabaseNode { return record; } } - return NullOpt; + return std::nullopt; } bool HasWorkload(const IRModule& mod) final { diff --git a/src/meta_schedule/database/schedule_fn_database.cc b/src/meta_schedule/database/schedule_fn_database.cc index a1a1351812e2..0dbac9616c49 100644 --- a/src/meta_schedule/database/schedule_fn_database.cc +++ b/src/meta_schedule/database/schedule_fn_database.cc @@ -40,11 +40,11 @@ class ScheduleFnDatabaseNode : public DatabaseNode { if (Optional sch = this->QuerySchedule(mod, target, workload_name)) { return TuningRecord(sch.value()->trace().value(), /*workload=*/Workload(mod, 0), // - /*run_secs=*/NullOpt, // + /*run_secs=*/std::nullopt, // /*target=*/target, // - /*arg_info=*/NullOpt); + /*arg_info=*/std::nullopt); } - return NullOpt; + return std::nullopt; } Optional QuerySchedule(const IRModule& mod, const Target& target, @@ -55,7 +55,7 @@ class ScheduleFnDatabaseNode : public DatabaseNode { /*debug_mode=*/0, /*error_render_level=*/tir::ScheduleErrorRenderLevel::kDetail); if (!schedule_fn(sch)) { - return NullOpt; + return std::nullopt; } return sch; } diff --git a/src/meta_schedule/database/union_database.cc b/src/meta_schedule/database/union_database.cc index 6d19a38c6d9e..876affbdb2b9 100644 --- a/src/meta_schedule/database/union_database.cc +++ b/src/meta_schedule/database/union_database.cc @@ -41,7 +41,7 @@ class UnionDatabaseNode : public DatabaseNode { } } std::stable_sort(results.begin(), results.end(), SortTuningRecordByMeanRunSecs()); - return results.empty() ? Optional(NullOpt) : results[0]; + return results.empty() ? Optional(std::nullopt) : results[0]; } bool HasWorkload(const IRModule& mod) final { diff --git a/src/meta_schedule/mutator/mutate_compute_location.cc b/src/meta_schedule/mutator/mutate_compute_location.cc index 98926c340518..f74d1640e475 100644 --- a/src/meta_schedule/mutator/mutate_compute_location.cc +++ b/src/meta_schedule/mutator/mutate_compute_location.cc @@ -115,7 +115,7 @@ std::vector MutateComputeLocationNode::Fin Optional MutateComputeLocationNode::Apply(const Trace& trace, TRandState* rand_state) { std::vector candidates = FindCandidates(trace, rand_state); if (candidates.empty()) { - return NullOpt; + return std::nullopt; } const Candidate& candidate = candidates[tir::SampleInt(rand_state, 0, candidates.size())]; int loc = candidate.locs[tir::SampleInt(rand_state, 0, candidate.locs.size())]; diff --git a/src/meta_schedule/mutator/mutate_parallel.cc b/src/meta_schedule/mutator/mutate_parallel.cc index e50e7410f6a0..6ddb6ea96bc9 100644 --- a/src/meta_schedule/mutator/mutate_parallel.cc +++ b/src/meta_schedule/mutator/mutate_parallel.cc @@ -250,7 +250,7 @@ Optional MutateParallelNode::Apply(const Trace& trace, TRandState* rand_s // Step 1. Find a parallel decision. Candidate candidate; if (!FindParallelDecision(trace, rand_state, &candidate)) { - return NullOpt; + return std::nullopt; } // Step 2. Replay the instructions to recover loop extents tir::Schedule sch = tir::Schedule::Traced( // @@ -283,7 +283,7 @@ Optional MutateParallelNode::Apply(const Trace& trace, TRandState* rand_s // Step 5. Pick a new plan int n_plans = plan2limit.size(); if (n_plans == 0) { - return NullOpt; + return std::nullopt; } it = plan2limit.begin(); for (int i = 0, n = tir::SampleInt(rand_state, 0, n_plans); i < n; ++i) { diff --git a/src/meta_schedule/mutator/mutate_thread_binding.cc b/src/meta_schedule/mutator/mutate_thread_binding.cc index 89671c50ccc0..3666e84bd59f 100644 --- a/src/meta_schedule/mutator/mutate_thread_binding.cc +++ b/src/meta_schedule/mutator/mutate_thread_binding.cc @@ -150,7 +150,7 @@ std::vector MutateThreadBindingNode::FindCan Optional MutateThreadBindingNode::Apply(const Trace& trace, TRandState* rand_state) { std::vector candidates = FindCandidates(trace, rand_state); if (candidates.empty()) { - return NullOpt; + return std::nullopt; } Candidate candidate = candidates[tir::SampleInt(rand_state, 0, candidates.size())]; // Remove the current decision diff --git a/src/meta_schedule/mutator/mutate_tile_size.cc b/src/meta_schedule/mutator/mutate_tile_size.cc index f06736abfb90..35dc23ceba60 100644 --- a/src/meta_schedule/mutator/mutate_tile_size.cc +++ b/src/meta_schedule/mutator/mutate_tile_size.cc @@ -216,7 +216,7 @@ Optional MutateSampleTileSize(const Trace& trace, Instruction inst, } if (max_factor_index == 0) { if (n_splits <= 2) { - return NullOpt; + return std::nullopt; } // Failed on this dst_idx, try next one. continue; @@ -253,7 +253,7 @@ Optional MutateTileSizeNode::Apply(const Trace& trace, TRandState* rand_s int size_a = sample_perfect_tile_insts.size(); int size_b = sample_vectorize_insts.size(); if (size_a == 0 && size_b == 0) { - return NullOpt; + return std::nullopt; } int n = tir::SampleInt(rand_state, 0, size_a + size_b); if (n < size_a) { diff --git a/src/meta_schedule/mutator/mutate_unroll.cc b/src/meta_schedule/mutator/mutate_unroll.cc index a3560943db04..782da45a355c 100644 --- a/src/meta_schedule/mutator/mutate_unroll.cc +++ b/src/meta_schedule/mutator/mutate_unroll.cc @@ -122,10 +122,10 @@ bool FindUnrollDecision(const Trace& trace, TRandState* rand_state, Optional MutateUnrollNode::Apply(const Trace& trace, TRandState* rand_state) { Candidate candidate; if (!FindUnrollDecision(trace, rand_state, &candidate)) { - return NullOpt; + return std::nullopt; } if (candidate.probs.size() == 0) { - return NullOpt; + return std::nullopt; } candidate.probs.erase(candidate.probs.begin() + candidate.decision); int result = tir::MakeMultinomialSampler(rand_state, candidate.probs)(); diff --git a/src/meta_schedule/postproc/disallow_async_strided_mem_copy.cc b/src/meta_schedule/postproc/disallow_async_strided_mem_copy.cc index a6a71202ae15..c32c7515facd 100644 --- a/src/meta_schedule/postproc/disallow_async_strided_mem_copy.cc +++ b/src/meta_schedule/postproc/disallow_async_strided_mem_copy.cc @@ -150,8 +150,8 @@ class DisallowAsyncStridedMemCopyNode : public PostprocNode { pass_list.push_back(tir::transform::InjectDoubleBuffer()); pass_list.push_back(tir::transform::VectorizeLoop(true)); pass_list.push_back(tir::transform::StorageRewrite()); - tir::PrimFunc f = WithAttr(GetRef(prim_func), "global_symbol", - runtime::String(g_var->name_hint)); + tir::PrimFunc f = + WithAttr(GetRef(prim_func), "global_symbol", String(g_var->name_hint)); IRModule mod = IRModule(Map({{GlobalVar(g_var->name_hint), f}})); lowered = tvm::transform::Sequential(pass_list)(std::move(mod)); } catch (const dmlc::Error& e) { diff --git a/src/meta_schedule/postproc/rewrite_cooperative_fetch.cc b/src/meta_schedule/postproc/rewrite_cooperative_fetch.cc index 353b90c36423..aa206764cce1 100644 --- a/src/meta_schedule/postproc/rewrite_cooperative_fetch.cc +++ b/src/meta_schedule/postproc/rewrite_cooperative_fetch.cc @@ -26,18 +26,18 @@ namespace tir { * \param sch The schedule * \param inst The instruction to be parsed * \param axis The axis name expected - * \return NullOpt if parsing fails; Otherwise, the extent of thread axis + * \return std::nullopt if parsing fails; Otherwise, the extent of thread axis */ Optional ParseThreadBinding(const Schedule& sch, const Instruction& inst, String axis) { static InstructionKind inst_kind_bind = InstructionKind::Get("Bind"); if (!inst->kind.same_as(inst_kind_bind)) { - return NullOpt; + return std::nullopt; } ICHECK_EQ(inst->inputs.size(), 1); ICHECK_EQ(inst->attrs.size(), 1); String thread_axis = Downcast(inst->attrs[0]); if (thread_axis != axis) { - return NullOpt; + return std::nullopt; } return Downcast(sch->Get(Downcast(inst->inputs[0]))->extent); } @@ -47,19 +47,19 @@ Optional ParseThreadBinding(const Schedule& sch, const Instruction& ins * \param sch The schedule * \param inst The instruction to be parsed * \param vector_lane The number of vector lane in vectorized cooperative fetching - * \return NullOpt if parsing fails; Otherwise, the annotated block + * \return std::nullopt if parsing fails; Otherwise, the annotated block */ Optional ParseAnnotate(const Schedule& sch, const Instruction& inst, int64_t* vector_lane) { static InstructionKind inst_kind_annotate = InstructionKind::Get("Annotate"); if (!inst->kind.same_as(inst_kind_annotate)) { - return NullOpt; + return std::nullopt; } ICHECK_EQ(inst->inputs.size(), 2); ICHECK_EQ(inst->attrs.size(), 1); String ann_key = Downcast(inst->attrs[0]); if (ann_key != attr::meta_schedule_cooperative_fetch) { - return NullOpt; + return std::nullopt; } *vector_lane = Downcast(sch->Get(Downcast(inst->inputs[1])))->value; return Downcast(inst->inputs[0]); @@ -186,7 +186,7 @@ bool RewriteCooperativeFetchNode::Apply(const tir::Schedule& sch) { } if (thread_extent_y != -1) { if (vector_lane > 1) { - Array split = sch->Split(fused, {NullOpt, // + Array split = sch->Split(fused, {std::nullopt, // Integer(thread_extent_y), // Integer(thread_extent_x), // Integer(vector_lane)}); @@ -194,7 +194,7 @@ bool RewriteCooperativeFetchNode::Apply(const tir::Schedule& sch) { sch->Bind(split[2], "threadIdx.x"); sch->Bind(split[1], "threadIdx.y"); } else { - Array split = sch->Split(fused, {NullOpt, // + Array split = sch->Split(fused, {std::nullopt, // Integer(thread_extent_y), // Integer(thread_extent_x)}); sch->Bind(split[2], "threadIdx.x"); @@ -202,13 +202,13 @@ bool RewriteCooperativeFetchNode::Apply(const tir::Schedule& sch) { } } else { if (vector_lane > 1) { - Array split = sch->Split(fused, {NullOpt, // + Array split = sch->Split(fused, {std::nullopt, // Integer(thread_extent_x), // Integer(vector_lane)}); sch->Vectorize(split[2]); sch->Bind(split[1], "threadIdx.x"); } else { - Array split = sch->Split(fused, {NullOpt, Integer(thread_extent_x)}); + Array split = sch->Split(fused, {std::nullopt, Integer(thread_extent_x)}); sch->Bind(split[1], "threadIdx.x"); } } diff --git a/src/meta_schedule/postproc/rewrite_layout.cc b/src/meta_schedule/postproc/rewrite_layout.cc index 6c8079fdda07..cdfc6c56e549 100644 --- a/src/meta_schedule/postproc/rewrite_layout.cc +++ b/src/meta_schedule/postproc/rewrite_layout.cc @@ -206,7 +206,7 @@ bool RewriteLayout(const Schedule& sch) { auto anchor_block_rv = sch->GetBlock(anchor_block->name_hint, func_name); add_layout_rewrite_block(anchor_block_rv, buffer_index); sch->TransformLayout(anchor_block_rv, buffer_index, BufferIndexType::kRead, index_map, - NullOpt); + std::nullopt); } else { // When the layout-free buffer is consumed by cache_read, we need to find the index map // for a cache-read buffer that is directly consumed by an anchor op. The last buffer @@ -219,7 +219,7 @@ bool RewriteLayout(const Schedule& sch) { auto [anchor_block, buffer_index, index_map] = *tup_opt; // Transform the layout of the last cache-read buffer. sch->TransformLayout(sch->GetBlock(anchor_block->name_hint, func_name), buffer_index, - BufferIndexType::kRead, index_map, NullOpt); + BufferIndexType::kRead, index_map, std::nullopt); // Propagate the layout transformation over cache_read_chain, starting from // the next-to-last cache-read buffer. @@ -231,7 +231,8 @@ bool RewriteLayout(const Schedule& sch) { // transformed by TransformLayout below. add_layout_rewrite_block(cache_read_block_rv, 0); } - sch->TransformLayout(cache_read_block_rv, 0, BufferIndexType::kRead, index_map, NullOpt); + sch->TransformLayout(cache_read_block_rv, 0, BufferIndexType::kRead, index_map, + std::nullopt); } } } diff --git a/src/meta_schedule/postproc/rewrite_parallel_vectorize_unroll.cc b/src/meta_schedule/postproc/rewrite_parallel_vectorize_unroll.cc index 965cc8baefd6..ad60f477b328 100644 --- a/src/meta_schedule/postproc/rewrite_parallel_vectorize_unroll.cc +++ b/src/meta_schedule/postproc/rewrite_parallel_vectorize_unroll.cc @@ -358,7 +358,7 @@ bool FindAnnotatedRootBlock(const Schedule& sch, ParsedAnnotation* parsed, Block void RewriteFuseSplitParallelVectorize(const Schedule& sch, Array* loop_rvs, int vec_len) { size_t n_loops = loop_rvs->size(); LoopRV fused = sch->Fuse({loop_rvs->begin(), loop_rvs->end()}); - Array split = sch->Split(fused, {NullOpt, Integer(vec_len)}); + Array split = sch->Split(fused, {std::nullopt, Integer(vec_len)}); ICHECK_EQ(split.size(), 2); const LoopRV& outer = split[0]; const LoopRV& inner = split[1]; diff --git a/src/meta_schedule/postproc/rewrite_reduction_block.cc b/src/meta_schedule/postproc/rewrite_reduction_block.cc index 05a7640f047c..295044596ff9 100644 --- a/src/meta_schedule/postproc/rewrite_reduction_block.cc +++ b/src/meta_schedule/postproc/rewrite_reduction_block.cc @@ -149,7 +149,7 @@ bool RewriteReductionBlockNode::Apply(const tir::Schedule& sch) { tir::GetAnn(block_sref, tir::attr::meta_schedule_auto_tensorize_init); // The annotation of tensorization of the init statement should be moved to the init block // after 'DecomposeReduction'. - // Annotate to hint `RewriteTensorize` postprocessor even if tensorize_init is NullOpt. + // Annotate to hint `RewriteTensorize` postprocessor even if tensorize_init is std::nullopt. sch->Annotate(init_block_rv, tir::attr::meta_schedule_auto_tensorize, tensorize_init.value_or("")); if (tensorize_init.defined()) { diff --git a/src/meta_schedule/postproc/verify_gpu_code.cc b/src/meta_schedule/postproc/verify_gpu_code.cc index b0d2c65edc85..f87e1ed9d50f 100644 --- a/src/meta_schedule/postproc/verify_gpu_code.cc +++ b/src/meta_schedule/postproc/verify_gpu_code.cc @@ -179,8 +179,8 @@ class VerifyGPUCodeNode : public PostprocNode { pass_list.push_back(tir::transform::LowerIntrin()); // Convert Function to IRModule transform::PassContext pass_ctx = transform::PassContext::Current(); - tir::PrimFunc f = WithAttr(GetRef(prim_func), "global_symbol", - runtime::String(g_var->name_hint)); + tir::PrimFunc f = + WithAttr(GetRef(prim_func), "global_symbol", String(g_var->name_hint)); f = WithAttr(f, tvm::attr::kTarget, this->target_); // Required for LowerIntrin bool noalias = pass_ctx->GetConfig("tir.noalias", true).value(); if (noalias) { diff --git a/src/meta_schedule/profiler.cc b/src/meta_schedule/profiler.cc index b7f261519fd2..b1386710b273 100644 --- a/src/meta_schedule/profiler.cc +++ b/src/meta_schedule/profiler.cc @@ -114,7 +114,7 @@ void Profiler::ExitWithScope() { Optional Profiler::Current() { std::vector* profilers = ThreadLocalProfilers(); if (profilers->empty()) { - return NullOpt; + return std::nullopt; } else { return profilers->back(); } diff --git a/src/meta_schedule/schedule/cuda/thread_bind.cc b/src/meta_schedule/schedule/cuda/thread_bind.cc index ee70ea8c717b..287f764a4640 100644 --- a/src/meta_schedule/schedule/cuda/thread_bind.cc +++ b/src/meta_schedule/schedule/cuda/thread_bind.cc @@ -67,13 +67,13 @@ Array BindSpatialLoop(Schedule sch, LoopRV loop, int64_t max_threadblock get_factor = MakeFactorSampler(sch, {32, 64, 128, 256, 512, 1024}); } ExprRV factor = get_factor(std::min(extent, max_threads_per_block)); - Array splits = sch->Split(loop, {NullOpt, factor}); + Array splits = sch->Split(loop, {std::nullopt, factor}); ICHECK_EQ(splits.size(), 2); sch->Bind(splits[0], "blockIdx.x"); sch->Bind(splits[1], "threadIdx.x"); return {splits[0], splits[1]}; } else { - Array splits = sch->Split(loop, {NullOpt, + Array splits = sch->Split(loop, {std::nullopt, Integer(max_threadblocks), // Integer(max_threads_per_block)}); ICHECK_EQ(splits.size(), 3); diff --git a/src/meta_schedule/schedule/cuda/winograd.cc b/src/meta_schedule/schedule/cuda/winograd.cc index 59ed7bdc009a..46ef6f366310 100644 --- a/src/meta_schedule/schedule/cuda/winograd.cc +++ b/src/meta_schedule/schedule/cuda/winograd.cc @@ -142,8 +142,8 @@ TVM_REGISTER_GLOBAL("meta_schedule.cuda.conv2d_nchw_winograd_inverse") BlockRV output = sch->GetConsumers(inverse)[0]; Array nchw = sch->GetLoops(output); ICHECK_EQ(nchw.size(), 4); - Array hs = sch->Split(nchw[2], {NullOpt, Integer(tile_size)}); - Array ws = sch->Split(nchw[3], {NullOpt, Integer(tile_size)}); + Array hs = sch->Split(nchw[2], {std::nullopt, Integer(tile_size)}); + Array ws = sch->Split(nchw[3], {std::nullopt, Integer(tile_size)}); sch->Reorder({hs[0], ws[0], hs[1], ws[1]}); outer = ws[0]; } diff --git a/src/meta_schedule/schedule_rule/apply_custom_rule.cc b/src/meta_schedule/schedule_rule/apply_custom_rule.cc index 15962baa927a..9fdcaa4ef535 100644 --- a/src/meta_schedule/schedule_rule/apply_custom_rule.cc +++ b/src/meta_schedule/schedule_rule/apply_custom_rule.cc @@ -69,7 +69,7 @@ class ApplyCustomRuleNode : public ScheduleRuleNode { } public: - Optional target_ = NullOpt; + Optional target_ = std::nullopt; void VisitAttrs(tvm::AttrVisitor* v) { v->Visit("target_", &target_); } diff --git a/src/meta_schedule/schedule_rule/cross_thread_reduction.cc b/src/meta_schedule/schedule_rule/cross_thread_reduction.cc index aa34b6467ab4..b71a14cc044e 100644 --- a/src/meta_schedule/schedule_rule/cross_thread_reduction.cc +++ b/src/meta_schedule/schedule_rule/cross_thread_reduction.cc @@ -86,7 +86,7 @@ class CrossThreadReductionNode : public ScheduleRuleNode { // - Otherwise, we search for the extent of "threadIdx.x" and use it as the split factor. if (!InThreadScope(tmp_sch, target_block)) { const Array& split_res = - tmp_sch->Split(tgt_block_innermost_loop, {NullOpt, thread_extent}); + tmp_sch->Split(tgt_block_innermost_loop, {std::nullopt, thread_extent}); tmp_sch->Bind(split_res[1], "threadIdx.x"); if (tgt_block_innermost_loop.same_as(target_loop)) { target_loop = split_res[0]; @@ -107,7 +107,7 @@ class CrossThreadReductionNode : public ScheduleRuleNode { ReorderAndFuseReductionLoops(tmp_sch, block_rv, &fused_reduce_loop, &num_spatial_loops); // Step 5. Split the fused reduction loop and bind the inner one to threadIdx. const Array& split_res = - tmp_sch->Split(fused_reduce_loop, {NullOpt, thread_extent}); + tmp_sch->Split(fused_reduce_loop, {std::nullopt, thread_extent}); tmp_sch->Bind(split_res[1], "threadIdx.x"); return {tmp_sch, sch}; diff --git a/src/meta_schedule/schedule_rule/multi_level_tiling_tensor_core.cc b/src/meta_schedule/schedule_rule/multi_level_tiling_tensor_core.cc index 5fa53d2bb568..2edb18ca8563 100644 --- a/src/meta_schedule/schedule_rule/multi_level_tiling_tensor_core.cc +++ b/src/meta_schedule/schedule_rule/multi_level_tiling_tensor_core.cc @@ -173,7 +173,7 @@ class MultiLevelTilingTensorCoreNode : public MultiLevelTilingNode { * \brief Transform and tensorize with the given tensor intrin * \param state The state of the meta schedule rule * \param intrin_name The name of the tensor intrin - * \return The loop to be tensorized. NullOpt if the workload can't be tensorized. + * \return The loop to be tensorized. std::nullopt if the workload can't be tensorized. */ Optional TransformWithTensorIntrin(TensorCoreStateNode* state, const String& intrin_name) const; @@ -502,7 +502,7 @@ std::vector MultiLevelTilingTensorCoreNode::TransformIntermediateOutputLa return result; }); sch->TransformLayout(state->block_rv, 0, tir::BufferIndexType::kWrite, index_map, - /*pad_value=*/NullOpt, /*assume_injective_transform=*/true); + /*pad_value=*/std::nullopt, /*assume_injective_transform=*/true); return {state}; } @@ -759,7 +759,7 @@ Optional MultiLevelTilingTensorCoreNode::TransformWithTensorIntrin( const tir::Block block_before_reindex = GetRef(block); if (block->reads.size() != 2 || block->writes.size() != 1) { // only matmul-like computation is allowed - return NullOpt; + return std::nullopt; } state->tensor_core_reindex_store = state->sch->ReIndex(state->block_rv, 0, tir::BufferIndexType::kWrite); @@ -840,7 +840,7 @@ Optional MultiLevelTilingTensorCoreNode::TransformWithTensorIntrin( auto sub_index_map = f_get_sub_index_map(lhs_buffer, reindexed_buffer_region->region); buffer_sub_index_map.Set(lhs_buffer, sub_index_map); state->sch->TransformLayout(state->block_rv, buffer_index, index_type, sub_index_map, - /*pad_value=*/NullOpt, /*assume_injective_transform=*/true); + /*pad_value=*/std::nullopt, /*assume_injective_transform=*/true); }; for (int i = 0, n = block_before_reindex->reads.size(); i < n; ++i) { diff --git a/src/meta_schedule/schedule_rule/multi_level_tiling_wide_vector.cc b/src/meta_schedule/schedule_rule/multi_level_tiling_wide_vector.cc index deceaa6f2c93..c7bbf82bf4e8 100644 --- a/src/meta_schedule/schedule_rule/multi_level_tiling_wide_vector.cc +++ b/src/meta_schedule/schedule_rule/multi_level_tiling_wide_vector.cc @@ -92,7 +92,7 @@ std::pair, Array> MultiLevelTilingWideVectorNode const int64_t* extent_int = tir::GetLoopIntExtent(loop); if (extent_int && *extent_int > vec_len) { Array inner_splits = sch->Split(/*loop=*/loop_rv, - /*factors=*/{NullOpt, PrimExpr(vec_len)}); + /*factors=*/{std::nullopt, PrimExpr(vec_len)}); Array outer_factors = sch->SamplePerfectTile( /*loop=*/inner_splits[0], /*n=*/n_tiles - 1, @@ -118,7 +118,7 @@ ScheduleRule ScheduleRule::MultiLevelTilingWideVector(String structure, Optional> reuse_read, Optional> reuse_write) { auto node = MultiLevelTilingInitCommon( - structure, NullOpt, max_innermost_factor, NullOpt, reuse_read, reuse_write); + structure, std::nullopt, max_innermost_factor, std::nullopt, reuse_read, reuse_write); node->vector_length_in_bits = vector_length_in_bits->value; return ScheduleRule(node); } diff --git a/src/meta_schedule/schedule_rule/multi_level_tiling_with_intrin.cc b/src/meta_schedule/schedule_rule/multi_level_tiling_with_intrin.cc index a8563750c834..554bb9dfb6a2 100644 --- a/src/meta_schedule/schedule_rule/multi_level_tiling_with_intrin.cc +++ b/src/meta_schedule/schedule_rule/multi_level_tiling_with_intrin.cc @@ -33,7 +33,7 @@ Optional TileForIntrin(tir::Schedule sch, tir::BlockRV block, const std::string& intrin_name) { Optional tiled_loop_rv = TileWithTensorIntrin(sch, block, intrin_name); if (!tiled_loop_rv) { - return NullOpt; + return std::nullopt; } ICHECK(tiled_loop_rv.defined()); tir::BlockRV outer_block = sch->Blockize(tiled_loop_rv.value()); diff --git a/src/meta_schedule/schedule_rule/schedule_rule.cc b/src/meta_schedule/schedule_rule/schedule_rule.cc index ec3c6ac480d0..5c5e2583dd59 100644 --- a/src/meta_schedule/schedule_rule/schedule_rule.cc +++ b/src/meta_schedule/schedule_rule/schedule_rule.cc @@ -68,10 +68,10 @@ Array ScheduleRule::DefaultLLVM() { /*max_innermost_factor=*/Integer(64)), ScheduleRule::MultiLevelTiling( /*structure=*/"SSRSRS", - /*tile_binds=*/NullOpt, + /*tile_binds=*/std::nullopt, /*max_innermost_factor=*/Integer(64), - /*vector_load_lens=*/NullOpt, - /*reuse_read=*/NullOpt, + /*vector_load_lens=*/std::nullopt, + /*reuse_read=*/std::nullopt, /*reuse_write=*/ Map{{"req", String("may")}, {"levels", Array{1, 2}}, @@ -105,20 +105,20 @@ Array ScheduleRule::DefaultX86(const String& type) { ScheduleRule::MultiLevelTilingWithIntrin( /*intrin_name=*/intrins[type], /*structure=*/"SSRSRS", - /*tile_binds=*/NullOpt, + /*tile_binds=*/std::nullopt, /*max_innermost_factor=*/Integer(64), - /*vector_load_lens=*/NullOpt, - /*reuse_read=*/NullOpt, + /*vector_load_lens=*/std::nullopt, + /*reuse_read=*/std::nullopt, /*reuse_write=*/ Map{{"req", String("may")}, {"levels", Array{1, 2}}, {"scope", String("global")}}), ScheduleRule::MultiLevelTiling( /*structure=*/"SSRSRS", - /*tile_binds=*/NullOpt, + /*tile_binds=*/std::nullopt, /*max_innermost_factor=*/Integer(64), - /*vector_load_lens=*/NullOpt, - /*reuse_read=*/NullOpt, + /*vector_load_lens=*/std::nullopt, + /*reuse_read=*/std::nullopt, /*reuse_write=*/ Map{{"req", String("may")}, {"levels", Array{1, 2}}, @@ -289,7 +289,7 @@ Array ScheduleRule::DefaultHexagon() { /*structure=*/"SRSRS", /*vector_length_in_bits=*/1024, /*max_innermost_factor=*/Integer(128), - /*reuse_read=*/NullOpt, + /*reuse_read=*/std::nullopt, /*reuse_write=*/ Map{{"req", String("may")}, {"levels", Array{1, 2}}, @@ -307,10 +307,10 @@ Array GetARMNeonSpecificRules() { ScheduleRule::MultiLevelTilingWithIntrin( /*intrin_name=*/String("dot_4x4_i8i8s32_neon"), /*structure=*/"SSRSRS", - /*tile_binds=*/NullOpt, + /*tile_binds=*/std::nullopt, /*max_innermost_factor=*/Integer(32), - /*vector_load_lens=*/NullOpt, - /*reuse_read=*/NullOpt, + /*vector_load_lens=*/std::nullopt, + /*reuse_read=*/std::nullopt, /*reuse_write=*/ Map{{"req", String("may")}, {"levels", Array{1, 2}}, @@ -323,10 +323,10 @@ Array GetARMDotprodSpecificRules() { ScheduleRule::MultiLevelTilingWithIntrin( /*intrin_name=*/String("dot_4x4_i8i8s32_sdot"), /*structure=*/"SSRSRS", - /*tile_binds=*/NullOpt, + /*tile_binds=*/std::nullopt, /*max_innermost_factor=*/Integer(32), - /*vector_load_lens=*/NullOpt, - /*reuse_read=*/NullOpt, + /*vector_load_lens=*/std::nullopt, + /*reuse_read=*/std::nullopt, /*reuse_write=*/ Map{{"req", String("may")}, {"levels", Array{1, 2}}, @@ -334,10 +334,10 @@ Array GetARMDotprodSpecificRules() { ScheduleRule::MultiLevelTilingWithIntrin( /*intrin_name=*/String("dot_4x4_u8u8u32_udot"), /*structure=*/"SSRSRS", - /*tile_binds=*/NullOpt, + /*tile_binds=*/std::nullopt, /*max_innermost_factor=*/Integer(32), - /*vector_load_lens=*/NullOpt, - /*reuse_read=*/NullOpt, + /*vector_load_lens=*/std::nullopt, + /*reuse_read=*/std::nullopt, /*reuse_write=*/ Map{{"req", String("may")}, {"levels", Array{1, 2}}, @@ -345,10 +345,10 @@ Array GetARMDotprodSpecificRules() { ScheduleRule::MultiLevelTilingWithIntrin( /*intrin_name=*/String("dot_4x4_u8u8i32_hdot"), /*structure=*/"SSRSRS", - /*tile_binds=*/NullOpt, + /*tile_binds=*/std::nullopt, /*max_innermost_factor=*/Integer(32), - /*vector_load_lens=*/NullOpt, - /*reuse_read=*/NullOpt, + /*vector_load_lens=*/std::nullopt, + /*reuse_read=*/std::nullopt, /*reuse_write=*/ Map{{"req", String("may")}, {"levels", Array{1, 2}}, @@ -374,10 +374,10 @@ Array ScheduleRule::DefaultARM(const String& type) { "dotprod" == type ? GetARMDotprodSpecificRules() : Array{}, ScheduleRule::MultiLevelTiling( /*structure=*/"SSRSRS", - /*tile_binds=*/NullOpt, + /*tile_binds=*/std::nullopt, /*max_innermost_factor=*/Integer(32), - /*vector_load_lens=*/NullOpt, - /*reuse_read=*/NullOpt, + /*vector_load_lens=*/std::nullopt, + /*reuse_read=*/std::nullopt, /*reuse_write=*/ Map{{"req", String("may")}, {"levels", Array{1, 2}}, diff --git a/src/meta_schedule/search_strategy/evolutionary_search.cc b/src/meta_schedule/search_strategy/evolutionary_search.cc index eea28fb0822b..f4812d56f19c 100644 --- a/src/meta_schedule/search_strategy/evolutionary_search.cc +++ b/src/meta_schedule/search_strategy/evolutionary_search.cc @@ -139,7 +139,7 @@ struct PerThreadData { TRandState* rand_state) { std::vector> mutators; std::vector masses; - mutators.push_back(NullOpt); + mutators.push_back(std::nullopt); masses.push_back(1.0 - genetic_mutate_prob); double total_mass_mutator = 0.0; if (genetic_mutate_prob > 0) { @@ -698,7 +698,7 @@ std::vector EvolutionarySearchNode::State::PickWithEpsGreedy( Optional> EvolutionarySearchNode::State::GenerateMeasureCandidates() { if (st >= max_trials) { - return NullOpt; + return std::nullopt; } int sample_num = num_trials_per_iter; if (ed > max_trials) { @@ -718,7 +718,7 @@ Optional> EvolutionarySearchNode::State::GenerateMeasure if (static_cast(unmeasured.size()) < self->init_min_unmeasured) { TVM_PY_LOG(WARNING, self->ctx_->logger) << "Cannot sample enough initial population, evolutionary search failed."; - return NullOpt; + return std::nullopt; } TVM_PY_LOG(INFO, self->ctx_->logger) << "Sampled " << unmeasured.size() << " candidate(s)"; inits.insert(inits.end(), measured.begin(), measured.end()); @@ -732,7 +732,7 @@ Optional> EvolutionarySearchNode::State::GenerateMeasure if (picks.empty()) { ++this->num_empty_iters; if (this->num_empty_iters >= self->num_empty_iters_before_early_stop) { - return NullOpt; + return std::nullopt; } } return AssembleCandidates(picks); diff --git a/src/meta_schedule/search_strategy/replay_func.cc b/src/meta_schedule/search_strategy/replay_func.cc index 7bb4a02ab299..60552b2e14f8 100644 --- a/src/meta_schedule/search_strategy/replay_func.cc +++ b/src/meta_schedule/search_strategy/replay_func.cc @@ -54,9 +54,9 @@ class ReplayFuncNode : public SearchStrategyNode { /*! \brief The random state. -1 means using random number. */ TRandState rand_state_ = -1; /*! \brief The IRModule to be scheduled from TuneContext. */ - Optional mod_ = NullOpt; + Optional mod_ = std::nullopt; /*! \brief The space generator from TuneContext. */ - Optional space_generator_ = NullOpt; + Optional space_generator_ = std::nullopt; /*! \brief The state of the search strategy. */ std::unique_ptr state_ = nullptr; @@ -108,8 +108,8 @@ class ReplayFuncNode : public SearchStrategyNode { SearchStrategy Clone() const final { ObjectPtr n = make_object(); n->rand_state_ = -1; - n->mod_ = NullOpt; - n->space_generator_ = NullOpt; + n->mod_ = std::nullopt; + n->space_generator_ = std::nullopt; n->state_ = nullptr; return SearchStrategy(n); } @@ -117,7 +117,7 @@ class ReplayFuncNode : public SearchStrategyNode { inline Optional> ReplayFuncNode::State::GenerateMeasureCandidates() { if (st >= max_trials) { - return NullOpt; + return std::nullopt; } ed = std::min(ed, max_trials); Array result; diff --git a/src/meta_schedule/search_strategy/replay_trace.cc b/src/meta_schedule/search_strategy/replay_trace.cc index dc9063ee1083..f7960688cd80 100644 --- a/src/meta_schedule/search_strategy/replay_trace.cc +++ b/src/meta_schedule/search_strategy/replay_trace.cc @@ -67,7 +67,7 @@ class ReplayTraceNode : public SearchStrategyNode { /*! \brief The random state. -1 means using random number. */ TRandState rand_state_ = -1; /*! \brief The IRModule to be scheduled from TuneContext. */ - Optional mod_ = NullOpt; + Optional mod_ = std::nullopt; /*! \brief The number of threads to be used. */ int num_threads_ = -1; /*! \brief The postprocessors. */ @@ -145,7 +145,7 @@ class ReplayTraceNode : public SearchStrategyNode { inline Optional> ReplayTraceNode::State::GenerateMeasureCandidates() { if (st >= max_trials) { - return NullOpt; + return std::nullopt; } ed = std::min(ed, max_trials); ICHECK_LT(st, ed); diff --git a/src/meta_schedule/task_scheduler/task_scheduler.cc b/src/meta_schedule/task_scheduler/task_scheduler.cc index ca5c6e4988a3..4411bd0792e0 100644 --- a/src/meta_schedule/task_scheduler/task_scheduler.cc +++ b/src/meta_schedule/task_scheduler/task_scheduler.cc @@ -22,7 +22,7 @@ namespace tvm { namespace meta_schedule { TaskRecord::TaskRecord(TuneContext ctx, double task_weight) { - ObjectPtr n = runtime::make_object(); + ObjectPtr n = ffi::make_object(); n->ctx = ctx; n->task_weight = task_weight; n->flop = 1.0; @@ -85,7 +85,7 @@ void SendToRunner(TaskRecordNode* self, const Runner& runner) { /*f_done=*/[]() -> bool { return true; }, /*f_result=*/ [msg = builder_result->error_msg]() -> RunnerResult { - return RunnerResult(NullOpt, msg); + return RunnerResult(std::nullopt, msg); })); } else { results.push_back(futures[j++]); @@ -104,7 +104,7 @@ void TaskCleanUp(TaskRecordNode* self, int task_id, const Array& r const BuilderResult& builder_result = self->builder_results.value()[i]; const MeasureCandidate& candidate = self->measure_candidates.value()[i]; const RunnerResult& runner_result = results[i]; - Optional error_msg = NullOpt; + Optional error_msg = std::nullopt; int trials = self->latency_ms.size() + 1; double run_ms = 1e9; if ((error_msg = builder_result->error_msg)) { @@ -135,9 +135,9 @@ void TaskCleanUp(TaskRecordNode* self, int task_id, const Array& r << ". Best GFLOPs: " << (self->flop / best_ms / 1e6); } } - self->measure_candidates = NullOpt; - self->builder_results = NullOpt; - self->runner_futures = NullOpt; + self->measure_candidates = std::nullopt; + self->builder_results = std::nullopt; + self->runner_futures = std::nullopt; } void TaskSchedulerNode::Tune(Array ctxs, Array task_weights, diff --git a/src/meta_schedule/utils.h b/src/meta_schedule/utils.h index de777e305919..e689edb425bf 100644 --- a/src/meta_schedule/utils.h +++ b/src/meta_schedule/utils.h @@ -21,6 +21,7 @@ #include #include +#include #include #include #include @@ -37,7 +38,6 @@ #include #include #include -#include #include #include #include @@ -319,7 +319,7 @@ struct ThreadedTraceApply { * \param mod The IRModule to be applied * \param trace The trace to apply to the IRModule * \param rand_state The random seed - * \return The schedule created, or NullOpt if any postprocessor fails + * \return The schedule created, or std::nullopt if any postprocessor fails */ Optional Apply(const IRModule& mod, const tir::Trace& trace, TRandState* rand_state) { @@ -336,7 +336,7 @@ struct ThreadedTraceApply { Item& item = items_[i]; if (!item.postproc->Apply(sch)) { item.fail_counter++; - return NullOpt; + return std::nullopt; } } return sch; @@ -418,7 +418,7 @@ inline double GetRunMsMedian(const RunnerResult& runner_result) { * \return The array of floating point numbers */ inline Array AsFloatArray(const ObjectRef& obj) { - const ArrayObj* arr = obj.as(); + const ffi::ArrayObj* arr = obj.as(); ICHECK(arr) << "TypeError: Expect an array, but gets: " << obj->GetTypeKey(); Array results; results.reserve(arr->size()); @@ -445,7 +445,7 @@ inline Array AsFloatArray(const ObjectRef& obj) { * \return The array of integers */ inline Array AsIntArray(const ObjectRef& obj) { - const ArrayObj* arr = obj.as(); + const ffi::ArrayObj* arr = obj.as(); ICHECK(arr) << "TypeError: Expect an array, but gets: " << obj->GetTypeKey(); Array results; results.reserve(arr->size()); diff --git a/src/node/container_printing.cc b/src/node/container_printing.cc index 261ae4825a8d..5fb3d503f55a 100644 --- a/src/node/container_printing.cc +++ b/src/node/container_printing.cc @@ -29,8 +29,8 @@ namespace tvm { // Container printer TVM_STATIC_IR_FUNCTOR(ReprPrinter, vtable) - .set_dispatch([](const ObjectRef& node, ReprPrinter* p) { - auto* op = static_cast(node.get()); + .set_dispatch([](const ObjectRef& node, ReprPrinter* p) { + auto* op = static_cast(node.get()); p->stream << '['; for (size_t i = 0; i < op->size(); ++i) { if (i != 0) { @@ -42,8 +42,8 @@ TVM_STATIC_IR_FUNCTOR(ReprPrinter, vtable) }); TVM_STATIC_IR_FUNCTOR(ReprPrinter, vtable) - .set_dispatch([](const ObjectRef& node, ReprPrinter* p) { - auto* op = static_cast(node.get()); + .set_dispatch([](const ObjectRef& node, ReprPrinter* p) { + auto* op = static_cast(node.get()); p->stream << '{'; for (auto it = op->begin(); it != op->end(); ++it) { if (it != op->begin()) { @@ -61,7 +61,7 @@ TVM_STATIC_IR_FUNCTOR(ReprPrinter, vtable) }); TVM_STATIC_IR_FUNCTOR(ReprPrinter, vtable) - .set_dispatch([](const ObjectRef& node, ReprPrinter* p) { - p->stream << Downcast(node); + .set_dispatch([](const ObjectRef& node, ReprPrinter* p) { + p->stream << ffi::Downcast(node); }); } // namespace tvm diff --git a/src/node/object_path.cc b/src/node/object_path.cc index fda5d3d9d160..bfb05aa4bc60 100644 --- a/src/node/object_path.cc +++ b/src/node/object_path.cc @@ -17,9 +17,9 @@ * under the License. */ +#include #include #include -#include #include #include diff --git a/src/node/reflection.cc b/src/node/reflection.cc index cf9f0dd3bd6e..6ba6a4ef1f18 100644 --- a/src/node/reflection.cc +++ b/src/node/reflection.cc @@ -253,7 +253,7 @@ ObjectRef ReflectionVTable::CreateObject(const std::string& type_key, std::vector packed_args(kwargs.size() * 2); int index = 0; - for (const auto& kv : *static_cast(kwargs.get())) { + for (const auto& kv : *static_cast(kwargs.get())) { packed_args[index] = kv.first.cast().c_str(); packed_args[index + 1] = kv.second; index += 2; @@ -336,7 +336,7 @@ Optional GetAttrKeyByAddress(const Object* object, const void* attr_addr ReflectionVTable::Global()->VisitAttrs(const_cast(object), &visitor); const char* key = visitor.GetKey(); if (key == nullptr) { - return NullOpt; + return std::nullopt; } else { return String(key); } diff --git a/src/node/script_printer.cc b/src/node/script_printer.cc index ab1be755685f..dd249b77dbae 100644 --- a/src/node/script_printer.cc +++ b/src/node/script_printer.cc @@ -72,13 +72,13 @@ PrinterConfig::PrinterConfig(Map config_dict) { n->module_alias = Downcast(v.value()); } if (auto v = config_dict.Get("buffer_dtype")) { - n->buffer_dtype = DataType(runtime::StringToDLDataType(Downcast(v.value()))); + n->buffer_dtype = DataType(StringToDLDataType(Downcast(v.value()))); } if (auto v = config_dict.Get("int_dtype")) { - n->int_dtype = DataType(runtime::StringToDLDataType(Downcast(v.value()))); + n->int_dtype = DataType(StringToDLDataType(Downcast(v.value()))); } if (auto v = config_dict.Get("float_dtype")) { - n->float_dtype = DataType(runtime::StringToDLDataType(Downcast(v.value()))); + n->float_dtype = DataType(StringToDLDataType(Downcast(v.value()))); } if (auto v = config_dict.Get("verbose_expr")) { n->verbose_expr = v.value().cast(); diff --git a/src/node/serialization.cc b/src/node/serialization.cc index 96c6696b336e..698483d06827 100644 --- a/src/node/serialization.cc +++ b/src/node/serialization.cc @@ -41,7 +41,7 @@ namespace tvm { inline std::string Type2String(const DataType& t) { return runtime::DLDataTypeToString(t); } -inline DataType String2Type(std::string s) { return DataType(runtime::StringToDLDataType(s)); } +inline DataType String2Type(std::string s) { return DataType(ffi::StringToDLDataType(s)); } inline std::string Base64Decode(std::string s) { dmlc::MemoryStringStream mstrm(&s); @@ -111,13 +111,13 @@ class NodeIndexer : public AttrVisitor { return; } MakeNodeIndex(node); - if (auto opt_array = node.as()) { - const ArrayObj* n = opt_array.value(); + if (auto opt_array = node.as()) { + const ffi::ArrayObj* n = opt_array.value(); for (auto elem : *n) { MakeIndex(elem); } - } else if (auto opt_map = node.as()) { - const MapObj* n = opt_map.value(); + } else if (auto opt_map = node.as()) { + const ffi::MapObj* n = opt_map.value(); bool is_str_map = std::all_of(n->begin(), n->end(), [](const auto& v) { return v.first.template as().has_value(); }); @@ -272,13 +272,13 @@ class JSONAttrGetter : public AttrVisitor { node_->attrs.clear(); node_->data.clear(); - if (auto opt_array = node.as()) { - const ArrayObj* n = opt_array.value(); + if (auto opt_array = node.as()) { + const ffi::ArrayObj* n = opt_array.value(); for (size_t i = 0; i < n->size(); ++i) { node_->data.push_back(node_index_->at(n->at(i))); } - } else if (auto opt_map = node.as()) { - const MapObj* n = opt_map.value(); + } else if (auto opt_map = node.as()) { + const ffi::MapObj* n = opt_map.value(); bool is_str_map = std::all_of(n->begin(), n->end(), [](const auto& v) { return v.first.template as().has_value(); }); @@ -381,7 +381,7 @@ class FieldDependencyFinder : public AttrVisitor { return; } // Skip containers - if (jnode->type_key == ArrayObj::_type_key || jnode->type_key == MapObj::_type_key) { + if (jnode->type_key == ffi::ArrayObj::_type_key || jnode->type_key == ffi::MapObj::_type_key) { return; } jnode_ = jnode; @@ -518,13 +518,13 @@ class JSONAttrSetter : public AttrVisitor { void SetAttrs(Any* node, JSONNode* jnode) { jnode_ = jnode; // handling Array - if (jnode->type_key == ArrayObj::_type_key) { + if (jnode->type_key == ffi::ArrayObj::_type_key) { Array result; for (auto index : jnode->data) { result.push_back(node_list_->at(index)); } *node = result; - } else if (jnode->type_key == MapObj::_type_key) { + } else if (jnode->type_key == ffi::MapObj::_type_key) { Map result; if (jnode->keys.empty()) { ICHECK_EQ(jnode->data.size() % 2, 0U); diff --git a/src/node/structural_equal.cc b/src/node/structural_equal.cc index 1a20810e790f..17a96b5e92a2 100644 --- a/src/node/structural_equal.cc +++ b/src/node/structural_equal.cc @@ -88,7 +88,7 @@ struct SEqualReducer::PathTracingData { bool SEqualReducer::operator()(const ObjectRef& lhs, const ObjectRef& rhs) const { if (tracing_data_ == nullptr) { // Fast path: no tracing - return handler_->SEqualReduce(lhs, rhs, map_free_vars_, NullOpt); + return handler_->SEqualReduce(lhs, rhs, map_free_vars_, std::nullopt); } return ObjectAttrsEqual(lhs, rhs, map_free_vars_, nullptr); } @@ -96,7 +96,7 @@ bool SEqualReducer::operator()(const ObjectRef& lhs, const ObjectRef& rhs) const bool SEqualReducer::DefEqual(const ObjectRef& lhs, const ObjectRef& rhs) { if (tracing_data_ == nullptr) { // Fast path: no tracing - return handler_->SEqualReduce(lhs, rhs, true, NullOpt); + return handler_->SEqualReduce(lhs, rhs, true, std::nullopt); } return ObjectAttrsEqual(lhs, rhs, true, nullptr); } @@ -239,7 +239,7 @@ bool SEqualReducer::ObjectAttrsEqual(const ObjectRef& lhs, const ObjectRef& rhs, const ObjectPathPair* paths) const { if (tracing_data_ == nullptr) { // Fast path: no tracing - return handler_->SEqualReduce(lhs, rhs, map_free_vars, NullOpt); + return handler_->SEqualReduce(lhs, rhs, map_free_vars, std::nullopt); } // Slow path: tracing object paths for better error reporting diff --git a/src/node/structural_hash.cc b/src/node/structural_hash.cc index 94e676820369..14c7b8a39a91 100644 --- a/src/node/structural_hash.cc +++ b/src/node/structural_hash.cc @@ -315,11 +315,11 @@ void SHashHandlerIgnoreNDArray::DispatchSHash(const ObjectRef& object, bool map_ struct StringObjTrait { static constexpr const std::nullptr_t VisitAttrs = nullptr; - static void SHashReduce(const runtime::StringObj* key, SHashReducer hash_reduce) { + static void SHashReduce(const ffi::StringObj* key, SHashReducer hash_reduce) { hash_reduce->SHashReduceHashedValue(ffi::details::StableHashBytes(key->data, key->size)); } - static bool SEqualReduce(const runtime::StringObj* lhs, const runtime::StringObj* rhs, + static bool SEqualReduce(const ffi::StringObj* lhs, const ffi::StringObj* rhs, SEqualReducer equal) { if (lhs == rhs) return true; if (lhs->size != rhs->size) return false; @@ -350,26 +350,20 @@ struct RefToObjectPtr : public ObjectRef { } }; -TVM_REGISTER_REFLECTION_VTABLE(runtime::StringObj, StringObjTrait) - .set_creator([](const std::string& bytes) { - return RefToObjectPtr::Get(runtime::String(bytes)); - }) +TVM_REGISTER_REFLECTION_VTABLE(ffi::StringObj, StringObjTrait) + .set_creator([](const std::string& bytes) { return RefToObjectPtr::Get(String(bytes)); }) .set_repr_bytes([](const Object* n) -> std::string { - return GetRef(static_cast(n)) - . - operator std::string(); + return GetRef(static_cast(n)).operator std::string(); }); TVM_STATIC_IR_FUNCTOR(ReprPrinter, vtable) - .set_dispatch([](const ObjectRef& node, ReprPrinter* p) { - auto* op = static_cast(node.get()); + .set_dispatch([](const ObjectRef& node, ReprPrinter* p) { + auto* op = static_cast(node.get()); p->stream << '"' << support::StrEscape(op->data, op->size) << '"'; }); TVM_REGISTER_REFLECTION_VTABLE(ffi::BytesObj, BytesObjTrait) - .set_creator([](const std::string& bytes) { - return RefToObjectPtr::Get(runtime::String(bytes)); - }) + .set_creator([](const std::string& bytes) { return RefToObjectPtr::Get(String(bytes)); }) .set_repr_bytes([](const Object* n) -> std::string { return GetRef(static_cast(n)).operator std::string(); }); @@ -439,14 +433,15 @@ TVM_REGISTER_REFLECTION_VTABLE(runtime::NDArray::Container, NDArrayContainerTrai struct ArrayObjTrait { static constexpr const std::nullptr_t VisitAttrs = nullptr; - static void SHashReduce(const ArrayObj* key, SHashReducer hash_reduce) { + static void SHashReduce(const ffi::ArrayObj* key, SHashReducer hash_reduce) { hash_reduce(static_cast(key->size())); for (uint32_t i = 0; i < key->size(); ++i) { hash_reduce(key->at(i)); } } - static bool SEqualReduce(const ArrayObj* lhs, const ArrayObj* rhs, SEqualReducer equal) { + static bool SEqualReduce(const ffi::ArrayObj* lhs, const ffi::ArrayObj* rhs, + SEqualReducer equal) { if (equal.IsPathTracingEnabled()) { return SEqualReduceTraced(lhs, rhs, equal); } @@ -459,7 +454,7 @@ struct ArrayObjTrait { } private: - static bool SEqualReduceTraced(const ArrayObj* lhs, const ArrayObj* rhs, + static bool SEqualReduceTraced(const ffi::ArrayObj* lhs, const ffi::ArrayObj* rhs, const SEqualReducer& equal) { uint32_t min_size = std::min(lhs->size(), rhs->size()); const ObjectPathPair& array_paths = equal.GetCurrentObjectPaths(); @@ -517,22 +512,22 @@ struct ArrayObjTrait { return false; } }; -TVM_REGISTER_REFLECTION_VTABLE(ArrayObj, ArrayObjTrait) +TVM_REGISTER_REFLECTION_VTABLE(ffi::ArrayObj, ArrayObjTrait) .set_creator([](const std::string&) -> ObjectPtr { - return ::tvm::runtime::make_object(); + return ffi::make_object(); }); -struct ShapeTupleObjTrait { +struct ShapeObjTrait { static constexpr const std::nullptr_t VisitAttrs = nullptr; - static void SHashReduce(const ShapeTupleObj* self, SHashReducer hash_reduce) { + static void SHashReduce(const ffi::ShapeObj* self, SHashReducer hash_reduce) { hash_reduce(static_cast(self->size)); for (uint32_t i = 0; i < self->size; ++i) { hash_reduce(self->data[i]); } } - static bool SEqualReduce(const ShapeTupleObj* lhs, const ShapeTupleObj* rhs, + static bool SEqualReduce(const ffi::ShapeObj* lhs, const ffi::ShapeObj* rhs, SEqualReducer equal) { if (lhs->size != rhs->size) return false; for (uint32_t i = 0; i < lhs->size; ++i) { @@ -542,7 +537,7 @@ struct ShapeTupleObjTrait { } }; -TVM_REGISTER_REFLECTION_VTABLE(ShapeTupleObj, ShapeTupleObjTrait) +TVM_REGISTER_REFLECTION_VTABLE(ffi::ShapeObj, ShapeObjTrait) .set_creator([](const std::string& blob) { // Store shape tuple in blob to avoid large integer overflow in JSON. dmlc::MemoryStringStream mstrm(const_cast(&blob)); @@ -552,14 +547,14 @@ TVM_REGISTER_REFLECTION_VTABLE(ShapeTupleObj, ShapeTupleObjTrait) b64strm.Read(&size); std::vector data(size); b64strm.ReadArray(data.data(), size); - ShapeTuple shape(data); + ffi::Shape shape(data); return RefToObjectPtr::Get(shape); }) .set_repr_bytes([](const Object* n) -> std::string { std::string blob; dmlc::MemoryStringStream mstrm(&blob); support::Base64OutStream b64strm(&mstrm); - const auto* shape = static_cast(n); + const auto* shape = static_cast(n); b64strm.Write(shape->size); b64strm.WriteArray(shape->data, shape->size); b64strm.Finish(); @@ -569,7 +564,7 @@ TVM_REGISTER_REFLECTION_VTABLE(ShapeTupleObj, ShapeTupleObjTrait) struct MapObjTrait { static constexpr const std::nullptr_t VisitAttrs = nullptr; - static void SHashReduceForOMap(const MapObj* key, SHashReducer hash_reduce) { + static void SHashReduceForOMap(const ffi::MapObj* key, SHashReducer hash_reduce) { // SHash's var handling depends on the determinism of traversal. // NOTE: only book-keep the mapped hash keys. // This resolves common use cases where we want to store @@ -605,7 +600,7 @@ struct MapObjTrait { } } - static void SHashReduceForSMap(const MapObj* key, SHashReducer hash_reduce) { + static void SHashReduceForSMap(const ffi::MapObj* key, SHashReducer hash_reduce) { // NOTE: only book-keep the mapped hash keys. // This resolves common use cases where we want to store // Map where Var is defined in the function @@ -628,7 +623,7 @@ struct MapObjTrait { } } - static void SHashReduce(const MapObj* key, SHashReducer hash_reduce) { + static void SHashReduce(const ffi::MapObj* key, SHashReducer hash_reduce) { bool is_str_map = std::all_of(key->begin(), key->end(), [](const auto& v) { return v.first.template as(); }); @@ -639,7 +634,8 @@ struct MapObjTrait { } } - static bool SEqualReduceTraced(const MapObj* lhs, const MapObj* rhs, const SEqualReducer& equal) { + static bool SEqualReduceTraced(const ffi::MapObj* lhs, const ffi::MapObj* rhs, + const SEqualReducer& equal) { const ObjectPathPair& map_paths = equal.GetCurrentObjectPaths(); // First, check that every key from `lhs` is also in `rhs`, // and their values are mapped to each other. @@ -678,7 +674,7 @@ struct MapObjTrait { TVM_FFI_UNREACHABLE(); } - static bool SEqualReduce(const MapObj* lhs, const MapObj* rhs, SEqualReducer equal) { + static bool SEqualReduce(const ffi::MapObj* lhs, const ffi::MapObj* rhs, SEqualReducer equal) { if (equal.IsPathTracingEnabled()) { return SEqualReduceTraced(lhs, rhs, equal); } @@ -699,8 +695,8 @@ struct MapObjTrait { return true; } }; -TVM_REGISTER_REFLECTION_VTABLE(MapObj, MapObjTrait) - .set_creator([](const std::string&) -> ObjectPtr { return MapObj::Empty(); }); +TVM_REGISTER_REFLECTION_VTABLE(ffi::MapObj, MapObjTrait) + .set_creator([](const std::string&) -> ObjectPtr { return ffi::MapObj::Empty(); }); struct ReportNodeTrait { static void VisitAttrs(runtime::profiling::ReportNode* report, AttrVisitor* attrs) { diff --git a/src/relax/analysis/analysis.cc b/src/relax/analysis/analysis.cc index a0ddb613d052..b4a5a039bbaa 100644 --- a/src/relax/analysis/analysis.cc +++ b/src/relax/analysis/analysis.cc @@ -178,7 +178,7 @@ Optional FindImpureCall(const Expr& expr, const Optional& own_name) private: const Optional& own_name_; - Optional impure_expr_ = NullOpt; + Optional impure_expr_ = std::nullopt; }; if (own_name) { diff --git a/src/relax/analysis/struct_info_analysis.cc b/src/relax/analysis/struct_info_analysis.cc index d44252e86fd2..5ad8a173c0b4 100644 --- a/src/relax/analysis/struct_info_analysis.cc +++ b/src/relax/analysis/struct_info_analysis.cc @@ -270,7 +270,7 @@ StructInfo EraseToWellDefined(const StructInfo& info, Map sh f_shape_var_map = [&](const tir::Var& var) -> Optional { auto it = shape_var_map.find(var); if (it != shape_var_map.end()) return (*it).second; - return NullOpt; + return std::nullopt; }; } @@ -278,7 +278,7 @@ StructInfo EraseToWellDefined(const StructInfo& info, Map sh f_var_map = [&](const Var& var) -> Optional { auto it = var_map.find(var); if (it != var_map.end()) return (*it).second; - return NullOpt; + return std::nullopt; }; } @@ -1143,7 +1143,7 @@ class StructInfoLCAFinder Optional> UnifyArray(const Array& lhs, const Array& rhs) { if (lhs.same_as(rhs)) return lhs; - if (lhs.size() != rhs.size()) return NullOpt; + if (lhs.size() != rhs.size()) return std::nullopt; size_t index = 0; return lhs.Map([&](const StructInfo& a) { return this->VisitStructInfo(a, rhs[index++]); }); } diff --git a/src/relax/analysis/tir_op_pattern_kind.cc b/src/relax/analysis/tir_op_pattern_kind.cc index fe7b7bbeb547..177fdeff588c 100644 --- a/src/relax/analysis/tir_op_pattern_kind.cc +++ b/src/relax/analysis/tir_op_pattern_kind.cc @@ -76,7 +76,7 @@ class PatternKindAnalyzer : public StmtExprVisitor { // Step 1. Clear loads and store loads_.clear(); - store_ = NullOpt; + store_ = std::nullopt; // Step 2. Visit block body. StmtVisitor::VisitStmt(op->body); diff --git a/src/relax/analysis/udchain.cc b/src/relax/analysis/udchain.cc index b6b6be4b83e0..1c16f25c997f 100644 --- a/src/relax/analysis/udchain.cc +++ b/src/relax/analysis/udchain.cc @@ -108,13 +108,12 @@ class UDChain : relax::ExprVisitor { } }; -std::pair>, runtime::Array> FunctionUseDef( - const Expr& fn) { +std::pair>, Array> FunctionUseDef(const Expr& fn) { auto usage = UDChain::Collect(fn); return {usage.downstream_usage, usage.outputs}; } -runtime::Map> DataflowBlockUseDef(const DataflowBlock& dfb) { +Map> DataflowBlockUseDef(const DataflowBlock& dfb) { auto usage = UDChain::Collect(SeqExpr({dfb}, Tuple(Array()))); return usage.downstream_usage; } diff --git a/src/relax/analysis/var2value.cc b/src/relax/analysis/var2value.cc index be50e9bdcef2..7625841eb69c 100644 --- a/src/relax/analysis/var2value.cc +++ b/src/relax/analysis/var2value.cc @@ -25,7 +25,7 @@ namespace tvm { namespace relax { class Var2ValAnalysis : public relax::ExprVisitor { public: - tvm::runtime::Map var2value_; + Map var2value_; void VisitBinding_(const VarBindingNode* binding) override { var2value_.Set(binding->var, binding->value); // Recursively visit the value to handle local functions. @@ -33,19 +33,19 @@ class Var2ValAnalysis : public relax::ExprVisitor { } }; -tvm::runtime::Map AnalyzeVar2Value(const Expr& expr) { +Map AnalyzeVar2Value(const Expr& expr) { Var2ValAnalysis var2val_analysis; var2val_analysis.VisitExpr(expr); return std::move(var2val_analysis.var2value_); } -tvm::runtime::Map AnalyzeVar2Value(const DataflowBlock& dfb) { +Map AnalyzeVar2Value(const DataflowBlock& dfb) { Var2ValAnalysis var2val_analysis; var2val_analysis.VisitBindingBlock_(dfb.get()); return std::move(var2val_analysis.var2value_); } -tvm::runtime::Map AnalyzeVar2Value(const IRModule& m) { +Map AnalyzeVar2Value(const IRModule& m) { Var2ValAnalysis var2val_analysis; for (const auto& it : m->functions) { @@ -64,7 +64,7 @@ TVM_REGISTER_GLOBAL(("relax.analysis.get_var2val")).set_body_typed([](const Func class Name2BindingAnalysis : public relax::ExprVisitor { public: - // runtime::Map is not suitable for doing in-place update. + // Map is not suitable for doing in-place update. // so we use standard container for internal usage. std::map> name2bindings_; void VisitBinding_(const VarBindingNode* binding) override { diff --git a/src/relax/analysis/well_formed.cc b/src/relax/analysis/well_formed.cc index 1ea15b38343d..316e87f351fa 100644 --- a/src/relax/analysis/well_formed.cc +++ b/src/relax/analysis/well_formed.cc @@ -332,7 +332,7 @@ class WellFormedChecker : public relax::ExprVisitor, if (auto func_normalize = op_map_normalize_.get(call->op, nullptr); func_normalize != nullptr) { auto dummy_builder = tvm::relax::BlockBuilder::Create(mod_); Call before_normalize = GetRef(call); - Optional after_normalize = NullOpt; + Optional after_normalize = std::nullopt; try { after_normalize = func_normalize(dummy_builder, before_normalize); } catch (std::exception& err) { @@ -369,7 +369,7 @@ class WellFormedChecker : public relax::ExprVisitor, // an expression that does not yet have `StructInfo`. auto dummy_builder = tvm::relax::BlockBuilder::Create(mod_); Call copied(call->op, call->args, call->attrs, call->sinfo_args); - Optional normalized = NullOpt; + Optional normalized = std::nullopt; try { normalized = dummy_builder->Normalize(copied); } catch (std::exception& err) { diff --git a/src/relax/backend/contrib/codegen_c/codegen_c.h b/src/relax/backend/contrib/codegen_c/codegen_c.h index 67e97cc99dbf..ce26e94cb7f5 100644 --- a/src/relax/backend/contrib/codegen_c/codegen_c.h +++ b/src/relax/backend/contrib/codegen_c/codegen_c.h @@ -24,8 +24,8 @@ #ifndef TVM_RELAX_BACKEND_CONTRIB_CODEGEN_C_CODEGEN_C_H_ #define TVM_RELAX_BACKEND_CONTRIB_CODEGEN_C_CODEGEN_C_H_ -#include -#include +#include +#include #include #include @@ -218,12 +218,12 @@ class CodegenCBase { if (!const_arr_name.empty()) { // If there are constants, insert the __init_ and the wrapper // This segment would be generated in C++ because of the usage - // of tvm::runtime::Array. This is not ideal, but this to demonstrate + // of tvm::Array. This is not ideal, but this to demonstrate // constant copying process used packed imports in other external // codegen. Moreover, in microTVM we dont expect this part to be generated. code_stream_ << "#ifdef __cplusplus\n"; code_stream_ << "int " << func_name - << "_init_wrapper_(tvm::runtime::Array arr) {\n"; + << "_init_wrapper_(tvm::Array arr) {\n"; EnterScope(); PrintIndents(); code_stream_ << func_name << "_consts = arr;\n"; @@ -393,7 +393,7 @@ class CodegenCBase { * \return The created declaration */ std::string CreateNDArrayPool(const std::string& symbol) const { - return "tvm::runtime::Array " + symbol + "_consts;"; + return "tvm::Array " + symbol + "_consts;"; } /*! diff --git a/src/relax/backend/contrib/codegen_json/codegen_json.h b/src/relax/backend/contrib/codegen_json/codegen_json.h index ce8ad2f8a7aa..f7df28bf716f 100644 --- a/src/relax/backend/contrib/codegen_json/codegen_json.h +++ b/src/relax/backend/contrib/codegen_json/codegen_json.h @@ -111,14 +111,14 @@ class OpAttrExtractor : public AttrVisitor { } void Visit(const char* key, runtime::ObjectRef* value) final { - if (const auto* an = (*value).as()) { + if (const auto* an = (*value).as()) { std::vector attr; for (size_t i = 0; i < an->size(); ++i) { if (const auto* im = (*an)[i].as()) { attr.push_back(std::to_string(im->value)); } else if (const auto* fm = (*an)[i].as()) { attr.push_back(Fp2String(fm->value)); - } else if (const auto* str = (*an)[i].as()) { + } else if (const auto* str = (*an)[i].as()) { String s = GetRef(str); attr.push_back(s); } else { @@ -132,7 +132,7 @@ class OpAttrExtractor : public AttrVisitor { SetNodeAttr(key, std::vector{std::to_string(im->value)}); } else if (const auto* fm = (*value).as()) { SetNodeAttr(key, std::vector{Fp2String(fm->value)}); - } else if (const auto* str = (*value).as()) { + } else if (const auto* str = (*value).as()) { String s = GetRef(str); SetNodeAttr(key, std::vector{s}); } else { diff --git a/src/relax/backend/contrib/cutlass/codegen.cc b/src/relax/backend/contrib/cutlass/codegen.cc index 115efa6adbfb..175be21834f9 100644 --- a/src/relax/backend/contrib/cutlass/codegen.cc +++ b/src/relax/backend/contrib/cutlass/codegen.cc @@ -204,7 +204,7 @@ class CodegenCutlass : public relax::MemoizedExprTranslator, const auto* fn_var = call->op.as(); ICHECK(fn_var); const auto func = Downcast(bindings_[GetRef(fn_var)]); - const auto pattern_name_opt = func->GetAttr(attr::kComposite); + const auto pattern_name_opt = func->GetAttr(attr::kComposite); ICHECK(pattern_name_opt) << "Only composite function is supported for CUTLASS."; auto ret = GenerateBody(call, pattern_name_opt.value(), func->attrs->dict); ext_func_body_.push_back(ret.decl); diff --git a/src/relax/backend/pattern_registry.cc b/src/relax/backend/pattern_registry.cc index 34ebb4d6ddbf..9feeca6662dc 100644 --- a/src/relax/backend/pattern_registry.cc +++ b/src/relax/backend/pattern_registry.cc @@ -64,7 +64,7 @@ Optional GetPattern(const String& pattern_name) { return *it; } } - return NullOpt; + return std::nullopt; } TVM_REGISTER_GLOBAL("relax.backend.RegisterPatterns").set_body_typed(RegisterPatterns); diff --git a/src/relax/backend/pattern_registry.h b/src/relax/backend/pattern_registry.h index 72eea1238d38..2c1f385a2dda 100644 --- a/src/relax/backend/pattern_registry.h +++ b/src/relax/backend/pattern_registry.h @@ -26,10 +26,10 @@ #ifndef TVM_RELAX_BACKEND_PATTERN_REGISTRY_H_ #define TVM_RELAX_BACKEND_PATTERN_REGISTRY_H_ +#include #include #include #include -#include #include namespace tvm { @@ -62,7 +62,7 @@ Array GetPatternsWithPrefix(const String& prefix); /*! * \brief Find the pattern with a particular name. * \param name The pattern name. - * \return The matched pattern. NullOpt if not found. + * \return The matched pattern. std::nullopt if not found. */ Optional GetPattern(const String& name); diff --git a/src/relax/backend/vm/codegen_vm.cc b/src/relax/backend/vm/codegen_vm.cc index b09602894577..44acd6ea81c2 100644 --- a/src/relax/backend/vm/codegen_vm.cc +++ b/src/relax/backend/vm/codegen_vm.cc @@ -225,7 +225,7 @@ class CodeGenVM : public ExprFunctor { LOG(FATAL) << "Should only use constant shape after shape lowering: " << op->values; } } - return builder_->ConvertConstant(ShapeTuple(shape)); + return builder_->ConvertConstant(ffi::Shape(shape)); } Instruction::Arg VisitExpr_(const PrimValueNode* op) final { diff --git a/src/relax/backend/vm/codegen_vm_tir.cc b/src/relax/backend/vm/codegen_vm_tir.cc index 0fead47194f4..cfcdf00efb6a 100644 --- a/src/relax/backend/vm/codegen_vm_tir.cc +++ b/src/relax/backend/vm/codegen_vm_tir.cc @@ -247,7 +247,7 @@ class CodeGenVMTIR : public ExprFunctor(const Expr&)> { if (dst_reg >= 0) { return RegListGet(dst_reg); } else { - return NullOpt; + return std::nullopt; } } @@ -291,7 +291,7 @@ class CodeGenVMTIR : public ExprFunctor(const Expr&)> { LOG(FATAL) << "Should only use constant shape after shape lowering: " << op->values; } } - return ConstListGet(builder_->ConvertConstant(ShapeTuple(shape)).value()); + return ConstListGet(builder_->ConvertConstant(ffi::Shape(shape)).value()); } Optional VisitExpr_(const PrimValueNode* op) final { return op->value; } @@ -356,13 +356,13 @@ class CodeGenVMTIR : public ExprFunctor(const Expr&)> { *kind = VMFuncInfo::FuncKind::kPackedFunc; return gvar->name_hint; } else { - return NullOpt; + return std::nullopt; } } // Lookup PrimFunc in the same module // We can do direct PrimFunc call in such cases Optional LookupPrimFunc(const String& name) { - if (!ctx_mod_->ContainGlobalVar(name)) return NullOpt; + if (!ctx_mod_->ContainGlobalVar(name)) return std::nullopt; GlobalVar gvar = ctx_mod_->GetGlobalVar(name); auto it = ctx_mod_->functions.find(gvar); @@ -372,7 +372,7 @@ class CodeGenVMTIR : public ExprFunctor(const Expr&)> { return GetRef(prim_func); } } - return NullOpt; + return std::nullopt; } Optional VisitExpr_(const GlobalVarNode* op) final { diff --git a/src/relax/backend/vm/vm_shape_lower.cc b/src/relax/backend/vm/vm_shape_lower.cc index e930ea46cf09..6400a3332133 100644 --- a/src/relax/backend/vm/vm_shape_lower.cc +++ b/src/relax/backend/vm/vm_shape_lower.cc @@ -288,7 +288,7 @@ class VMShapeLowerMutator auto new_body = builder_->Normalize(SeqExpr(blocks, body_seq->body)); - current_gvar_ = NullOpt; + current_gvar_ = std::nullopt; // create a new function return Function(func->params, new_body, func->ret_struct_info, func->is_pure, func->attrs); @@ -778,7 +778,7 @@ class VMShapeLowerMutator std::vector> slot_vec_; /*! \brief Expr => slot. */ PrimExprSlotMap slot_map_; - Optional current_gvar_ = NullOpt; + Optional current_gvar_ = std::nullopt; /*! * \brief List of vars that are being defined but * have not go through outstanding shape compute check. diff --git a/src/relax/distributed/global_info.cc b/src/relax/distributed/global_info.cc index d9f0cfdfd71a..c0d6204c8739 100644 --- a/src/relax/distributed/global_info.cc +++ b/src/relax/distributed/global_info.cc @@ -23,7 +23,7 @@ namespace tvm { namespace relax { namespace distributed { -DeviceMesh::DeviceMesh(ShapeTuple shape, Array device_ids) { +DeviceMesh::DeviceMesh(ffi::Shape shape, Array device_ids) { int prod = 1; for (int i = 0; i < static_cast(shape.size()); i++) { prod *= shape[i]; @@ -36,7 +36,7 @@ DeviceMesh::DeviceMesh(ShapeTuple shape, Array device_ids) { data_ = std::move(n); } -DeviceMesh::DeviceMesh(ShapeTuple shape, Range device_range) { +DeviceMesh::DeviceMesh(ffi::Shape shape, Range device_range) { ObjectPtr n = make_object(); Array device_ids; int range_start = device_range->min.as()->value; @@ -58,7 +58,7 @@ DeviceMesh::DeviceMesh(ShapeTuple shape, Range device_range) { TVM_REGISTER_NODE_TYPE(DeviceMeshNode); TVM_REGISTER_GLOBAL("relax.distributed.DeviceMesh") - .set_body_typed([](ShapeTuple shape, Array device_ids, Optional device_range) { + .set_body_typed([](ffi::Shape shape, Array device_ids, Optional device_range) { if (device_range.defined()) return DeviceMesh(shape, device_range.value()); else diff --git a/src/relax/distributed/transform/lower_distir.cc b/src/relax/distributed/transform/lower_distir.cc index 7c729e443837..59de65450e9e 100644 --- a/src/relax/distributed/transform/lower_distir.cc +++ b/src/relax/distributed/transform/lower_distir.cc @@ -61,7 +61,7 @@ class DistIRSharder : public ExprMutator { } ShapeExpr ShardShape(ShapeExpr orig_shape, DeviceMesh device_mesh, Placement placement) { - ShapeTuple device_mesh_shape = device_mesh->shape; + ffi::Shape device_mesh_shape = device_mesh->shape; Array new_tensor_shape_value = orig_shape->values; for (int i = 0; i < static_cast(device_mesh_shape.size()); i++) { if (placement->dim_specs[i]->kind == PlacementSpecKind::kSharding) { @@ -178,7 +178,7 @@ class DistIRSharder : public ExprMutator { func_ = func; new_params_ = new_params; auto new_body = VisitWithNewScope(func->body, new_params); - Function new_func(new_params, new_body, NullOpt, func->is_pure, func->attrs); + Function new_func(new_params, new_body, std::nullopt, func->is_pure, func->attrs); return new_func; } diff --git a/src/relax/distributed/transform/propagate_sharding.cc b/src/relax/distributed/transform/propagate_sharding.cc index dfcdde5c9eb4..15b372fb8348 100644 --- a/src/relax/distributed/transform/propagate_sharding.cc +++ b/src/relax/distributed/transform/propagate_sharding.cc @@ -429,7 +429,7 @@ class DistributedIRBuilder : public ExprMutator { } } auto new_body = VisitWithNewScope(func->body, new_params); - Function new_func(new_params, new_body, NullOpt, func->is_pure, func->attrs); + Function new_func(new_params, new_body, std::nullopt, func->is_pure, func->attrs); return new_func; } diff --git a/src/relax/distributed/transform/utils.h b/src/relax/distributed/transform/utils.h index 26ce6530116f..2680c892695c 100644 --- a/src/relax/distributed/transform/utils.h +++ b/src/relax/distributed/transform/utils.h @@ -40,7 +40,7 @@ inline Optional MatchPrimFunc(const IRModule& mod_, const Expr& o if (auto* pfunc = base_func.as()) { return GetRef(pfunc); } - return NullOpt; + return std::nullopt; } /*! * \brief Check whether the given struct infos can appear in DistIR diff --git a/src/relax/ir/binding_rewrite.cc b/src/relax/ir/binding_rewrite.cc index 1aee7bef780a..8a70f1832440 100644 --- a/src/relax/ir/binding_rewrite.cc +++ b/src/relax/ir/binding_rewrite.cc @@ -235,7 +235,7 @@ std::set GetUnusedVars(Map> users_map, Array fn_output class RemoveUnusedVars : public ExprMutator { public: std::set unused_vars; - Optional caught_rewrite = NullOpt; + Optional caught_rewrite = std::nullopt; RemoveUnusedVars(std::set unused_vars) : unused_vars(std::move(unused_vars)) {} diff --git a/src/relax/ir/block_builder.cc b/src/relax/ir/block_builder.cc index 5f56e7cf453d..db173fe9d069 100644 --- a/src/relax/ir/block_builder.cc +++ b/src/relax/ir/block_builder.cc @@ -162,7 +162,7 @@ class BlockBuilderImpl : public BlockBuilderNode { //------------------------------- Optional LookupBinding(const Var& var) final { auto it = binding_table_.find(var->vid); - if (it == binding_table_.end()) return NullOpt; + if (it == binding_table_.end()) return std::nullopt; return it->second; } @@ -418,8 +418,8 @@ class BlockBuilderImpl : public BlockBuilderNode { name_hint = is_dataflow ? "lv" : "gv"; } Id vid = Id(GetUniqueName(name_hint)); - return is_dataflow ? DataflowVar(vid, /*struct_info_annotation=*/NullOpt) - : Var(vid, /*struct_info_annotation=*/NullOpt); + return is_dataflow ? DataflowVar(vid, /*struct_info_annotation=*/std::nullopt) + : Var(vid, /*struct_info_annotation=*/std::nullopt); } private: @@ -866,12 +866,12 @@ class Normalizer : public BlockBuilderImpl, private ExprFunctor Optional { auto it = curr_scope->shape_var_map.find(var); if (it != curr_scope->shape_var_map.end()) return (*it).second; - return NullOpt; + return std::nullopt; }; return EraseToWellDefined(info, f_shape_var_map); } - Expr VisitWithNewScope(const Expr& expr, Optional> params = NullOpt) { + Expr VisitWithNewScope(const Expr& expr, Optional> params = std::nullopt) { if (params.defined()) { this->BeginScope(params.value()); } else { diff --git a/src/relax/ir/dataflow_block_rewriter.cc b/src/relax/ir/dataflow_block_rewriter.cc index 661c43842db4..b82269f22813 100644 --- a/src/relax/ir/dataflow_block_rewriter.cc +++ b/src/relax/ir/dataflow_block_rewriter.cc @@ -201,7 +201,7 @@ static std::optional TryValidate( if (auto ptr = current_match.matched(p_node)) { return GetRef(ptr); } else { - return NullOpt; + return std::nullopt; } }; @@ -340,14 +340,14 @@ Optional> MatchGraph(const PatternContext& ctx, } if (roots.empty()) { - return NullOpt; + return std::nullopt; } arith::Analyzer analyzer; auto match = MatchTree({}, 0, pattern2node, var2node, &matcher, roots, ctx->validation_constraints, ud_analysis, &analyzer); if (!match) { - return NullOpt; + return std::nullopt; } Map ret; @@ -397,7 +397,7 @@ class PatternContextRewriterNode : public PatternMatchingRewriterNode { } } - return NullOpt; + return std::nullopt; } }; diff --git a/src/relax/ir/dataflow_expr_rewriter.cc b/src/relax/ir/dataflow_expr_rewriter.cc index da1614f50b47..1c5aa4a0cc37 100644 --- a/src/relax/ir/dataflow_expr_rewriter.cc +++ b/src/relax/ir/dataflow_expr_rewriter.cc @@ -256,7 +256,7 @@ Optional ExprPatternRewriterNode::RewriteExpr(const Expr& expr, return rewritten_expr.value(); } } - return NullOpt; + return std::nullopt; } TVM_REGISTER_GLOBAL("relax.dpl.PatternRewriter") @@ -780,7 +780,8 @@ PatternMatchingRewriter PatternMatchingRewriter::FromModule(IRModule mod) { return SeqExpr(new_blocks, func_replacement->body->body); }; - return PatternMatchingRewriter::FromPattern(top_pattern, rewriter_func, NullOpt, new_subroutines); + return PatternMatchingRewriter::FromPattern(top_pattern, rewriter_func, std::nullopt, + new_subroutines); } Optional> ExtractMatchedExpr(DFPattern pattern, Expr expr, @@ -789,7 +790,7 @@ Optional> ExtractMatchedExpr(DFPattern pattern, Expr expr, DFPatternMatcher matcher(bindings); if (!matcher.Match(pattern, expr)) { - return NullOpt; + return std::nullopt; } return matcher.GetMemo(); @@ -857,7 +858,7 @@ class PatternMatchingMutator : public ExprMutator { // If the SeqExpr's output is not a variable, treat it as if it // were the last variable binding of the last block. This // simplifies the special handling of the SeqExpr's body. - Optional dummy_output_var = NullOpt; + Optional dummy_output_var = std::nullopt; if (!seq->body->IsInstance()) { dummy_output_var = Var("dummy_output_var", GetStructInfo(seq->body)); VarBinding dummy_binding(dummy_output_var.value(), seq->body); @@ -991,7 +992,7 @@ class PatternMatchingMutator : public ExprMutator { auto new_blocks = old_blocks.Map(visit_block); if (old_blocks.same_as(new_blocks)) { - return NullOpt; + return std::nullopt; } // Restore the body of the SeqExpr, if needed. diff --git a/src/relax/ir/dataflow_matcher.cc b/src/relax/ir/dataflow_matcher.cc index 1176f1eaee7e..8a4ca3f7ba0a 100644 --- a/src/relax/ir/dataflow_matcher.cc +++ b/src/relax/ir/dataflow_matcher.cc @@ -80,7 +80,7 @@ Expr DFPatternMatcher::UnwrapBindings(Expr expr, const Map& var2val) } } - return NullOpt; + return std::nullopt; }; while (auto unwrapped = unwrap(expr)) { @@ -489,7 +489,7 @@ std::tuple SameShapeConstraintNode::AsPrimExpr( } else if (auto shape_expr = sinfo.as()) { return shape_expr->values; } else { - return NullOpt; + return std::nullopt; } }(); @@ -524,8 +524,8 @@ std::tuple SameShapeConstraintNode::AsPrimExpr( } else { // Missing an argument, so the constraint will either return - // NullOpt or false at this point. However, delay the return of - // NullOpt until the end of the function, because we'd rather + // std::nullopt or false at this point. However, delay the return of + // std::nullopt until the end of the function, because we'd rather // return "false" if it possible to do so. all_shapes_defined = false; } diff --git a/src/relax/ir/dataflow_matcher.h b/src/relax/ir/dataflow_matcher.h index c5d58db5b9d0..76f48383c47c 100644 --- a/src/relax/ir/dataflow_matcher.h +++ b/src/relax/ir/dataflow_matcher.h @@ -38,7 +38,7 @@ namespace relax { class DFPatternMatcher : public DFPatternFunctor { public: - using var2val_t = runtime::Map; + using var2val_t = Map; explicit DFPatternMatcher() {} explicit DFPatternMatcher(var2val_t var2val) : var2val_(std::move(var2val)) {} diff --git a/src/relax/ir/dataflow_pattern.cc b/src/relax/ir/dataflow_pattern.cc index f7414faaabb6..7f045ebe486e 100644 --- a/src/relax/ir/dataflow_pattern.cc +++ b/src/relax/ir/dataflow_pattern.cc @@ -424,7 +424,7 @@ DataTypePattern DFPattern::HasDtype(const DataType& dtype) const { return DataTypePattern(*this, dtype); } DataTypePattern DFPattern::HasDtype(const std::string& dtype) const { - return HasDtype(DataType(runtime::StringToDLDataType(dtype))); + return HasDtype(DataType(ffi::StringToDLDataType(dtype))); } ShapePattern DFPattern::HasShape(const Array& shape) const { return ShapePattern(*this, shape); @@ -438,7 +438,7 @@ std::stack& pattern_ctx_stack() { } Optional PatternContext::Current() { - if (pattern_ctx_stack().empty()) return NullOpt; + if (pattern_ctx_stack().empty()) return std::nullopt; return pattern_ctx_stack().top(); } diff --git a/src/relax/ir/dataflow_rewriter.h b/src/relax/ir/dataflow_rewriter.h index 4eec98373d0c..d2016adbf8e7 100644 --- a/src/relax/ir/dataflow_rewriter.h +++ b/src/relax/ir/dataflow_rewriter.h @@ -67,7 +67,7 @@ class PatternMatchingRewriter : public tvm::transform::Pass { public: static PatternMatchingRewriter FromPattern( DFPattern pattern, ffi::TypedFunction(Expr, Map)> func, - Optional> additional_bindings = NullOpt, + Optional> additional_bindings = std::nullopt, Map new_subroutines = {}); static PatternMatchingRewriter FromModule(IRModule mod); @@ -103,7 +103,7 @@ class ExprPatternRewriter : public PatternMatchingRewriter { public: ExprPatternRewriter(DFPattern pattern, ffi::TypedFunction(Expr, Map)> func, - Optional> additional_bindings = NullOpt, + Optional> additional_bindings = std::nullopt, Map new_subroutines = {}); TVM_DEFINE_OBJECT_REF_METHODS(ExprPatternRewriter, PatternMatchingRewriter, @@ -170,7 +170,7 @@ class TupleRewriter : public PatternMatchingRewriter { public: TupleRewriter(Array patterns, ffi::TypedFunction(Expr, Map)> func, - Optional> additional_bindings = NullOpt, + Optional> additional_bindings = std::nullopt, Map new_subroutines = {}); TVM_DEFINE_OBJECT_REF_METHODS(TupleRewriter, PatternMatchingRewriter, TupleRewriterNode); diff --git a/src/relax/ir/emit_te.cc b/src/relax/ir/emit_te.cc index bfb5896c9988..86c38d08a1c1 100644 --- a/src/relax/ir/emit_te.cc +++ b/src/relax/ir/emit_te.cc @@ -49,7 +49,7 @@ te::Tensor TETensor(Expr value, Map tir_var_map, std::string n->dtype = DataType(constant->data->dtype); int ndim = constant->data->ndim; - ShapeTuple shape_tuple = constant->data.Shape(); + ffi::Shape shape_tuple = constant->data.Shape(); Array shape; shape.reserve(ndim); for (int i = 0; i < ndim; ++i) { diff --git a/src/relax/ir/expr.cc b/src/relax/ir/expr.cc index 4f8a1b6c650d..4981e9b9f850 100644 --- a/src/relax/ir/expr.cc +++ b/src/relax/ir/expr.cc @@ -27,7 +27,6 @@ namespace tvm { namespace relax { using tvm::ReprPrinter; -using tvm::runtime::Optional; TVM_REGISTER_NODE_TYPE(IdNode); @@ -145,7 +144,7 @@ Tuple::Tuple(tvm::Array fields, Span span) { if (field->struct_info_.defined()) { field_sinfo.push_back(GetStructInfo(field)); } else { - return NullOpt; + return std::nullopt; } } return TupleStructInfo(field_sinfo); @@ -346,7 +345,8 @@ Constant::Constant(runtime::NDArray data, Optional struct_info_annot TVM_REGISTER_NODE_TYPE(ConstantNode); TVM_REGISTER_GLOBAL("relax.Constant") - .set_body_typed([](runtime::NDArray data, Optional struct_info_annotation = NullOpt, + .set_body_typed([](runtime::NDArray data, + Optional struct_info_annotation = std::nullopt, Span span = Span()) { return Constant(data, struct_info_annotation, span); }); @@ -602,7 +602,7 @@ Function::Function(Array params, Expr body, Optional ret_struct if (lookup.count(var)) { return var; } else { - return NullOpt; + return std::nullopt; } }; }(); @@ -741,7 +741,7 @@ TVM_REGISTER_GLOBAL("relax.FuncWithAttr") if (func->IsInstance()) { return WithAttr(Downcast(std::move(func)), key, value); } - return NullOpt; + return std::nullopt; }); TVM_REGISTER_GLOBAL("relax.FuncWithAttrs") @@ -749,7 +749,7 @@ TVM_REGISTER_GLOBAL("relax.FuncWithAttrs") if (func->IsInstance()) { return WithAttrs(Downcast(std::move(func)), attr_map); } - return NullOpt; + return std::nullopt; }); TVM_REGISTER_GLOBAL("relax.FuncWithoutAttr") @@ -757,7 +757,7 @@ TVM_REGISTER_GLOBAL("relax.FuncWithoutAttr") if (func->IsInstance()) { return WithoutAttr(Downcast(std::move(func)), key); } - return NullOpt; + return std::nullopt; }); } // namespace relax diff --git a/src/relax/ir/expr_functor.cc b/src/relax/ir/expr_functor.cc index a450919decff..0b497a97de92 100644 --- a/src/relax/ir/expr_functor.cc +++ b/src/relax/ir/expr_functor.cc @@ -601,7 +601,7 @@ Expr ExprMutator::VisitExpr_(const FunctionNode* op) { // example, if the previous return value was // `TensorStructInfo(shape=[16,16])`, but the new return value is // `TensorStructInfo(shape=[8,8])`. - return Function(params, body, NullOpt, op->is_pure, op->attrs); + return Function(params, body, std::nullopt, op->is_pure, op->attrs); } } diff --git a/src/relax/ir/struct_info.cc b/src/relax/ir/struct_info.cc index 28049e941c39..38e54d4794a5 100644 --- a/src/relax/ir/struct_info.cc +++ b/src/relax/ir/struct_info.cc @@ -53,7 +53,7 @@ PrimStructInfo::PrimStructInfo(PrimExpr value, Span span) { PrimStructInfo::PrimStructInfo(DataType dtype, Span span) { ObjectPtr n = make_object(); n->dtype = dtype; - n->value = NullOpt; + n->value = std::nullopt; n->span = span; data_ = std::move(n); } diff --git a/src/relax/op/memory/view.cc b/src/relax/op/memory/view.cc index 21a72f6200b0..0b8243a88977 100644 --- a/src/relax/op/memory/view.cc +++ b/src/relax/op/memory/view.cc @@ -136,7 +136,7 @@ StructInfo InferStructInfoView(const Call& call, const BlockBuilder& ctx) { return prim_sinfo->value.value(); } else { // An offset of unknown value is applied. - return NullOpt; + return std::nullopt; } } else { LOG(FATAL) << "TypeError: " @@ -149,7 +149,7 @@ StructInfo InferStructInfoView(const Call& call, const BlockBuilder& ctx) { Optional> input_shape = data_sinfo->GetShape(); - Optional> output_shape = NullOpt; + Optional> output_shape = std::nullopt; int output_ndim = kUnknownNDim; if (view_shape_sinfo && view_shape_sinfo->values.defined()) { output_shape = view_shape_sinfo->values.value(); @@ -168,7 +168,7 @@ StructInfo InferStructInfoView(const Call& call, const BlockBuilder& ctx) { // number of bytes per scalar element. auto get_size_bytes = [](const DataType& dtype) -> Optional { if (dtype.is_void()) { - return NullOpt; + return std::nullopt; } else { auto size_bits = dtype.bits() * dtype.lanes(); return IntImm(DataType::Int(64), (size_bits + 7) / 8); @@ -179,7 +179,7 @@ StructInfo InferStructInfoView(const Call& call, const BlockBuilder& ctx) { // given the shape of that array. auto get_num_elements = [&ctx](const Optional>& shape) -> Optional { if (!shape.defined()) { - return NullOpt; + return std::nullopt; } PrimExpr num_elements = Integer(1); diff --git a/src/relax/op/nn/attention.cc b/src/relax/op/nn/attention.cc index ca3746ddad4e..d6e7fa707d73 100644 --- a/src/relax/op/nn/attention.cc +++ b/src/relax/op/nn/attention.cc @@ -137,8 +137,8 @@ StructInfo InferStructInfoAttention(const Call& call, const BlockBuilder& ctx) { } Call InferMixedPrecisionAttention(const Call& call, const DataType& out_dtype) { - return Downcast( - attention(call->args[0], call->args[1], call->args[2], NullOpt, NullOpt, NullOpt, NullOpt)); + return Downcast(attention(call->args[0], call->args[1], call->args[2], std::nullopt, + std::nullopt, std::nullopt, std::nullopt)); } TVM_REGISTER_OP("relax.nn.attention") diff --git a/src/relax/op/op.cc b/src/relax/op/op.cc index bb3d645adea4..94fabd2d0ede 100644 --- a/src/relax/op/op.cc +++ b/src/relax/op/op.cc @@ -258,11 +258,11 @@ TVM_REGISTER_GLOBAL("relax.op.call_inplace_packed").set_body_typed(MakeCallInpla * If the arguments provided are not compatible with the PrimFunc's * signature, an error will be raised. If the arguments are * compatible with the PrimFunc's signature, but are not sufficient to - * determine the output's StructInfo, then `NullOpt` will be returned. + * determine the output's StructInfo, then `std::nullopt` will be returned. * * \param func_sinfo The StructInfo of the TIR callee. * \param arg_sinfo The StructInfo of the argument tuple. - * \param packed_ints_sinfo The StructInfo of the ShapeTuple argument, + * \param packed_ints_sinfo The StructInfo of the ffi::Shape argument, * if present. * \param opt_inplace_indices For `R.call_tir_inplace`, an array of * indices indicating which outputs are constructed from in-place @@ -270,7 +270,7 @@ TVM_REGISTER_GLOBAL("relax.op.call_inplace_packed").set_body_typed(MakeCallInpla * `CallTIRInplaceAttrs::inplace_indices` for more details. * * \return The `arg_sinfo`, if it can be inferred from the arguments. - * Otherwise, NullOpt. + * Otherwise, std::nullopt. */ static Optional InferCallTIROutputStructInfoFromArguments( StructInfo func_sinfo, StructInfo arg_sinfo, Optional packed_ints_sinfo, @@ -311,7 +311,7 @@ static Optional InferCallTIROutputStructInfoFromArguments( CHECK(packed_tuple_sinfo && !packed_tuple_sinfo->IsUnknownNdim()) << "TypeError: " << "The third argument to `R.call_tir`, if present, " - << "must be a ShapeTuple with known dimensionality. " + << "must be a ffi::Shape with known dimensionality. " << "However, the argument received was of type " << packed_sinfo; num_trailing_int_arguments = packed_tuple_sinfo->ndim; } else { @@ -338,7 +338,7 @@ static Optional InferCallTIROutputStructInfoFromArguments( } }; if (contains_dtensor(arg_sinfo)) { - return NullOpt; + return std::nullopt; } // At this point, the return types are known. However, the shapes @@ -413,7 +413,7 @@ static Optional InferCallTIROutputStructInfoFromArguments( auto derived_ret_sinfo = DeriveCallRetStructInfo( dummy_callee_sinfo, Call(Var("dummy_callee", dummy_callee_sinfo), dummy_args), - BlockBuilder::Create(NullOpt)); + BlockBuilder::Create(std::nullopt)); return derived_ret_sinfo; } @@ -466,7 +466,7 @@ Expr NormalizeCallTIR(const BlockBuilder& ctx, Call call) { Expr packed_ints = call->args[2]; CHECK(packed_ints->struct_info_.as()) << "Operation " << call->op << " expects the optional third argument, " - << "if present, to be a ShapeTuple. " + << "if present, to be a ffi::Shape. " << "However, the third argument " << packed_ints << " has struct info " << packed_ints->struct_info_; } @@ -481,7 +481,7 @@ Expr NormalizeCallTIR(const BlockBuilder& ctx, Call call) { return bound_value.value(); } } - return NullOpt; + return std::nullopt; }; Tuple new_arg_tuple = [&]() { @@ -535,7 +535,7 @@ void ValidateCallTIR(Call call) { auto packed_int_sinfo = [&]() -> Optional { if (call->args.size() <= 2) { - return NullOpt; + return std::nullopt; } else { return GetStructInfo(call->args[2]); } @@ -545,7 +545,7 @@ void ValidateCallTIR(Call call) { if (const auto* attrs = call->attrs.as()) { return attrs->inplace_indices; } else { - return NullOpt; + return std::nullopt; } }(); diff --git a/src/relax/op/op_common.cc b/src/relax/op/op_common.cc index f9c1ece38c18..f439a345eb19 100644 --- a/src/relax/op/op_common.cc +++ b/src/relax/op/op_common.cc @@ -136,7 +136,7 @@ Optional> InferBinaryBroadcastShape(const Call& call, const Bloc << " is " << dim1 << ", which are not broadcastable."); } else { // Use simple fallback when shape mismatch. - return NullOpt; + return std::nullopt; } } auto& longer_shape = (x1_ndim > x2_ndim) ? x1_shape : x2_shape; diff --git a/src/relax/op/op_common.h b/src/relax/op/op_common.h index 85a3d885dce8..df29d9c88503 100644 --- a/src/relax/op/op_common.h +++ b/src/relax/op/op_common.h @@ -344,7 +344,7 @@ inline Optional InferBinaryArithOpOutVDevice(const Call& call, const Bl if (const auto* tensor = sinfo.as()) { return tensor->vdevice; } else { - return NullOpt; + return std::nullopt; } }; @@ -374,8 +374,8 @@ inline Optional InferBinaryArithOpOutVDevice(const Call& call, const Bl * \param ctx The error reporting context. * \param x1_shape The shape of the first operand. * \param x2_shape The shape of the second operand. - * \return The inferred output shape after broadcasting. Or `NullOpt` if the output shape cannot be - * determined due to symbolic broadcast. + * \return The inferred output shape after broadcasting. Or `std::nullopt` if the output shape + * cannot be determined due to symbolic broadcast. */ Optional> InferBinaryBroadcastShape(const Call& call, const BlockBuilder& ctx, const Array& x1_shape, @@ -536,7 +536,7 @@ inline std::pair CheckTensorLayout(const Call * \param ctx The error reporting context. * \param sinfo The input tensor struct info to be checked. * \param layout The layout that the given tensor is expected to have. - * \return The shape of the input tensor in ShapeExpr, or `NullOpt` if the shape is unknown. + * \return The shape of the input tensor in ShapeExpr, or `std::nullopt` if the shape is unknown. */ inline Optional CheckNdimPerLayoutAndGetShape(const Call& call, const BlockBuilder& ctx, const TensorStructInfo& sinfo, @@ -550,7 +550,7 @@ inline Optional CheckNdimPerLayoutAndGetShape(const Call& call, const if (const auto* shape_expr = sinfo->shape.as()) { return GetRef(shape_expr); } - return NullOpt; + return std::nullopt; } Expr MakeVMAllocStorage(Expr size, PrimValue runtime_device_index, DataTypeImm dtype, diff --git a/src/relax/op/tensor/binary.cc b/src/relax/op/tensor/binary.cc index e7fab8f166e1..74ae8e9cbc5c 100644 --- a/src/relax/op/tensor/binary.cc +++ b/src/relax/op/tensor/binary.cc @@ -92,7 +92,7 @@ StructInfo InferStructInfoBroadcast(const Call& call, const BlockBuilder& ctx, } else if (const auto* tensor = sinfo.as()) { return tensor->GetShape(); } else { - return NullOpt; + return std::nullopt; } }; @@ -113,7 +113,7 @@ StructInfo InferStructInfoBroadcast(const Call& call, const BlockBuilder& ctx, if (const auto* tensor = sinfo.as()) { return tensor->shape; } else { - return NullOpt; + return std::nullopt; } }; diff --git a/src/relax/op/tensor/create.cc b/src/relax/op/tensor/create.cc index 361f90c7b043..c06b51ae2e66 100644 --- a/src/relax/op/tensor/create.cc +++ b/src/relax/op/tensor/create.cc @@ -40,7 +40,7 @@ Expr full(Variant> shape, Expr fill_value, Optional()) { shape_in_expr = GetRef(expr); - } else if (const auto* _array = shape.as()) { + } else if (const auto* _array = shape.as()) { shape_in_expr = ShapeExpr(GetRef>(_array)); } else { LOG(FATAL) diff --git a/src/relax/op/tensor/create.h b/src/relax/op/tensor/create.h index 5f770b2a6ed9..0bf15bbd57e7 100644 --- a/src/relax/op/tensor/create.h +++ b/src/relax/op/tensor/create.h @@ -24,8 +24,8 @@ #ifndef TVM_RELAX_OP_TENSOR_CREATE_H_ #define TVM_RELAX_OP_TENSOR_CREATE_H_ +#include #include -#include #include "../op_common.h" diff --git a/src/relax/op/tensor/index.cc b/src/relax/op/tensor/index.cc index 4e62a9ecd7d7..8f262ce38da7 100644 --- a/src/relax/op/tensor/index.cc +++ b/src/relax/op/tensor/index.cc @@ -190,17 +190,17 @@ TVM_REGISTER_GLOBAL("relax.op.strided_slice").set_body_typed(strided_slice); * \param sinfo The StructInfo to inspect * * \returns An array of the `PrimType`, if it can be extracted. - * Otherwise, `NullOpt`. + * Otherwise, `std::nullopt`. */ template >> Optional> UnpackTupleOfPrimValue(Optional sinfo) { - if (!sinfo) return NullOpt; + if (!sinfo) return std::nullopt; // An ObjectStructInfo may contain a tuple of the desired type, but // it isn't yet known whether it does. Return early, as we cannot // provide a known `Array` to the caller. - if (sinfo.as()) return NullOpt; + if (sinfo.as()) return std::nullopt; auto tuple = sinfo.as(); CHECK(tuple) << "TypeError: " @@ -211,7 +211,7 @@ Optional> UnpackTupleOfPrimValue(Optional sinfo) { for (size_t i = 0; i < tuple->fields.size(); i++) { auto field = tuple->fields[i]; - if (field.as()) return NullOpt; + if (field.as()) return std::nullopt; auto prim_sinfo = field.as(); CHECK(prim_sinfo) << "TypeError: " @@ -220,7 +220,7 @@ Optional> UnpackTupleOfPrimValue(Optional sinfo) { << PrimType::ContainerType::_type_key << ", because element " << i << " has struct info " << field; - if (!prim_sinfo->value.defined()) return NullOpt; + if (!prim_sinfo->value.defined()) return std::nullopt; Optional element = prim_sinfo->value.as(); if (!element) return std::nullopt; @@ -249,7 +249,7 @@ Optional> UnpackTupleOfPrimValue(Optional sinfo) { * \param expr The `relax::Expr` to inspect * * \returns An array of the `PrimType`, if it can be extracted. - * Otherwise, `NullOpt`. + * Otherwise, `std::nullopt`. */ template >> @@ -257,7 +257,7 @@ Optional> UnpackTupleOfPrimValue(Optional expr) { if (expr) { return UnpackTupleOfPrimValue(GetStructInfo(expr.value())); } else { - return NullOpt; + return std::nullopt; } } @@ -276,7 +276,7 @@ StructInfo InferStructInfoStridedSlice(const Call& call, const BlockBuilder& ctx if (n_args > 4) { return call->args[4]; } else { - return NullOpt; + return std::nullopt; } }(); @@ -287,7 +287,7 @@ StructInfo InferStructInfoStridedSlice(const Call& call, const BlockBuilder& ctx if (n_args > 4) { return GetStructInfo(call->args[4]); } else { - return NullOpt; + return std::nullopt; } }(); @@ -329,7 +329,7 @@ StructInfo InferStructInfoStridedSlice(const Call& call, const BlockBuilder& ctx const auto* data_sinfo = data->struct_info_.as(); DataType dtype = DataType::Void(); - Optional vdevice = NullOpt; + Optional vdevice = std::nullopt; int ndim = kUnknownNDim; if (data_sinfo) { dtype = data_sinfo->dtype; @@ -338,15 +338,15 @@ StructInfo InferStructInfoStridedSlice(const Call& call, const BlockBuilder& ctx } Optional shape = [&]() -> Optional { - if (!data_sinfo) return NullOpt; - if (!data_sinfo->shape) return NullOpt; + if (!data_sinfo) return std::nullopt; + if (!data_sinfo->shape) return std::nullopt; auto opt_axes_tuple = UnpackTupleOfPrimValue(axes); - if (!opt_axes_tuple) return NullOpt; + if (!opt_axes_tuple) return std::nullopt; auto axes_tuple = opt_axes_tuple.value(); auto opt_begin_tuple = UnpackTupleOfPrimValue(begin); - if (!opt_begin_tuple) return NullOpt; + if (!opt_begin_tuple) return std::nullopt; auto begin_tuple = opt_begin_tuple.value(); CHECK_EQ(axes_tuple.size(), begin_tuple.size()) @@ -356,7 +356,7 @@ StructInfo InferStructInfoStridedSlice(const Call& call, const BlockBuilder& ctx << ") and " << begin_tuple.size() << " 'begin' indices specified (" << begin_tuple << ")"; auto opt_end_tuple = UnpackTupleOfPrimValue(end); - if (!opt_end_tuple) return NullOpt; + if (!opt_end_tuple) return std::nullopt; auto end_tuple = opt_end_tuple.value(); CHECK_EQ(axes_tuple.size(), end_tuple.size()) @@ -368,7 +368,7 @@ StructInfo InferStructInfoStridedSlice(const Call& call, const BlockBuilder& ctx Array strides_tuple; if (strides.defined()) { auto opt_strides_tuple = UnpackTupleOfPrimValue(strides); - if (!opt_strides_tuple) return NullOpt; + if (!opt_strides_tuple) return std::nullopt; strides_tuple = opt_strides_tuple.value(); } else { @@ -387,7 +387,7 @@ StructInfo InferStructInfoStridedSlice(const Call& call, const BlockBuilder& ctx if (axes_tuple.empty() && !opt_data_shape.defined()) { return data_sinfo->shape.value(); } else if (!opt_data_shape.defined()) { - return NullOpt; + return std::nullopt; } std::vector axes = NormalizeAxes(call, ctx, data_sinfo->ndim, axes_tuple); diff --git a/src/relax/op/tensor/index.h b/src/relax/op/tensor/index.h index 46b5fd501b95..63a12e28f622 100644 --- a/src/relax/op/tensor/index.h +++ b/src/relax/op/tensor/index.h @@ -37,7 +37,7 @@ namespace relax { * \param indices The indices of the values to extract. * It is required to be a one-dimensional tensor which has integer dtype. * \param axis The axis over which to select values. - * If it is `NullOpt`, the input tensor is required to be one-dimensional. + * If it is `std::nullopt`, the input tensor is required to be one-dimensional. * \return The taken result. */ Expr take(Expr x, Expr indices, Optional axis); @@ -50,11 +50,11 @@ Expr take(Expr x, Expr indices, Optional axis); * \param end The indices indicating end of the slice, exclusive. * \param strides Specifies the stride values, it can be negative in that case, * the input tensor will be reversed in that particular axis. - * If it is `NullOpt`, it by default is an list of ones of the same length as `axes`. + * If it is `std::nullopt`, it by default is an list of ones of the same length as `axes`. * \param assume_inbound Whether to assume the indices are in bound. * \return The sliced result */ -Expr strided_slice(Expr x, Expr axes, Expr begin, Expr end, Optional strides = NullOpt, +Expr strided_slice(Expr x, Expr axes, Expr begin, Expr end, Optional strides = std::nullopt, bool assume_inbound = false); } // namespace relax diff --git a/src/relax/op/tensor/manipulate.cc b/src/relax/op/tensor/manipulate.cc index d3da5a5e1199..9b653046f76a 100644 --- a/src/relax/op/tensor/manipulate.cc +++ b/src/relax/op/tensor/manipulate.cc @@ -171,7 +171,7 @@ Optional> CheckConcatOutputShape(const Call& call, const BlockBu } if (shape_unknown) { - return NullOpt; + return std::nullopt; } Array output_shape = shape_values[0]; output_shape.Set(axis, concat_sum); @@ -192,7 +192,7 @@ StructInfo InferStructInfoConcat(const Call& call, const BlockBuilder& ctx) { const auto* attrs = call->attrs.as(); int output_ndim = attrs->axis.has_value() ? kUnknownNDim : 1; DataType output_dtype = DataType::Void(); - Optional vdev = NullOpt; + Optional vdev = std::nullopt; bool shape_unknown = false; bool is_void_dtype = false; bool vdevice_unknown = false; @@ -260,7 +260,7 @@ StructInfo InferStructInfoConcat(const Call& call, const BlockBuilder& ctx) { output_dtype = DataType::Void(); } if (vdevice_unknown) { - vdev = NullOpt; + vdev = std::nullopt; } if (output_ndim == kUnknownNDim) { @@ -812,16 +812,16 @@ TVM_REGISTER_OP("relax.permute_dims") /* relax.reshape */ Expr ConvertNewShapeToExpr(const Expr& data, const Variant>& shape) { - const ArrayObj* array; + const ffi::ArrayObj* array; // Treat shape expressions as constant arrays to handle special values. if (const auto* e = shape.as()) { - array = e->values.as(); + array = e->values.as(); // Other non-shape expressions are used directly. } else if (const auto* e = shape.as()) { return GetRef(e); // Process special values in constants and produce an expression. } else { - array = shape.as(); + array = shape.as(); } CHECK(array != nullptr) << "Reshape only expects the input new shape to be either an Expr or an " "Array of PrimExprs. However, the given new shape is " @@ -973,7 +973,7 @@ Expr split(Expr x, Variant> indices_or_sections, int axis) ObjectPtr attrs = make_object(); ObjectRef indices_or_sections_obj; - if (const auto* indices = indices_or_sections.as()) { + if (const auto* indices = indices_or_sections.as()) { for (int i = 0; i < static_cast(indices->size()); ++i) { const auto* idx = indices->at(i).as(); CHECK(idx != nullptr) << "Split op only accepts an array of integers as the indices. " @@ -1373,7 +1373,7 @@ Optional> CheckStackOutputShape(const Call& call, const BlockBui } if (shape_unknown) { - return NullOpt; + return std::nullopt; } // Insert new dimension at axis position @@ -1406,7 +1406,7 @@ StructInfo InferStructInfoStack(const Call& call, const BlockBuilder& ctx) { // Default axis is 0 if not specified int output_ndim = tensor_sinfo[0]->ndim + 1; // Stack adds one dimension DataType output_dtype = DataType::Void(); - Optional vdev = NullOpt; + Optional vdev = std::nullopt; bool shape_unknown = false; bool is_void_dtype = false; bool vdevice_unknown = false; @@ -1459,7 +1459,7 @@ StructInfo InferStructInfoStack(const Call& call, const BlockBuilder& ctx) { } if (is_void_dtype) output_dtype = DataType::Void(); - if (vdevice_unknown) vdev = NullOpt; + if (vdevice_unknown) vdev = std::nullopt; // Normalize axis (default to 0 if not specified) int axis = @@ -2124,7 +2124,7 @@ StructInfo InferStructInfoMeshgrid(const Call& call, const BlockBuilder& ctx) { std::vector lengths; DataType common_dtype = DataType::Void(); bool shape_unknown = false; - Optional vdev = NullOpt; + Optional vdev = std::nullopt; bool vdevice_unknown = false; for (int i = 0; i < n_inputs; ++i) { diff --git a/src/relax/op/tensor/manipulate.h b/src/relax/op/tensor/manipulate.h index 9f0c86abd2fb..7d42b50838c4 100644 --- a/src/relax/op/tensor/manipulate.h +++ b/src/relax/op/tensor/manipulate.h @@ -24,8 +24,8 @@ #ifndef TVM_RELAX_OP_TENSOR_MANIPULATE_H_ #define TVM_RELAX_OP_TENSOR_MANIPULATE_H_ +#include #include -#include #include "../op_common.h" #include "tvm/relax/expr.h" @@ -41,7 +41,7 @@ Expr broadcast_to(Expr x, Expr shape); * \param tensors An Expr in Tuple type, containing the tensors to be concatenated, * or a list of tensors * \param axis The axis along which the tensors are concatenated. - * If it is `NullOpt`, the input tensor is required to be flattened before concatenation. + * If it is `std::nullopt`, the input tensor is required to be flattened before concatenation. * \return The concatenated tensor. */ Expr concat(Expr tensors, Optional axis); @@ -74,7 +74,7 @@ Expr flatten(Expr x); */ Expr layout_transform(Expr x, tir::IndexMap index_map, Optional pad_value, Optional> axis_separators, - Optional> input_axis_separators = NullOpt); + Optional> input_axis_separators = std::nullopt); /*! * \brief Permutes the dimensions of an array. @@ -113,7 +113,7 @@ Expr split(Expr x, Variant> indices_or_sections, int axis) * \brief Squeeze axes in the array. * \param x The input data to the operator. * \param axis The set of axes to remove. - * If it is `NullOpt`, remove all axis of dimensions 1. + * If it is `std::nullopt`, remove all axis of dimensions 1. * If any specified axis has dimension that does not equal 1, it is an error. * \return The squeezed result. */ @@ -154,7 +154,7 @@ Expr collapse_sum_to(Expr data, Expr shape); * from the backward. By default, use the flattened input array, and return a flat output array. * \return The computed result. */ -Expr repeat(Expr data, int repeats, Optional axis = NullOpt); +Expr repeat(Expr data, int repeats, Optional axis = std::nullopt); /*! * \brief Construct an array by repeating data the number of times given by reps. diff --git a/src/relax/op/tensor/set.cc b/src/relax/op/tensor/set.cc index e2aef8005e78..f2f840ba3154 100644 --- a/src/relax/op/tensor/set.cc +++ b/src/relax/op/tensor/set.cc @@ -130,10 +130,10 @@ TVM_REGISTER_OP("relax.unique") "original input ended up in the returned unique list.") .add_argument("return_counts", "Tensor", "Whether to return an additional tensor with counts of each unique elements") - .add_argument( - "axis", "Tensor", - "The dimension to apply unique. If it is NullOpt, the unique values of the flattened input " - "are returned.") + .add_argument("axis", "Tensor", + "The dimension to apply unique. If it is std::nullopt, the unique values of the " + "flattened input " + "are returned.") .set_attr("FInferStructInfo", InferStructInfoUnique) .set_attr("FCallPacked", "relax.run.unique") .set_attr("FPurity", Bool(true)); diff --git a/src/relax/op/tensor/statistical.h b/src/relax/op/tensor/statistical.h index c527ba363894..aa312f5df766 100644 --- a/src/relax/op/tensor/statistical.h +++ b/src/relax/op/tensor/statistical.h @@ -61,12 +61,10 @@ namespace relax { /*! * \brief Computes the maximum value of tensor elements over given axes. * \param x The input data tensor - * \param axis Axis or axes along which a max is performed. Being `NullOpt` means to max all the - * elements of the input tensor - * \param keepdims If this is set to True, the axes which are reduced are left in the result as - * dimensions with size one. With this option, the result will broadcast correctly against the - * input tensor. - * \return The result after reduction. + * \param axis Axis or axes along which a max is performed. Being `std::nullopt` means to max all + * the elements of the input tensor \param keepdims If this is set to True, the axes which are + * reduced are left in the result as dimensions with size one. With this option, the result will + * broadcast correctly against the input tensor. \return The result after reduction. */ Expr max(Expr x, Optional> axis, bool keepdims); @@ -98,8 +96,8 @@ Expr sum(Expr x, Optional> axis, bool keepdims); * \return The computed * result. */ -Expr cumprod(Expr data, Optional axis = NullOpt, Optional dtype = NullOpt, - Bool exclusive = Bool(false)); +Expr cumprod(Expr data, Optional axis = std::nullopt, + Optional dtype = std::nullopt, Bool exclusive = Bool(false)); /*! * \brief Numpy style cumsum op. Return the cumulative inclusive sum of the elements along @@ -113,8 +111,8 @@ Expr cumprod(Expr data, Optional axis = NullOpt, Optional dty * which the first element is not included. * \return The computed result. */ -Expr cumsum(Expr data, Optional axis = NullOpt, Optional dtype = NullOpt, - Bool exclusive = Bool(false)); +Expr cumsum(Expr data, Optional axis = std::nullopt, + Optional dtype = std::nullopt, Bool exclusive = Bool(false)); /*! \brief Computes the variance of tensor elements over given axes. */ Expr variance(Expr x, Optional> axis, bool keepdims); diff --git a/src/relax/training/utils.cc b/src/relax/training/utils.cc index 101217c15463..43fa2357f09d 100644 --- a/src/relax/training/utils.cc +++ b/src/relax/training/utils.cc @@ -77,7 +77,7 @@ class AppendLossMutator : private ExprMutator { loss_function_->params.end()); Expr new_body = this->VisitExpr(func->body); - return Function(new_params, new_body, NullOpt, func->is_pure, func->attrs); + return Function(new_params, new_body, std::nullopt, func->is_pure, func->attrs); } Expr VisitExpr_(const SeqExprNode* seq_expr) final { diff --git a/src/relax/training/utils.h b/src/relax/training/utils.h index f280308f9d51..1bfb20da3521 100644 --- a/src/relax/training/utils.h +++ b/src/relax/training/utils.h @@ -51,7 +51,7 @@ namespace transform { * \return The Pass. */ TVM_DLL Pass AppendLoss(String func_name, Function loss_function, int num_backbone_outputs = 1, - Optional new_func_name = NullOpt); + Optional new_func_name = std::nullopt); } // namespace transform } // namespace relax diff --git a/src/relax/transform/adjust_matmul_order.cc b/src/relax/transform/adjust_matmul_order.cc index 79749cb41693..8d268cfef7f3 100644 --- a/src/relax/transform/adjust_matmul_order.cc +++ b/src/relax/transform/adjust_matmul_order.cc @@ -106,7 +106,7 @@ std::tuple)>> Crea if (sinfo) { return sinfo->GetShape(); } else { - return NullOpt; + return std::nullopt; } }; @@ -122,15 +122,15 @@ std::tuple)>> Crea auto shape_c = opt_shape_c.value(); if (matches.count(pat_permuted_matmul_on_lhs)) { - expr_a = permute_dims(expr_a, NullOpt); - expr_b = permute_dims(expr_b, NullOpt); + expr_a = permute_dims(expr_a, std::nullopt); + expr_b = permute_dims(expr_b, std::nullopt); CHECK_EQ(shape_a.size(), 2); CHECK_EQ(shape_b.size(), 2); shape_a = {shape_a[1], shape_a[0]}; shape_b = {shape_b[1], shape_b[0]}; } else if (matches.count(pat_permuted_matmul_on_rhs)) { - expr_b = permute_dims(expr_b, NullOpt); - expr_c = permute_dims(expr_c, NullOpt); + expr_b = permute_dims(expr_b, std::nullopt); + expr_c = permute_dims(expr_c, std::nullopt); CHECK_EQ(shape_b.size(), 2); CHECK_EQ(shape_c.size(), 2); shape_b = {shape_b[1], shape_b[0]}; diff --git a/src/relax/transform/canonicalize_bindings.cc b/src/relax/transform/canonicalize_bindings.cc index 807914075e8d..3d8c65de95a6 100644 --- a/src/relax/transform/canonicalize_bindings.cc +++ b/src/relax/transform/canonicalize_bindings.cc @@ -122,7 +122,7 @@ class SymbolicVarCanonicalizer : public ExprMutator { if (auto it = known_values_.find(var); it != known_values_.end()) { return it->second.expr; } else { - return NullOpt; + return std::nullopt; } }); if (output.same_as(expr)) { @@ -301,22 +301,22 @@ class CanonicalizePlanner : public ExprVisitor { auto earlier_tuple = [&]() -> Optional { auto expr_tuple = expr.as(); if (!expr_tuple) { - return NullOpt; + return std::nullopt; } if (expr_tuple->fields.empty()) { - return NullOpt; + return std::nullopt; } auto first_element = recursively_unwrap_var(expr_tuple->fields[0]).as(); if (!first_element) { - return NullOpt; + return std::nullopt; } auto earlier_tuple_size = Downcast(GetStructInfo(first_element->tuple))->fields.size(); if (earlier_tuple_size != expr_tuple->fields.size()) { - return NullOpt; + return std::nullopt; } Expr earlier_tuple = recursively_unwrap_var(first_element->tuple); @@ -324,16 +324,16 @@ class CanonicalizePlanner : public ExprVisitor { for (size_t i = 0; i < expr_tuple->fields.size(); i++) { auto element = recursively_unwrap_var(expr_tuple->fields[i]).as(); if (!element) { - return NullOpt; + return std::nullopt; } if (static_cast(element->index) != i) { - return NullOpt; + return std::nullopt; } auto source_of_element = recursively_unwrap_var(element->tuple); if (!earlier_tuple.same_as(source_of_element)) { - return NullOpt; + return std::nullopt; } } @@ -343,7 +343,7 @@ class CanonicalizePlanner : public ExprVisitor { return earlier_tuple.value(); } - return NullOpt; + return std::nullopt; } void VisitBinding(const Binding& binding) override { diff --git a/src/relax/transform/combine_parallel_matmul.cc b/src/relax/transform/combine_parallel_matmul.cc index cc55eaff0721..916061aa575f 100644 --- a/src/relax/transform/combine_parallel_matmul.cc +++ b/src/relax/transform/combine_parallel_matmul.cc @@ -38,8 +38,6 @@ namespace tvm { namespace relax { -using runtime::Map; - using FCheck = ffi::TypedFunction, Array, Map)>; /*! \brief Group shapes of the RHS matrices by rank. Matrices in a group whose batch sizes @@ -160,7 +158,7 @@ ffi::TypedFunction(Map, Map)> GetRewri std::vector splits; for (auto index : indices) { Var rhs = matchings[patterns.rhs[index]]; - Optional bias = NullOpt; + Optional bias = std::nullopt; if (branch_info.bias_dim.has_value()) { bias = matchings[patterns.bias[index]]; } diff --git a/src/relax/transform/convert_dataflow.cc b/src/relax/transform/convert_dataflow.cc index 5fb3683c40a2..1c4cef892af5 100644 --- a/src/relax/transform/convert_dataflow.cc +++ b/src/relax/transform/convert_dataflow.cc @@ -91,7 +91,7 @@ class DataflowBlockExtractor : public ExprMutator { } dataflow_bindings = {}; - input_dataflow_block = NullOpt; + input_dataflow_block = std::nullopt; }; for (auto block : seq->blocks) { diff --git a/src/relax/transform/convert_layout.cc b/src/relax/transform/convert_layout.cc index b41ad9ea29c4..78670bd51af0 100644 --- a/src/relax/transform/convert_layout.cc +++ b/src/relax/transform/convert_layout.cc @@ -200,7 +200,7 @@ class LayoutConvertMutator : public ExprMutator { const Map>& desired_layouts, const VarLayoutMap& var_layout_map) { const OpNode* op_node = call_node->op.as(); - if (op_node == nullptr) return NullOpt; + if (op_node == nullptr) return std::nullopt; Op op = Downcast(GetRef(op_node)); const auto attr_map = Op::GetAttrMap("FRelaxInferLayout"); if (attr_map.count(op) && !HasUnknownDimTensor(call_node->args)) { @@ -209,7 +209,7 @@ class LayoutConvertMutator : public ExprMutator { return f(GetRef(call_node), desired_layouts, var_layout_map); } else { // Otherwise, we use the default policy. - return NullOpt; + return std::nullopt; } } @@ -217,7 +217,7 @@ class LayoutConvertMutator : public ExprMutator { Optional res = GetInferLayoutInfo(call_node, desired_layouts_, var_layout_map_); ObjectPtr new_call = make_object(*call_node); - new_call->struct_info_ = NullOpt; + new_call->struct_info_ = std::nullopt; if (!res.defined() || (!IsNestedTensor(binding->var) && !binding->var->IsInstance())) { // Default policy: use the initial layout. diff --git a/src/relax/transform/dead_code_elimination.cc b/src/relax/transform/dead_code_elimination.cc index f1dc3908fc8e..abceb517c1dd 100644 --- a/src/relax/transform/dead_code_elimination.cc +++ b/src/relax/transform/dead_code_elimination.cc @@ -90,7 +90,7 @@ IRModule RemoveUnusedFunctions(IRModule mod, const std::unordered_set return mod; } -IRModule DeadCodeElimination(const IRModule& arg_mod, Array entry_function_names) { +IRModule DeadCodeElimination(const IRModule& arg_mod, Array entry_function_names) { IRModule mod = arg_mod; // S0: Make a list of all user-specified entry functions and @@ -133,7 +133,7 @@ IRModule DeadCodeElimination(const IRModule& arg_mod, Array ent namespace transform { -Pass DeadCodeElimination(Array entry_functions) { +Pass DeadCodeElimination(Array entry_functions) { auto pass_func = [=](IRModule m, PassContext pc) { return relax::DeadCodeElimination(m, entry_functions); }; diff --git a/src/relax/transform/eliminate_common_subexpr.cc b/src/relax/transform/eliminate_common_subexpr.cc index 59960b47d73c..5173df7ef386 100644 --- a/src/relax/transform/eliminate_common_subexpr.cc +++ b/src/relax/transform/eliminate_common_subexpr.cc @@ -47,7 +47,7 @@ namespace { */ struct ReplacementKey { tvm::relax::Expr bound_value; - tvm::Optional match_cast = tvm::NullOpt; + tvm::Optional match_cast = std::nullopt; explicit ReplacementKey(const tvm::relax::Binding& binding) : bound_value(GetBoundValue(binding)) { diff --git a/src/relax/transform/expand_tuple_arguments.cc b/src/relax/transform/expand_tuple_arguments.cc index 550409f82800..8d5c833d43fb 100644 --- a/src/relax/transform/expand_tuple_arguments.cc +++ b/src/relax/transform/expand_tuple_arguments.cc @@ -33,13 +33,13 @@ using PMap = std::unordered_map; Optional ExpandParams(Function func) { bool is_exposed = func->attrs.GetAttr(tvm::attr::kGlobalSymbol).defined(); - if (is_exposed) return NullOpt; + if (is_exposed) return std::nullopt; bool has_tuple_param = std::any_of( func->params.begin(), func->params.end(), [](const Var& param) -> bool { return param->struct_info_.as(); }); - if (!has_tuple_param) return NullOpt; + if (!has_tuple_param) return std::nullopt; Array params; Array bindings; diff --git a/src/relax/transform/few_shot_tuning.cc b/src/relax/transform/few_shot_tuning.cc index 3df818cf3cea..084791bde123 100644 --- a/src/relax/transform/few_shot_tuning.cc +++ b/src/relax/transform/few_shot_tuning.cc @@ -55,11 +55,11 @@ tir::PrimFunc FewShotTunePrimFunc(const tir::PrimFunc& prim_func, const Target& /*target=*/target, /*space_generator=*/ meta_schedule::SpaceGenerator::PostOrderApply(/*f_block_filter=*/nullptr, - /*sch_rules=*/NullOpt, - /*postprocs=*/NullOpt, - /*mutator_probs=*/NullOpt), + /*sch_rules=*/std::nullopt, + /*postprocs=*/std::nullopt, + /*mutator_probs=*/std::nullopt), /*search_strategy=*/meta_schedule::SearchStrategy::ReplayTrace(/*max_fail_count=*/100), - /*task_name=*/NullOpt, + /*task_name=*/std::nullopt, /*num_threads=*/num_threads, // use all available local threads /*rand_state=*/-1, // -1 means use random seed /*logger=*/nullptr); @@ -67,8 +67,8 @@ tir::PrimFunc FewShotTunePrimFunc(const tir::PrimFunc& prim_func, const Target& task->search_strategy.value()->PreTuning( /*max_trials=*/valid_count, /*num_trials_per_iter=*/valid_count, /*design_spaces=*/task->space_generator.value()->GenerateDesignSpace(mod), - /*database=*/NullOpt, - /*cost_model=*/NullOpt); + /*database=*/std::nullopt, + /*cost_model=*/std::nullopt); int fail_count = 0, max_fail_count = 100; while (valid_count > 0 && fail_count < max_fail_count) { Optional> candidates = diff --git a/src/relax/transform/fold_constant.cc b/src/relax/transform/fold_constant.cc index 2cce9c8d7c26..2d916d0391ea 100644 --- a/src/relax/transform/fold_constant.cc +++ b/src/relax/transform/fold_constant.cc @@ -45,14 +45,14 @@ class ConstantFolder : public ExprMutator { * constant shape and get runtime shape tuple from it. * \param struct_info The given struct info whose shape inside is to be casted. * \return The runtime shape tuple, or nullopt if it is not a constant shape. - * \note Only TensorStructInfo is supported at this moment. Return NullOpt + * \note Only TensorStructInfo is supported at this moment. Return std::nullopt * if the input struct info is not TensorStructInfo. */ - static Optional MatchConstShape(const StructInfo& struct_info) { + static Optional MatchConstShape(const StructInfo& struct_info) { // Only support single output for call_tir at this moment. const auto* tensor_sinfo = struct_info.as(); if (tensor_sinfo == nullptr) { - return NullOpt; + return std::nullopt; } const auto* shape = tensor_sinfo->shape.as(); @@ -61,10 +61,10 @@ class ConstantFolder : public ExprMutator { std::vector shape_values; for (const auto v : shape->values) { auto* ptr = v.as(); - if (!ptr) return NullOpt; + if (!ptr) return std::nullopt; shape_values.push_back(ptr->value); } - return runtime::ShapeTuple(shape_values.begin(), shape_values.end()); + return ffi::Shape(shape_values.begin(), shape_values.end()); } /*! @@ -75,7 +75,7 @@ class ConstantFolder : public ExprMutator { Array res; for (auto arg : args) { auto* ptr = arg.as(); - if (!ptr) return NullOpt; + if (!ptr) return std::nullopt; res.push_back(ptr->data); } return res; @@ -92,7 +92,7 @@ class ConstantFolder : public ExprMutator { if (auto* pfunc = base_func.as()) { return GetRef(pfunc); } - return NullOpt; + return std::nullopt; } /*! @@ -108,7 +108,7 @@ class ConstantFolder : public ExprMutator { if (it != func_build_cache_.end()) { return it->second; } - Optional build_func = NullOpt; + Optional build_func = std::nullopt; try { // Not all the primfunc can be directly built via llvm, for example, if a function is @@ -141,12 +141,12 @@ class ConstantFolder : public ExprMutator { } // Try constant evaluate the function call - // if failed return NullOpt + // if failed return std::nullopt Optional ConstEvaluateCallTIR(tir::PrimFunc tir_func, Array arr_args, - runtime::ShapeTuple shape, DataType ret_type) { + ffi::Shape shape, DataType ret_type) { // obtain function from the cache. Optional func = GetCachedBuild(tir_func); - if (!func) return NullOpt; + if (!func) return std::nullopt; // here the vector size has an additional + 1 because we need to put ret_tensor at the end std::vector packed_args(arr_args.size() + 1); @@ -180,7 +180,7 @@ class ConstantFolder : public ExprMutator { Optional> arr_args = MatchConstArrayArgs(call->args[1].as()->fields); ICHECK_EQ(call->sinfo_args.size(), 1) << "call_tir should have exactly one sinfo arg"; - Optional shape = MatchConstShape(call->sinfo_args[0]); + Optional shape = MatchConstShape(call->sinfo_args[0]); bool output_not_tuple = call->sinfo_args.size() == 1; // Pattern 0: call constant function, const argument with const shape. if (func && arr_args && shape && output_not_tuple) { diff --git a/src/relax/transform/fuse_ops.cc b/src/relax/transform/fuse_ops.cc index 4819cefb9ac3..74141724ee24 100644 --- a/src/relax/transform/fuse_ops.cc +++ b/src/relax/transform/fuse_ops.cc @@ -537,26 +537,26 @@ class FunctionCreator : public ExprMutator { // If the result is not used outside LOG(WARNING) << "There are dead codes in the current IRModule, please run the " "DeadCodeElimination Pass before FuseOps"; - function_ = NullOpt; + function_ = std::nullopt; } else { Expr body = outputs.size() == 1 ? outputs[0] : Tuple(outputs); body = builder_->Normalize(body); body = builder_->Normalize(SeqExpr({new_block}, body)); group_attrs.Set(tvm::relax::attr::kPrimitive, true); - Function function = Function(/*params=*/params_, // - /*body=*/body, // - /*ret_struct_info=*/NullOpt, // - /*is_pure=*/true, // + Function function = Function(/*params=*/params_, // + /*body=*/body, // + /*ret_struct_info=*/std::nullopt, // + /*is_pure=*/true, // /*attrs=*/DictAttrs(group_attrs)); Array free_vars = FreeSymbolicVars(function).Map([](const tir::Var& var) -> PrimExpr { return var; }); if (!free_vars.empty()) { params_.push_back(Var("tir_vars", ShapeStructInfo(free_vars))); arguments_.push_back(ShapeExpr(free_vars)); - function = Function(/*params=*/params_, // - /*body=*/body, // - /*ret_struct_info=*/NullOpt, // - /*is_pure=*/true, // + function = Function(/*params=*/params_, // + /*body=*/body, // + /*ret_struct_info=*/std::nullopt, // + /*is_pure=*/true, // /*attrs=*/DictAttrs(group_attrs)); } function_ = SymbolicVarRenewMutator::Renew(function); @@ -572,7 +572,7 @@ class FunctionCreator : public ExprMutator { /*! \brief The name for the fused function */ String name_hint_ = "fused"; /*! \brief The constructed Relax function */ - Optional function_ = NullOpt; + Optional function_ = std::nullopt; private: std::optional GetOutputIndex(Var v) { diff --git a/src/relax/transform/fuse_tir.cc b/src/relax/transform/fuse_tir.cc index 4f4a3ec2c73a..0dc807a5a624 100644 --- a/src/relax/transform/fuse_tir.cc +++ b/src/relax/transform/fuse_tir.cc @@ -900,7 +900,7 @@ class FusedTIRConstructor : public ExprVisitor { */ static void CollectPrimFuncParams(const Var& relax_param, std::vector>* out, - const tvm::runtime::Optional& tir_buffer_param) { + const Optional& tir_buffer_param) { auto struct_info = GetStructInfo(relax_param); CHECK(!struct_info.as()) @@ -963,7 +963,7 @@ class FusedTIRConstructor : public ExprVisitor { tir::Stmt body = tir::BlockNameDeduplicator()(tir::SeqStmt::Flatten(func_info_.bodies)); body = subst.Substitute(body); - body = tir::Block({}, {}, {}, "root", std::move(body), NullOpt, alloc_buffers); + body = tir::Block({}, {}, {}, "root", std::move(body), std::nullopt, alloc_buffers); body = tir::BlockRealize({}, Bool(true), Downcast(body)); tir::PrimFunc func(func_info_.params, body, VoidType(), func_info_.buffer_map, DictAttrs(attr_map)); diff --git a/src/relax/transform/gradient.cc b/src/relax/transform/gradient.cc index fa96f31cf5a8..35c6d9af5ec0 100644 --- a/src/relax/transform/gradient.cc +++ b/src/relax/transform/gradient.cc @@ -668,7 +668,7 @@ class GradientMutator : private ExprMutator { orig_params_ = func->params; Expr new_body = this->VisitExpr(func->body); - return Function(func->params, new_body, NullOpt, func->is_pure, func->attrs); + return Function(func->params, new_body, std::nullopt, func->is_pure, func->attrs); } Expr VisitExpr_(const SeqExprNode* seq_expr) final { diff --git a/src/relax/transform/infer_amp_utils.h b/src/relax/transform/infer_amp_utils.h index 3440afb7211d..a3a86dd2e0c3 100644 --- a/src/relax/transform/infer_amp_utils.h +++ b/src/relax/transform/infer_amp_utils.h @@ -38,9 +38,8 @@ namespace tvm { namespace relax { -using runtime::DLDataTypeToString; -using runtime::String; -using runtime::StringToDLDataType; +using ffi::DLDataTypeToString; +using ffi::StringToDLDataType; enum MixedPrecisionPolicyKind : int { kAlways = 0, kFollow = 1, kNever = 2 }; diff --git a/src/relax/transform/inline_functions.cc b/src/relax/transform/inline_functions.cc index 457d6d9ead46..981a5e654c1c 100644 --- a/src/relax/transform/inline_functions.cc +++ b/src/relax/transform/inline_functions.cc @@ -85,7 +85,7 @@ class FunctionInliner : public ExprMutator { } else if (auto opt = replacements_.Get(gvar->name_hint)) { return opt; } else { - return NullOpt; + return std::nullopt; } } diff --git a/src/relax/transform/lambda_lift.cc b/src/relax/transform/lambda_lift.cc index ee19872e5af5..41a970abfecf 100644 --- a/src/relax/transform/lambda_lift.cc +++ b/src/relax/transform/lambda_lift.cc @@ -166,7 +166,7 @@ class LambdaNameCollector : ExprVisitor { if (auto it = lifted_with_global_symbol_.find(func); it != lifted_with_global_symbol_.end()) { return it->second; } else { - return NullOpt; + return std::nullopt; } }); @@ -181,7 +181,7 @@ class LambdaNameCollector : ExprVisitor { // 3. Try concatenating the entire path together. Don't include // paths of length 2, as they would already be attempted earlier. attempt_name_generation([&](const FunctionNode*, const auto& location) -> Optional { - if (location.size() == 2) return NullOpt; + if (location.size() == 2) return std::nullopt; std::stringstream stream; bool is_first = true; @@ -485,7 +485,7 @@ class LambdaLifter : public ExprMutator { std::unordered_map nested_closure_map_; std::unordered_map rebind_map_; std::unordered_set, ObjectPtrHash, ObjectPtrEqual> closures_; - Optional current_lambda_var_ = NullOpt; + Optional current_lambda_var_ = std::nullopt; IRModule mod_; std::unordered_map lifted_names_; diff --git a/src/relax/transform/lazy_transform_params.cc b/src/relax/transform/lazy_transform_params.cc index 66aa35887f08..d1cf4ff7147b 100644 --- a/src/relax/transform/lazy_transform_params.cc +++ b/src/relax/transform/lazy_transform_params.cc @@ -80,7 +80,7 @@ class LazyInputMutator : public ExprMutator { if (externally_visible_vars.count(var)) { return var; } else { - return NullOpt; + return std::nullopt; } }); diff --git a/src/relax/transform/legalize_ops.cc b/src/relax/transform/legalize_ops.cc index b66132154aca..71a55a3d84d1 100644 --- a/src/relax/transform/legalize_ops.cc +++ b/src/relax/transform/legalize_ops.cc @@ -149,7 +149,7 @@ class LegalizeMutator : public ExprMutator { return GetTarget(tup_sinfo->fields); } } - return NullOpt; + return std::nullopt; } Expr BindTarget(Expr expr) { diff --git a/src/relax/transform/merge_composite_functions.cc b/src/relax/transform/merge_composite_functions.cc index d814629026d5..9538249b771b 100644 --- a/src/relax/transform/merge_composite_functions.cc +++ b/src/relax/transform/merge_composite_functions.cc @@ -168,13 +168,13 @@ class CompositeGroupsBuilder : public MemoizedExprTranslator { Optional GetCodegenName(const Expr& callee) { auto const* gvar = callee.as(); if (!gvar) { - return NullOpt; + return std::nullopt; } auto composite_name_opt = mod_->Lookup(GetRef(gvar))->GetAttr(attr::kComposite); if (!composite_name_opt) { - return NullOpt; + return std::nullopt; } return relax::GetCodegenName(composite_name_opt.value()); diff --git a/src/relax/transform/meta_schedule.cc b/src/relax/transform/meta_schedule.cc index 875d26ea47a1..57012a40ddaa 100644 --- a/src/relax/transform/meta_schedule.cc +++ b/src/relax/transform/meta_schedule.cc @@ -173,8 +173,8 @@ Pass MetaScheduleApplyDatabase(Optional work_dir, bool enable_warning = Pass MetaScheduleTuneIRMod(Map params, String work_dir, Integer max_trials_global, - Optional max_trials_per_task = NullOpt, - Optional> op_names = NullOpt) { + Optional max_trials_per_task = std::nullopt, + Optional> op_names = std::nullopt) { Target target = Target::Current(false); auto pass_func = [=](IRModule m, PassContext ctx) { auto max_trials_task = max_trials_per_task.value_or(max_trials_global); @@ -191,7 +191,8 @@ Pass MetaScheduleTuneTIR(String work_dir, Integer max_trials_global) { Target target = Target::Current(false); ffi::TypedFunction pass_func = [=](tir::PrimFunc f, IRModule mod, PassContext ctx) { - return MetaScheduleTuner(target, work_dir, max_trials_global, max_trials_global, NullOpt) + return MetaScheduleTuner(target, work_dir, max_trials_global, max_trials_global, + std::nullopt) .TuneTIR(f, ctx); }; return tir::transform::CreatePrimFuncPass(/*pass function*/ pass_func, /*opt level*/ 0, diff --git a/src/relax/transform/normalize.cc b/src/relax/transform/normalize.cc index e81cd16207e9..2c57c89a265c 100644 --- a/src/relax/transform/normalize.cc +++ b/src/relax/transform/normalize.cc @@ -35,7 +35,7 @@ namespace relax { // TODO(@altanh): LCA binding lifting class NormalizeMutator : public ExprMutatorBase { public: - NormalizeMutator() { builder_ = BlockBuilder::Create(NullOpt); } + NormalizeMutator() { builder_ = BlockBuilder::Create(std::nullopt); } Expr VisitExpr(const Expr& expr) override { return builder_->Normalize(ExprMutatorBase::VisitExpr(expr)); @@ -63,7 +63,7 @@ class NormalizeMutator : public ExprMutatorBase { } } - Expr VisitWithNewScope(const Expr& expr, Optional> params = NullOpt) { + Expr VisitWithNewScope(const Expr& expr, Optional> params = std::nullopt) { builder_->BeginBindingBlock(); if (params.defined()) { builder_->BeginScope(params); diff --git a/src/relax/transform/realize_vdevice.cc b/src/relax/transform/realize_vdevice.cc index 9e6ebbbc2632..15474eb8f8d6 100644 --- a/src/relax/transform/realize_vdevice.cc +++ b/src/relax/transform/realize_vdevice.cc @@ -76,7 +76,7 @@ class VDeviceLookup { } private: - Optional> opt_vdevices_ = NullOpt; + Optional> opt_vdevices_ = std::nullopt; }; class DeviceHintCollector : ExprVisitor { @@ -183,7 +183,7 @@ class DeviceHintCollector : ExprVisitor { return bound.value(); } } - return NullOpt; + return std::nullopt; } // A lookup to identify the VDevice from the IRModule attributes, @@ -254,7 +254,7 @@ class VDeviceSetCollector : ExprVisitor { } } - Optional current_binding_ = NullOpt; + Optional current_binding_ = std::nullopt; // Lookup from relax variable to the set of relax variables which // must be located on the same device. For example, a trivial diff --git a/src/relax/transform/remove_unused_outputs.cc b/src/relax/transform/remove_unused_outputs.cc index aafd1941ec90..b967ad68d126 100644 --- a/src/relax/transform/remove_unused_outputs.cc +++ b/src/relax/transform/remove_unused_outputs.cc @@ -143,7 +143,7 @@ class PartialTupleUsageCollector : ExprVisitor { return known_binding.value(); } } - return NullOpt; + return std::nullopt; }; while (auto unwrapped = get_bound_value(expr)) { diff --git a/src/relax/transform/rewrite_cuda_graph.cc b/src/relax/transform/rewrite_cuda_graph.cc index aebf722bcfd2..608f72ee1f20 100644 --- a/src/relax/transform/rewrite_cuda_graph.cc +++ b/src/relax/transform/rewrite_cuda_graph.cc @@ -88,7 +88,7 @@ struct LiftedFunctionRewritePlan { // The corresponding binding vars in the original function of the inputs of the lifted function std::vector inputs; // The tir vars in the original function that are propagated to the lifted function - Optional propogated_tir_vars = NullOpt; + Optional propogated_tir_vars = std::nullopt; }; /*! \brief Builder of the lifted function for cuda graph capturing or allocations */ @@ -123,7 +123,7 @@ class FuncBuilder : public ExprMutator { /*! \brief Build the new function */ Function Build() { Array params; - Optional shape_expr = NullOpt; + Optional shape_expr = std::nullopt; if (shape_expr_inputs_.size()) { Array tir_vars; for (const auto* var : shape_expr_inputs_) { @@ -871,8 +871,8 @@ class CUDAGraphRewriter : public ExprMutator { int index_alloc_ = 0; int index_capture_ = 0; support::Arena arena_; - Optional gv_global_alloc_ = NullOpt; - Optional current_func_ = NullOpt; + Optional gv_global_alloc_ = std::nullopt; + Optional current_func_ = std::nullopt; }; IRModule RewriteCUDAGraph(IRModule mod) { diff --git a/src/relax/transform/split_call_tir_by_pattern.cc b/src/relax/transform/split_call_tir_by_pattern.cc index 14d1d7d2fb92..d0edab850652 100644 --- a/src/relax/transform/split_call_tir_by_pattern.cc +++ b/src/relax/transform/split_call_tir_by_pattern.cc @@ -88,7 +88,7 @@ class ForMatcher : public TensorizeComparator { return it->second; } } - return NullOpt; + return std::nullopt; } bool VisitExpr(const PrimExpr& lhs, const PrimExpr& rhs) final { @@ -568,7 +568,7 @@ std::pair> SplitFunctions(PrimFunc func, Array match_results = TIRPatternMatcher::Match(patterns, func->body.as()->block->body); if (match_results.empty()) { - return {func, NullOpt}; + return {func, std::nullopt}; } Array codegen_result = f_codegen(match_results); ICHECK(codegen_result.size() == 3); @@ -576,12 +576,12 @@ std::pair> SplitFunctions(PrimFunc func, int num_matched_ops = Downcast(codegen_result[1])->value; Array func1_args = Downcast>(codegen_result[2]); if (num_matched_ops == 0) { - return {func, NullOpt}; + return {func, std::nullopt}; } FunctionPartitioner partitioner(num_matched_ops); partitioner(body); if (partitioner.fail) { - return {func, NullOpt}; + return {func, std::nullopt}; } bool has_second_func = false; for (const auto& pr : partitioner.block_partition) { @@ -592,7 +592,7 @@ std::pair> SplitFunctions(PrimFunc func, } if (!has_second_func) { // No need to split the function. - return {WithAttr(func, kLibraryKernel, library_code), NullOpt}; + return {WithAttr(func, kLibraryKernel, library_code), std::nullopt}; } // Step 2. Split the function into two functions. Stmt body1 = BlockRemover::RemoveBlockByPartition(func->body, partitioner.block_partition, @@ -660,7 +660,7 @@ void StringReplace(std::string* subject, const std::string& search, const std::s tvm::BaseFunc CodegenWithLibrary(const tir::PrimFuncNode* pf, String global_symbol) { using namespace tvm::tir; - Optional library_code = pf->attrs.GetAttr(kLibraryKernel); + Optional library_code = pf->attrs.GetAttr(kLibraryKernel); if (!library_code.defined()) { return GetRef(pf); } diff --git a/src/relax/transform/split_layout_rewrite_preproc.cc b/src/relax/transform/split_layout_rewrite_preproc.cc index 41213859f8ce..542dba3cf6c6 100644 --- a/src/relax/transform/split_layout_rewrite_preproc.cc +++ b/src/relax/transform/split_layout_rewrite_preproc.cc @@ -41,7 +41,7 @@ class SplitPrimFuncLayoutRewrite : public StmtMutator { if (layout_rewrite_preproc_stmts_.size() > 0) { return std::make_tuple(create_layout_rewrite_preproc_func(), create_compute_func()); } else { - return std::make_tuple(NullOpt, func); + return std::make_tuple(std::nullopt, func); } } @@ -124,7 +124,7 @@ class SplitPrimFuncLayoutRewrite : public StmtMutator { /*block=*/ Block(/*iter_vars=*/{}, /*reads=*/{}, /*writes=*/{}, /*name_hint=*/"root", body, - /*init=*/NullOpt, + /*init=*/std::nullopt, /*alloc_buffers=*/alloc_buffers)); Map dict; diff --git a/src/relax/transform/static_plan_block_memory.cc b/src/relax/transform/static_plan_block_memory.cc index dcbd3077b1ea..f3a9860eaa7f 100644 --- a/src/relax/transform/static_plan_block_memory.cc +++ b/src/relax/transform/static_plan_block_memory.cc @@ -166,7 +166,7 @@ class TokenAllocator1D { * \brief Request a storage token from the available token pool for a * given prototype, or report no appropriate available token in the pool. * \param prototype The requesting prototype storage token. - * \return The request result token. Return NullOpt if there is no + * \return The request result token. Return std::nullopt if there is no * appropriate available token in the pool. */ Optional RequestReuse(StorageToken prototype) { @@ -175,7 +175,7 @@ class TokenAllocator1D { // If the prototype has no reference at all, feel free to allocate new storage. // The unused binding can be removed by cleaning passes. if (prototype->ref_counter == 0) { - return NullOpt; + return std::nullopt; } // Step 1. Get the available pool of the token dtype. @@ -197,7 +197,7 @@ class TokenAllocator1D { return available_token; } } - return NullOpt; + return std::nullopt; } // Step 2. Get the range of memory blocks in [size / match_range_, size * match_range_) auto begin = pool.lower_bound(size / match_range_); @@ -228,8 +228,9 @@ class TokenAllocator1D { pool.erase(mid); return available_token; } - // Return `NullOpt` indicating that no satisfiable storage token is found in the available pool. - return NullOpt; + // Return `std::nullopt` indicating that no satisfiable storage token is found in the available + // pool. + return std::nullopt; } /*! diff --git a/src/relax/transform/to_mixed_precision.cc b/src/relax/transform/to_mixed_precision.cc index 9482f500d942..c82d4b573646 100644 --- a/src/relax/transform/to_mixed_precision.cc +++ b/src/relax/transform/to_mixed_precision.cc @@ -38,8 +38,6 @@ namespace tvm { namespace relax { -using runtime::String; - int GetMixedPrecisionInfo(const CallNode* call_node) { const OpNode* op_node = call_node->op.as(); if (op_node == nullptr) { @@ -511,7 +509,7 @@ class ToMixedPrecisionRewriter : public ExprMutator { if (opt_new_dtype) { auto new_dtype = opt_new_dtype.value(); new_call.CopyOnWrite()->args = RewriteArgs(new_call->args, new_dtype); - new_call.CopyOnWrite()->struct_info_ = NullOpt; + new_call.CopyOnWrite()->struct_info_ = std::nullopt; new_value = builder_->Normalize(Call(new_call)); @@ -535,7 +533,7 @@ class ToMixedPrecisionRewriter : public ExprMutator { } ObjectPtr new_tuple = make_object(*tuple_node); new_tuple->fields = std::move(RemapArgs(tuple_node->fields)); - new_tuple->struct_info_ = NullOpt; + new_tuple->struct_info_ = std::nullopt; Expr new_value = builder_->Normalize(Tuple(new_tuple)); if (!binding->var->IsInstance()) { // Global var: store the tensors to the original dtype @@ -555,7 +553,7 @@ class ToMixedPrecisionRewriter : public ExprMutator { ObjectPtr new_tuple_get_item = make_object(*tuple_get_item_node); new_tuple_get_item->tuple = RemapArgs({tuple_get_item_node->tuple})[0]; - new_tuple_get_item->struct_info_ = NullOpt; + new_tuple_get_item->struct_info_ = std::nullopt; Expr new_value = TupleGetItem(new_tuple_get_item); if (!binding->var->IsInstance()) { // Global var: store the tensors to the original dtype diff --git a/src/relax/transform/topological_sort.cc b/src/relax/transform/topological_sort.cc index 24ed53948e71..a42b1db7712b 100644 --- a/src/relax/transform/topological_sort.cc +++ b/src/relax/transform/topological_sort.cc @@ -98,7 +98,7 @@ class BindingOrderCollector : ExprVisitor { // If there is a variable without any inputs (e.g. `R.const(1)`) // or an unused variable, these must be handled somewhere, to // ensure they are visited corrected. It's easiest to perform the - // depth/breadth-first search if handled here, with `NullOpt` + // depth/breadth-first search if handled here, with `std::nullopt` // acting as a special value, so that the later traversal doesn't // need to check for this special case. std::vector zero_input_bindings; @@ -247,7 +247,7 @@ class TopologicalSorter : public ExprMutator { std::unordered_set visited; - // Given a variable that has just been defined (or NullOpt for the + // Given a variable that has just been defined (or std::nullopt for the // function's output), mark nodes as ready to visit. auto push_descendents_to_stack = [&](const DataflowNode& var) { auto it = forward_edge_lookup.find(var); diff --git a/src/relax/transform/tuning_api/database.cc b/src/relax/transform/tuning_api/database.cc index 87d9a76cfbee..c0336f9df335 100644 --- a/src/relax/transform/tuning_api/database.cc +++ b/src/relax/transform/tuning_api/database.cc @@ -49,7 +49,7 @@ TuningRecord TuningRecord::FromJSON(const ObjectRef& json_obj) { Trace trace{nullptr}; Optional> run_secs{nullptr}; try { - const ArrayObj* json_array = json_obj.as(); + const ffi::ArrayObj* json_array = json_obj.as(); CHECK(json_array && json_array->size() == 2); // Load json[0] => trace { @@ -256,7 +256,7 @@ Database Database::JSONDatabase(String path_workload, String path_tuning_record, 0, json_objs.size(), num_threads, [&](int thread_id, int task_id) { const ObjectRef& json_obj = json_objs[task_id].cast(); try { - const ArrayObj* arr = json_obj.as(); + const ffi::ArrayObj* arr = json_obj.as(); ICHECK_EQ(arr->size(), 3); workload_idxs[task_id] = Downcast(arr->at(0)).IntValue(); targets[task_id] = Target(Downcast>(arr->at(1))); @@ -288,7 +288,7 @@ Database Database::JSONDatabase(String path_workload, String path_tuning_record, 0, json_objs.size(), num_threads, [&](int thread_id, int task_id) { const ObjectRef& json_obj = json_objs[task_id].cast(); try { - const ArrayObj* arr = json_obj.as(); + const ffi::ArrayObj* arr = json_obj.as(); ICHECK_EQ(arr->size(), 3); workload_idxs[task_id] = Downcast(arr->at(0)).IntValue(); targets[task_id] = Target(Downcast>(arr->at(1))); diff --git a/src/relax/transform/tuning_api/primitives.cc b/src/relax/transform/tuning_api/primitives.cc index cdad8e58c3c3..949cf611c20f 100644 --- a/src/relax/transform/tuning_api/primitives.cc +++ b/src/relax/transform/tuning_api/primitives.cc @@ -64,12 +64,12 @@ Choice Choice::FromJSON(const ObjectRef& json) { String transform_func_key, constr_func_key; Array transform_func_args, constr_func_args; try { - const ArrayObj* arr = json.as(); + const ffi::ArrayObj* arr = json.as(); ICHECK(arr && arr->size() == 4); const auto* arr0 = arr->at(0).as(); - const auto* arr1 = arr->at(1).as(); + const auto* arr1 = arr->at(1).as(); const auto* arr2 = arr->at(2).as(); - const auto* arr3 = arr->at(3).as(); + const auto* arr3 = arr->at(3).as(); ICHECK(arr0 && arr1 && arr2 && arr3); transform_func_key = GetRef(arr0); { @@ -123,10 +123,10 @@ Knob Knob::FromJSON(const ObjectRef& json) { String name; Map choices; try { - const ArrayObj* arr = json.as(); + const ffi::ArrayObj* arr = json.as(); ICHECK(arr && arr->size() == 2); const auto* arr0 = arr->at(0).as(); - const auto* arr1 = arr->at(1).as(); + const auto* arr1 = arr->at(1).as(); ICHECK(arr0 && arr1); name = GetRef(arr0); for (auto const& x : GetRef>(arr1)) { @@ -198,12 +198,12 @@ Trace Trace::FromJSON(const ObjectRef& json) { Array knobs; Array decisions; try { - const ArrayObj* arr = json.as(); + const ffi::ArrayObj* arr = json.as(); // A trace will have 2 or 3 entries depending on `include_irmod` parameter. ICHECK(arr && (arr->size() == 2 || arr->size() == 3)); - const auto* arr0 = arr->at(0).as(); - const auto* arr1 = arr->at(1).as(); + const auto* arr0 = arr->at(0).as(); + const auto* arr1 = arr->at(1).as(); ICHECK(arr0 && arr1); for (const Any& elem : *arr0) { diff --git a/src/relax/transform/utils.h b/src/relax/transform/utils.h index 67d5fd4875e0..edd953e3126e 100644 --- a/src/relax/transform/utils.h +++ b/src/relax/transform/utils.h @@ -115,7 +115,7 @@ class MemoizedExprTranslator : public ::tvm::relax::ExprFunctor entry_funcs); +TVM_DLL IRModule DeadCodeElimination(const IRModule& mod, Array entry_funcs); /*! * \brief Get the external symbol of the Relax function name. @@ -434,7 +434,7 @@ Expr CanonicalizeBindings(Expr expr); * * \ret The updated function. */ -Function BundleModelParams(const Function& func, Optional param_tuple_name = NullOpt); +Function BundleModelParams(const Function& func, Optional param_tuple_name = std::nullopt); /*! \brief Compose two functions * diff --git a/src/runtime/c_runtime_api.cc b/src/runtime/c_runtime_api.cc index b76687522d69..e7ecd0802c98 100644 --- a/src/runtime/c_runtime_api.cc +++ b/src/runtime/c_runtime_api.cc @@ -23,7 +23,9 @@ */ #include #include +#include #include +#include #include #include #include @@ -750,9 +752,9 @@ int TVMDeviceAllocDataSpace(DLDevice dev, size_t nbytes, size_t alignment, DLDat int TVMDeviceAllocDataSpaceWithScope(DLDevice dev, int ndim, const int64_t* shape, DLDataType dtype, const char* mem_scope, void** out_data) { API_BEGIN(); - Optional scope; + tvm::Optional scope; if (mem_scope != nullptr) { - scope = String(std::string(mem_scope)); + scope = tvm::String(std::string(mem_scope)); } out_data[0] = DeviceAPIManager::Get(dev)->AllocDataSpace(dev, ndim, shape, dtype, scope); API_END(); diff --git a/src/runtime/const_loader_module.cc b/src/runtime/const_loader_module.cc index 2536847726c8..75ce6612f43c 100644 --- a/src/runtime/const_loader_module.cc +++ b/src/runtime/const_loader_module.cc @@ -27,9 +27,9 @@ * code and constants significantly reduces the efforts for handling external * codegen and runtimes. */ -#include -#include -#include +#include +#include +#include #include #include #include diff --git a/src/runtime/container.cc b/src/runtime/container.cc index 004feb3afba8..a789cfc769f2 100644 --- a/src/runtime/container.cc +++ b/src/runtime/container.cc @@ -21,11 +21,11 @@ * \file src/runtime/container.cc * \brief Implementations of common containers. */ -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include #include #include @@ -88,22 +88,11 @@ TVM_REGISTER_GLOBAL("runtime.MapItems").set_body_typed([](const ffi::MapObj* n) return rkvs; }); -// ShapeTuple -TVM_REGISTER_OBJECT_TYPE(ShapeTupleObj); - -TVM_REGISTER_GLOBAL("runtime.ShapeTuple").set_body_packed([](ffi::PackedArgs args, Any* ret) { - std::vector shape; - for (int i = 0; i < args.size(); ++i) { - shape.push_back(args[i].cast()); - } - *ret = ShapeTuple(shape); -}); - -TVM_REGISTER_GLOBAL("runtime.GetShapeTupleSize").set_body_typed([](ShapeTuple shape) { +TVM_REGISTER_GLOBAL("runtime.GetShapeSize").set_body_typed([](ffi::Shape shape) { return static_cast(shape.size()); }); -TVM_REGISTER_GLOBAL("runtime.GetShapeTupleElem").set_body_typed([](ShapeTuple shape, int idx) { +TVM_REGISTER_GLOBAL("runtime.GetShapeElem").set_body_typed([](ffi::Shape shape, int idx) { ICHECK_LT(idx, shape.size()); return shape[idx]; }); diff --git a/src/runtime/contrib/clml/clml_runtime.cc b/src/runtime/contrib/clml/clml_runtime.cc index 21584997a76f..c59068152793 100644 --- a/src/runtime/contrib/clml/clml_runtime.cc +++ b/src/runtime/contrib/clml/clml_runtime.cc @@ -291,7 +291,7 @@ class CLMLRuntime : public JSONRuntimeBase { // Dump tensor to CPU std::vector shape = node.GetOpShape()[0]; DLDataType tvm_dtype = node.GetOpDataType()[0]; - NDArray narr = NDArray::Empty(ShapeTuple(shape), tvm_dtype, {kDLCPU, 0}); + NDArray narr = NDArray::Empty(ffi::Shape(shape), tvm_dtype, {kDLCPU, 0}); CopyDataFromCLMLTensor(clml_desc, narr.operator->()->data); // Naming convention diff --git a/src/runtime/contrib/cudnn/cudnn_utils.cc b/src/runtime/contrib/cudnn/cudnn_utils.cc index 191fb9af325e..3d7546d4e01b 100644 --- a/src/runtime/contrib/cudnn/cudnn_utils.cc +++ b/src/runtime/contrib/cudnn/cudnn_utils.cc @@ -177,7 +177,7 @@ void SetConvDescriptors(CuDNNThreadEntry* entry_ptr, int format, int dims, int g entry_ptr->conv_entry.tensor_format = static_cast(format); // Set Data Type entry_ptr->conv_entry.data_type = - CuDNNDataType::DLTypeToCuDNNType(runtime::StringToDLDataType(conv_dtype)); + CuDNNDataType::DLTypeToCuDNNType(ffi::StringToDLDataType(conv_dtype)); cudnnDataType_t cudnn_data_type = CuDNNDataType::DLTypeToCuDNNType(data_dtype); diff --git a/src/runtime/contrib/json/json_node.h b/src/runtime/contrib/json/json_node.h index 88834a7c01ea..b0f2bb582142 100644 --- a/src/runtime/contrib/json/json_node.h +++ b/src/runtime/contrib/json/json_node.h @@ -149,7 +149,7 @@ class JSONGraphNode { reader->Read(&tmp); ICHECK(!reader->NextArrayItem()); for (const auto& it : tmp) { - dtype_.push_back(tvm::runtime::StringToDLDataType(it)); + dtype_.push_back(ffi::StringToDLDataType(it)); } } else if (key == "shape") { reader->BeginArray(); diff --git a/src/runtime/contrib/nnapi/nnapi_ops.cc b/src/runtime/contrib/nnapi/nnapi_ops.cc index 8e2da6489fde..bea3712fab3e 100644 --- a/src/runtime/contrib/nnapi/nnapi_ops.cc +++ b/src/runtime/contrib/nnapi/nnapi_ops.cc @@ -275,7 +275,7 @@ void CastOpConverter::Convert(NNAPIModelBuilder& builder, const JSONGraphNode& n const auto dtype_attr = node.GetAttr>("astype_dtype"); ICHECK(dtype_attr.size() == 1); const auto dtype_str = dtype_attr[0]; - const DLDataType dtype = runtime::StringToDLDataType(dtype_str); + const DLDataType dtype = StringToDLDataType(dtype_str); ICHECK(outputs.size() == 1); const auto output_tensor_type = outputs[0].GetTensorType(); ICHECK(TensorTypeFromDLDataType(dtype) == output_tensor_type) diff --git a/src/runtime/contrib/nvshmem/init.cc b/src/runtime/contrib/nvshmem/init.cc index 33a787b5b9f3..cac0c1bc050a 100644 --- a/src/runtime/contrib/nvshmem/init.cc +++ b/src/runtime/contrib/nvshmem/init.cc @@ -28,7 +28,7 @@ namespace tvm { namespace runtime { -ShapeTuple InitNVSHMEMUID() { +ffi::Shape InitNVSHMEMUID() { nvshmemx_uniqueid_t uid; nvshmemx_get_uniqueid(&uid); std::vector uid_64; @@ -36,10 +36,10 @@ ShapeTuple InitNVSHMEMUID() { for (int i = 0; i < UNIQUEID_PADDING; ++i) { uid_64.push_back(static_cast(uid.internal[i])); } - return ShapeTuple(uid_64); + return ffi::Shape(uid_64); } -void InitNVSHMEM(ShapeTuple uid_64, int num_workers, int worker_id_start) { +void InitNVSHMEM(ffi::Shape uid_64, int num_workers, int worker_id_start) { DiscoWorker* worker = ThreadLocalDiscoWorker::Get()->worker; int worker_id; if (worker == nullptr) { @@ -99,7 +99,7 @@ void InitNVSHMEMWrapper(String args) { uid_vector.push_back(elem.get()); } - ShapeTuple uid_64(uid_vector); + ffi::Shape uid_64(uid_vector); int num_workers = static_cast(obj["npes"].get()); int worker_id_start = static_cast(obj["pe_start"].get()); diff --git a/src/runtime/contrib/nvshmem/memory_allocator.cc b/src/runtime/contrib/nvshmem/memory_allocator.cc index 4380c7e65dd8..5f7b181e27e3 100644 --- a/src/runtime/contrib/nvshmem/memory_allocator.cc +++ b/src/runtime/contrib/nvshmem/memory_allocator.cc @@ -57,7 +57,7 @@ class NVSHMEMAllocator final : public PooledAllocator { return allocator; } - NDArray Empty(ShapeTuple shape, DataType dtype, Device device) { + NDArray Empty(ffi::Shape shape, DataType dtype, Device device) { NDArray::Container* container = new NDArray::Container(nullptr, shape, dtype, device); container->SetDeleter([](Object* obj) { auto* ptr = static_cast(obj); @@ -88,7 +88,7 @@ class NVSHMEMAllocator final : public PooledAllocator { void DeviceFreeDataSpace(Device dev, void* ptr) final { nvshmem_free(ptr); } }; -NDArray NVSHMEMEmpty(ShapeTuple shape, DataType dtype, Device device) { +NDArray NVSHMEMEmpty(ffi::Shape shape, DataType dtype, Device device) { return NVSHMEMAllocator::Global()->Empty(shape, dtype, UseDefaultDeviceIfNone(device)); } diff --git a/src/runtime/debug_compile.cc b/src/runtime/debug_compile.cc index 570c4cb4cb8d..eee8ed3cb6f9 100644 --- a/src/runtime/debug_compile.cc +++ b/src/runtime/debug_compile.cc @@ -22,13 +22,13 @@ * \brief File used for debug migration */ // #include +#include +#include +#include +#include +#include #include #include -#include -#include -#include -#include -#include #include // #include diff --git a/src/runtime/disco/bcast_session.cc b/src/runtime/disco/bcast_session.cc index 81f10190e00b..6b17c7ba3aa8 100644 --- a/src/runtime/disco/bcast_session.cc +++ b/src/runtime/disco/bcast_session.cc @@ -68,7 +68,7 @@ void BcastSessionObj::Shutdown() { BcastSessionObj::Internal::BroadcastUnpacked(this, DiscoAction::kShutDown, 0); } -void BcastSessionObj::InitCCL(String ccl, IntTuple device_ids) { +void BcastSessionObj::InitCCL(String ccl, ffi::Shape device_ids) { const auto pf = tvm::ffi::Function::GetGlobal("runtime.disco." + ccl + ".init_ccl"); CHECK(pf.has_value()) << "ValueError: Cannot initialize CCL `" << ccl << "`, because cannot find function: runtime.disco." << ccl << ".init_ccl"; diff --git a/src/runtime/disco/builtin.cc b/src/runtime/disco/builtin.cc index a58c840ea325..4cd3e98d8862 100644 --- a/src/runtime/disco/builtin.cc +++ b/src/runtime/disco/builtin.cc @@ -17,7 +17,7 @@ * under the License. */ #include -#include +#include #include #include #include @@ -66,7 +66,7 @@ Module LoadVMModule(std::string path, Device device) { return mod; } -NDArray DiscoEmptyNDArray(ShapeTuple shape, DataType dtype, Device device) { +NDArray DiscoEmptyNDArray(ffi::Shape shape, DataType dtype, Device device) { return NDArray::Empty(shape, dtype, UseDefaultDeviceIfNone(device)); } @@ -124,22 +124,22 @@ void SyncWorker() { TVM_REGISTER_GLOBAL("runtime.disco.load_vm_module").set_body_typed(LoadVMModule); TVM_REGISTER_GLOBAL("runtime.disco.empty") - .set_body_typed([](ShapeTuple shape, DataType dtype, Device device, bool worker0_only, + .set_body_typed([](ffi::Shape shape, DataType dtype, Device device, bool worker0_only, bool in_group) -> Optional { int worker_id = WorkerId(); int group_size = DiscoWorker::ThreadLocal()->num_workers / DiscoWorker::ThreadLocal()->num_groups; bool is_worker0 = (worker_id == 0 && !in_group) || (in_group && worker_id % group_size == 0); if (worker0_only && !is_worker0) { - return NullOpt; + return std::nullopt; } else { return DiscoEmptyNDArray(shape, dtype, device); } }); TVM_REGISTER_GLOBAL("runtime.disco.allreduce") - .set_body_typed([](NDArray send, ShapeTuple reduce_kind, bool in_group, NDArray recv) { - int kind = IntegerFromShapeTuple(reduce_kind); + .set_body_typed([](NDArray send, ffi::Shape reduce_kind, bool in_group, NDArray recv) { + int kind = IntegerFromShape(reduce_kind); CHECK(0 <= kind && kind <= 4) << "ValueError: Unknown ReduceKind: " << kind; AllReduce(send, static_cast(kind), in_group, recv); }); @@ -152,8 +152,8 @@ TVM_REGISTER_GLOBAL("runtime.disco.send_to_next_group").set_body_typed(SendToNex TVM_REGISTER_GLOBAL("runtime.disco.recv_from_prev_group").set_body_typed(RecvFromPrevGroup); TVM_REGISTER_GLOBAL("runtime.disco.send_to_worker").set_body_typed(SendToWorker); TVM_REGISTER_GLOBAL("runtime.disco.recv_from_worker").set_body_typed(RecvFromWorker); -TVM_REGISTER_GLOBAL("runtime.disco.worker_id").set_body_typed([]() -> ShapeTuple { - return ShapeTuple({WorkerId()}); +TVM_REGISTER_GLOBAL("runtime.disco.worker_id").set_body_typed([]() -> ffi::Shape { + return ffi::Shape({WorkerId()}); }); TVM_REGISTER_GLOBAL("runtime.disco.worker_rank").set_body_typed([]() -> int64_t { return WorkerId(); @@ -161,12 +161,12 @@ TVM_REGISTER_GLOBAL("runtime.disco.worker_rank").set_body_typed([]() -> int64_t TVM_REGISTER_GLOBAL("runtime.disco.device").set_body_typed([]() -> Device { return DiscoWorker::ThreadLocal()->default_device; }); -TVM_REGISTER_GLOBAL("runtime.disco.bind_worker_to_cpu_core").set_body_typed([](IntTuple cpu_ids) { +TVM_REGISTER_GLOBAL("runtime.disco.bind_worker_to_cpu_core").set_body_typed([](ffi::Shape cpu_ids) { int worker_id = WorkerId(); ICHECK_LT(worker_id, static_cast(cpu_ids.size())); const auto f_set_thread_affinity = tvm::ffi::Function::GetGlobalRequired("tvm.runtime.threading.set_current_thread_affinity"); - f_set_thread_affinity(IntTuple{cpu_ids[worker_id]}); + f_set_thread_affinity(ffi::Shape{cpu_ids[worker_id]}); }); } // namespace runtime diff --git a/src/runtime/disco/cuda_ipc/cuda_ipc_memory.cc b/src/runtime/disco/cuda_ipc/cuda_ipc_memory.cc index eb22834d1a80..2ae5be1d453b 100644 --- a/src/runtime/disco/cuda_ipc/cuda_ipc_memory.cc +++ b/src/runtime/disco/cuda_ipc/cuda_ipc_memory.cc @@ -200,7 +200,7 @@ class CUDAIPCMemoryAllocator final : public memory::PooledAllocator { * \param dtype_hint The dtype of the storage to allocate. * \return The allocated storage object with internal CUDA IPC memory buffer. */ -memory::Storage IPCAllocStorage(ShapeTuple buffer_shape, DLDataType dtype_hint) { +memory::Storage IPCAllocStorage(ffi::Shape buffer_shape, DLDataType dtype_hint) { auto storage_obj = ffi::SimpleObjAllocator().make_object(); nccl::CCLThreadLocalContext* nccl_ctx = nccl::CCLThreadLocalContext::Get(); Device device{DLDeviceType::kDLCUDA, nccl_ctx->device_id}; diff --git a/src/runtime/disco/loader.cc b/src/runtime/disco/loader.cc index 7a79f0c392ef..fee20f7cdeda 100644 --- a/src/runtime/disco/loader.cc +++ b/src/runtime/disco/loader.cc @@ -45,7 +45,7 @@ using ParamRecord = NDArrayCacheMetadata::FileRecord::ParamRecord; struct ShardInfo { struct TensorInfo { - ShapeTuple shape; + ffi::Shape shape; DataType dtype; }; struct ShardFunc { @@ -78,7 +78,7 @@ ShardInfo::TensorInfo LoadTensorInfoFromJSON(const picojson::array& json_tensor_ shape.push_back(AsType(shape_json[i])); } std::string dtype = AsType(json_tensor_info[1]); - return ShardInfo::TensorInfo{ShapeTuple(std::move(shape)), DataType(StringToDLDataType(dtype))}; + return ShardInfo::TensorInfo{ffi::Shape(std::move(shape)), DataType(StringToDLDataType(dtype))}; } ShardInfo::ShardFunc LoadShardFuncFromJSON(const picojson::array& json_shard_func) { @@ -314,13 +314,13 @@ NDArray ShardLoaderObj::Load(int weight_index) const { bool needs_sharding = !param_info.shard_info.funcs.empty(); if (needs_sharding) { - ShapeTuple shape = param_info.shard_info.funcs.back().output_info.shape; + ffi::Shape shape = param_info.shard_info.funcs.back().output_info.shape; DataType dtype = param_info.shard_info.funcs.back().output_info.dtype; ICHECK(shape.size() >= 1 && shape[0] == num_shards) << "ValueError: The first dimension of the " << "output shape must be equal to the " << "number of shards, but got: " << shape << " and num_shards = " << num_shards; - NDArray recv = NDArray::Empty(ShapeTuple(shape.begin() + 1, shape.end()), dtype, device); + NDArray recv = NDArray::Empty(ffi::Shape(shape.begin() + 1, shape.end()), dtype, device); if (worker_id == 0) { NDArray w = LoadDirect(weight_index); for (const ShardInfo::ShardFunc& shard_func : param_info.shard_info.funcs) { @@ -328,7 +328,7 @@ NDArray ShardLoaderObj::Load(int weight_index) const { } ScatterFromWorker0(w, /*in_group=*/false, recv); } else { - ScatterFromWorker0(NullOpt, /*in_group=*/false, recv); + ScatterFromWorker0(std::nullopt, /*in_group=*/false, recv); } return recv; } else { @@ -408,18 +408,18 @@ Array ShardLoaderObj::LoadAllPresharded() const { TVM_REGISTER_GLOBAL("runtime.disco.ShardLoader").set_body_typed(ShardLoaderObj::Create); TVM_REGISTER_GLOBAL("runtime.disco.ShardLoaderLoad") - .set_body_typed([](ObjectRef loader_obj, ShapeTuple weight_index) { + .set_body_typed([](ObjectRef loader_obj, ffi::Shape weight_index) { const auto* loader = loader_obj.as(); CHECK(loader != nullptr) << "TypeError: Expected ShardLoaderObj, but gets: " << loader_obj->GetTypeKey(); - return loader->Load(IntegerFromShapeTuple(weight_index)); + return loader->Load(IntegerFromShape(weight_index)); }); TVM_REGISTER_GLOBAL("runtime.disco.ShardLoaderLoadPresharded") - .set_body_typed([](ObjectRef loader_obj, ShapeTuple weight_index) { + .set_body_typed([](ObjectRef loader_obj, ffi::Shape weight_index) { const auto* loader = loader_obj.as(); CHECK(loader != nullptr) << "TypeError: Expected ShardLoaderObj, but gets: " << loader_obj->GetTypeKey(); - return loader->LoadPresharded(IntegerFromShapeTuple(weight_index)); + return loader->LoadPresharded(IntegerFromShape(weight_index)); }); TVM_REGISTER_GLOBAL("runtime.disco.ShardLoaderLoadAll").set_body_typed([](ObjectRef loader_obj) { diff --git a/src/runtime/disco/nccl/nccl.cc b/src/runtime/disco/nccl/nccl.cc index 075068a336ac..9a0b3fb442d5 100644 --- a/src/runtime/disco/nccl/nccl.cc +++ b/src/runtime/disco/nccl/nccl.cc @@ -52,7 +52,7 @@ inline ncclRedOp_t AsNCCLRedOp(ReduceKind kind) { throw; } -void InitCCL(Session sess, IntTuple device_ids) { +void InitCCL(Session sess, ffi::Shape device_ids) { DRef func = sess->GetGlobalFunc("runtime.disco." TVM_DISCO_CCL_NAME ".init_ccl_per_worker"); DLOG(INFO) << "Initializing " TVM_DISCO_CCL_NAME " with devices: " << device_ids; ncclUniqueId id; @@ -60,7 +60,7 @@ void InitCCL(Session sess, IntTuple device_ids) { sess->CallPacked(func, device_ids, ffi::Bytes(id.internal, NCCL_UNIQUE_ID_BYTES)); } -void InitCCLPerWorker(IntTuple device_ids, std::string unique_id_bytes) { +void InitCCLPerWorker(ffi::Shape device_ids, std::string unique_id_bytes) { CCLThreadLocalContext* ctx = CCLThreadLocalContext::Get(); DiscoWorker* worker = DiscoWorker::ThreadLocal(); ICHECK(worker != nullptr); @@ -116,7 +116,7 @@ void InitCCLPerWorker(IntTuple device_ids, std::string unique_id_bytes) { void AllReduce(NDArray send, ReduceKind reduce_kind, bool in_group, NDArray recv) { CCLThreadLocalContext* ctx = CCLThreadLocalContext::Get(); - ShapeTuple shape = send.Shape(); + ffi::Shape shape = send.Shape(); int64_t numel = shape->Product(); deviceStream_t stream = ctx->GetDefaultStream(); DataType dtype = DataType(send->dtype); @@ -131,7 +131,7 @@ void AllReduce(NDArray send, ReduceKind reduce_kind, bool in_group, NDArray recv void AllGather(NDArray send, bool in_group, NDArray recv) { CCLThreadLocalContext* ctx = CCLThreadLocalContext::Get(); - ShapeTuple shape = send.Shape(); + ffi::Shape shape = send.Shape(); int64_t numel = shape->Product(); deviceStream_t stream = ctx->GetDefaultStream(); NCCL_CALL(ncclAllGather(send->data, recv->data, numel, diff --git a/src/runtime/disco/process_session.cc b/src/runtime/disco/process_session.cc index 4265bd21c43d..6f2042aa2529 100644 --- a/src/runtime/disco/process_session.cc +++ b/src/runtime/disco/process_session.cc @@ -70,7 +70,7 @@ class ProcessSessionObj final : public BcastSessionObj { read_fds.reserve(num_workers - 1); write_fds.reserve(num_workers - 1); for (int i = 1; i < num_workers; ++i) { - IntTuple fds = process_pool(i).cast(); + ffi::Shape fds = process_pool(i).cast(); CHECK_EQ(fds.size(), 2) << "ValueError: process_pool(" << i << ") should return a tuple of " << "size 2, but got a tuple of size " << fds.size() << "."; read_fds.push_back(fds[0]); diff --git a/src/runtime/disco/protocol.h b/src/runtime/disco/protocol.h index 13fda2fecde4..c14f7cdaba3a 100644 --- a/src/runtime/disco/protocol.h +++ b/src/runtime/disco/protocol.h @@ -124,15 +124,15 @@ template inline uint64_t DiscoProtocol::GetObjectBytes(Object* obj) { if (obj->IsInstance()) { return sizeof(uint32_t) + sizeof(int64_t); - } else if (obj->IsInstance()) { - uint64_t size = static_cast(obj)->size; + } else if (obj->IsInstance()) { + uint64_t size = static_cast(obj)->size; return sizeof(uint32_t) + sizeof(uint64_t) + size * sizeof(char); } else if (obj->IsInstance()) { uint64_t size = static_cast(obj)->size; return sizeof(uint32_t) + sizeof(uint64_t) + size * sizeof(char); - } else if (obj->IsInstance()) { - uint64_t ndim = static_cast(obj)->size; - return sizeof(uint32_t) + sizeof(uint64_t) + ndim * sizeof(ShapeTupleObj::index_type); + } else if (obj->IsInstance()) { + uint64_t ndim = static_cast(obj)->size; + return sizeof(uint32_t) + sizeof(uint64_t) + ndim * sizeof(ffi::ShapeObj::index_type); } else if (obj->IsInstance()) { return sizeof(uint32_t) + static_cast(obj)->GetObjectBytes(); } else { @@ -147,8 +147,8 @@ inline void DiscoProtocol::WriteObject(Object* obj) { int64_t reg_id = static_cast(obj)->reg_id; self->template Write(TypeIndex::kRuntimeDiscoDRef); self->template Write(reg_id); - } else if (obj->IsInstance()) { - StringObj* str = static_cast(obj); + } else if (obj->IsInstance()) { + ffi::StringObj* str = static_cast(obj); self->template Write(TypeIndex::kRuntimeString); self->template Write(str->size); self->template WriteArray(str->data, str->size); @@ -157,11 +157,11 @@ inline void DiscoProtocol::WriteObject(Object* obj) { self->template Write(ffi::TypeIndex::kTVMFFIBytes); self->template Write(bytes->size); self->template WriteArray(bytes->data, bytes->size); - } else if (obj->IsInstance()) { - ShapeTupleObj* shape = static_cast(obj); - self->template Write(TypeIndex::kRuntimeShapeTuple); + } else if (obj->IsInstance()) { + ffi::ShapeObj* shape = static_cast(obj); + self->template Write(TypeIndex::kRuntimeShape); self->template Write(shape->size); - self->template WriteArray(shape->data, shape->size); + self->template WriteArray(shape->data, shape->size); } else if (obj->IsInstance()) { self->template Write(0); std::string str = static_cast(obj)->SaveToStr(); @@ -196,12 +196,12 @@ inline void DiscoProtocol::ReadObject(int* tcode, TVMValue* value) std::string data(size, '\0'); self->template ReadArray(data.data(), size); result = ffi::Bytes(std::move(data)); - } else if (type_index == TypeIndex::kRuntimeShapeTuple) { + } else if (type_index == TypeIndex::kRuntimeShape) { uint64_t ndim = 0; self->template Read(&ndim); - std::vector data(ndim); - self->template ReadArray(data.data(), ndim); - result = ShapeTuple(std::move(data)); + std::vector data(ndim); + self->template ReadArray(data.data(), ndim); + result = ffi::Shape(std::move(data)); } else if (type_index == 0) { uint64_t size = 0; self->template Read(&size); diff --git a/src/runtime/disco/utils.h b/src/runtime/disco/utils.h index 0c177e36e925..fa58c73aa787 100644 --- a/src/runtime/disco/utils.h +++ b/src/runtime/disco/utils.h @@ -39,7 +39,7 @@ inline Device UseDefaultDeviceIfNone(Device device) { * \note At the time of scaffolding Disco, RelaxVM has not provided mature support for standalone * integers. A common workaround is to use a 1-d shape tuple as an integer. */ -inline int64_t IntegerFromShapeTuple(const ShapeTuple& shape) { +inline int64_t IntegerFromShape(const ffi::Shape& shape) { CHECK_EQ(shape.size(), 1) << "ValueError: shape tuple must be 1-d to be converted to integer."; return shape[0]; } diff --git a/src/runtime/dso_library.cc b/src/runtime/dso_library.cc index 185b066e724e..7ae4971a85f1 100644 --- a/src/runtime/dso_library.cc +++ b/src/runtime/dso_library.cc @@ -21,7 +21,7 @@ * \file dso_libary.cc * \brief Create library module to load from dynamic shared library. */ -#include +#include #include #include #include diff --git a/src/runtime/file_utils.h b/src/runtime/file_utils.h index 0f3dc135712f..b4da7adea813 100644 --- a/src/runtime/file_utils.h +++ b/src/runtime/file_utils.h @@ -24,8 +24,8 @@ #ifndef TVM_RUNTIME_FILE_UTILS_H_ #define TVM_RUNTIME_FILE_UTILS_H_ -#include -#include +#include +#include #include #include diff --git a/src/runtime/memory/memory_manager.cc b/src/runtime/memory/memory_manager.cc index 9b6eae80394a..2b5c217c72be 100644 --- a/src/runtime/memory/memory_manager.cc +++ b/src/runtime/memory/memory_manager.cc @@ -59,7 +59,7 @@ inline size_t GetDataAlignment(const DLDataType& dtype) { return align; } -NDArray StorageObj::AllocNDArrayScoped(int64_t offset, ShapeTuple shape, DLDataType dtype, +NDArray StorageObj::AllocNDArrayScoped(int64_t offset, ffi::Shape shape, DLDataType dtype, String scope) { if (scope == "global" || scope.empty()) { return AllocNDArray(offset, shape, dtype); @@ -90,7 +90,7 @@ NDArray StorageObj::AllocNDArrayScoped(int64_t offset, ShapeTuple shape, DLDataT this->buffer.device, shape, scope, offset); } -NDArray StorageObj::AllocNDArray(int64_t offset, ShapeTuple shape, DLDataType dtype) { +NDArray StorageObj::AllocNDArray(int64_t offset, ffi::Shape shape, DLDataType dtype) { VerifyDataType(dtype); size_t needed_size = ffi::GetDataSize(shape.Product(), dtype); @@ -212,7 +212,7 @@ void MemoryManager::Clear() { } } -NDArray Allocator::Empty(ShapeTuple shape, DLDataType dtype, DLDevice dev, +NDArray Allocator::Empty(ffi::Shape shape, DLDataType dtype, DLDevice dev, Optional mem_scope) { VerifyDataType(dtype); @@ -245,7 +245,7 @@ bool Allocator::AllowMemoryScope(const std::string& mem_scope) const { return mem_scope.empty() || mem_scope == "global"; } -Buffer Allocator::Alloc(Device dev, ShapeTuple shape, DLDataType type_hint, +Buffer Allocator::Alloc(Device dev, ffi::Shape shape, DLDataType type_hint, const std::string& mem_scope) { if (AllowMemoryScope(mem_scope)) { // by default, we can always redirect to the flat memory allocations diff --git a/src/runtime/memory/naive_allocator.h b/src/runtime/memory/naive_allocator.h index 6d8e90fed9f2..aed990d22c3b 100644 --- a/src/runtime/memory/naive_allocator.h +++ b/src/runtime/memory/naive_allocator.h @@ -48,7 +48,7 @@ class NaiveAllocator final : public Allocator { return buf; } - Buffer Alloc(Device dev, ShapeTuple shape, DLDataType type_hint, + Buffer Alloc(Device dev, ffi::Shape shape, DLDataType type_hint, const std::string& mem_scope) final { Buffer buf; size_t nbytes = 1; diff --git a/src/runtime/memory/pooled_allocator.h b/src/runtime/memory/pooled_allocator.h index 2c46d5df51a4..744c61987cdd 100644 --- a/src/runtime/memory/pooled_allocator.h +++ b/src/runtime/memory/pooled_allocator.h @@ -73,7 +73,7 @@ class PooledAllocator : public Allocator { return buf; } - Buffer Alloc(Device dev, ShapeTuple shape, DLDataType type_hint, + Buffer Alloc(Device dev, ffi::Shape shape, DLDataType type_hint, const std::string& mem_scope) override { if (AllowMemoryScope(mem_scope)) { return Allocator::Alloc(dev, shape, type_hint, mem_scope); diff --git a/src/runtime/ndarray.cc b/src/runtime/ndarray.cc index c90c3aaa95f9..d30c29689963 100644 --- a/src/runtime/ndarray.cc +++ b/src/runtime/ndarray.cc @@ -92,7 +92,7 @@ void ArrayCopyToBytes(const DLTensor* handle, void* data, size_t nbytes) { DeviceAPI::Get(handle->device)->StreamSync(handle->device, nullptr); } -NDArray NDArray::Empty(ShapeTuple shape, DLDataType dtype, Device dev, Optional mem_scope) { +NDArray NDArray::Empty(ffi::Shape shape, DLDataType dtype, Device dev, Optional mem_scope) { struct DeviceAPIAlloc { void AllocData(DLTensor* tensor, ffi::Optional mem_scope) { tensor->data = DeviceAPI::Get(tensor->device) @@ -117,7 +117,7 @@ struct NDArray::Internal { static void FFIDecRef(TVMArrayHandle tensor) { NDArray::FFIDecRef(tensor); } }; -NDArray NDArray::CreateView(ShapeTuple shape, DLDataType dtype, +NDArray NDArray::CreateView(ffi::Shape shape, DLDataType dtype, uint64_t relative_byte_offset) const { ICHECK(data_ != nullptr); @@ -152,7 +152,7 @@ NDArray NDArray::CreateView(ShapeTuple shape, DLDataType dtype, << "This would occupy bytes " << relative_byte_offset << " <= i_byte < " << (relative_byte_offset + view_size) << " within the backing array. " << "However, the NDArray being viewed only contains " << curr_size << " bytes (shape = " - << ShapeTuple(curr_dl_tensor.shape, curr_dl_tensor.shape + curr_dl_tensor.ndim) + << ffi::Shape(curr_dl_tensor.shape, curr_dl_tensor.shape + curr_dl_tensor.ndim) << ", dtype= " << curr_dl_tensor.dtype << ")."; // helper allocator class that retains ref count of original NDArray @@ -191,7 +191,7 @@ NDArray NDArray::CopyTo(const Device& dev, Optional mem_scope) const { ICHECK(data_ != nullptr); const DLTensor* dptr = operator->(); NDArray ret = - Empty(ShapeTuple(dptr->shape, dptr->shape + dptr->ndim), dptr->dtype, dev, mem_scope); + Empty(ffi::Shape(dptr->shape, dptr->shape + dptr->ndim), dptr->dtype, dev, mem_scope); this->CopyTo(ret); Device copy_gpu_dev = dptr->device.device_type != kDLCPU ? dptr->device : dev; DeviceAPI::Get(copy_gpu_dev)->StreamSync(copy_gpu_dev, nullptr); @@ -239,7 +239,7 @@ int TVMArrayAlloc(const tvm_index_t* shape, int ndim, int dtype_code, int dtype_ tvm::Device dev; dev.device_type = static_cast(device_type); dev.device_id = device_id; - auto ndarray = NDArray::Empty(ShapeTuple(shape, shape + ndim), dtype, dev); + auto ndarray = NDArray::Empty(tvm::ffi::Shape(shape, shape + ndim), dtype, dev); *out = NDArray::Internal::MoveToFFIHandle(ndarray); API_END(); diff --git a/src/runtime/opencl/opencl_common.h b/src/runtime/opencl/opencl_common.h index 6f2a9e610363..7288b65b0a24 100644 --- a/src/runtime/opencl/opencl_common.h +++ b/src/runtime/opencl/opencl_common.h @@ -340,8 +340,8 @@ class OpenCLWorkspace : public DeviceAPI { return device_info[GetCLDeviceID(device_id)].image_from_buffer_support; } - void* AllocDataSpaceView(Device dev, void* data, ShapeTuple shape, DLDataType dtype, - Optional mem_scope = NullOpt); + void* AllocDataSpaceView(Device dev, void* data, ffi::Shape shape, DLDataType dtype, + Optional mem_scope = std::nullopt); void FreeDataSpaceView(Device dev, void* ptr); cl_device_id GetCLDeviceID(int device_id); @@ -350,9 +350,9 @@ class OpenCLWorkspace : public DeviceAPI { void GetAttr(Device dev, DeviceAttrKind kind, ffi::Any* rv) final; void* AllocDataSpace(Device dev, size_t size, size_t alignment, DLDataType type_hint) final; void* AllocDataSpace(Device dev, int ndim, const int64_t* shape, DLDataType dtype, - Optional mem_scope = NullOpt) final; + Optional mem_scope = std::nullopt) final; void* AllocDataSpace(Device dev, size_t width, size_t height, DLDataType type_hint, - Optional mem_scope = NullOpt); + Optional mem_scope = std::nullopt); void* GetNativePtr(const tvm::runtime::NDArray& narr); void SetNativePtr(const tvm::runtime::NDArray& narr, void* host_ptr, size_t buf_size); void SetPerfHint(Device dev, cl_uint perf_hint); @@ -360,7 +360,7 @@ class OpenCLWorkspace : public DeviceAPI { void StreamSync(Device dev, TVMStreamHandle stream) final; void* AllocWorkspace(Device dev, size_t size, DLDataType type_hint) final; void FreeWorkspace(Device dev, void* data) final; - size_t GetDataSize(const DLTensor& arr, Optional mem_scope = NullOpt) final; + size_t GetDataSize(const DLTensor& arr, Optional mem_scope = std::nullopt) final; // cl_mem alloc utils void* AllocCLBuffer(Device dev, size_t size, size_t alignment, DLDataType type_hint); diff --git a/src/runtime/opencl/opencl_device_api.cc b/src/runtime/opencl/opencl_device_api.cc index a436ede61bc9..d6eaec6c0e04 100644 --- a/src/runtime/opencl/opencl_device_api.cc +++ b/src/runtime/opencl/opencl_device_api.cc @@ -358,7 +358,7 @@ size_t OpenCLWorkspace::GetDataSize(const DLTensor& arr, Optional mem_sc mem_scope.value(), row_align); } -void* OpenCLWorkspace::AllocDataSpaceView(Device dev, void* data, ShapeTuple shape, +void* OpenCLWorkspace::AllocDataSpaceView(Device dev, void* data, ffi::Shape shape, DLDataType dtype, Optional mem_scope) { cl::BufferDescriptor* desc = static_cast(data); @@ -851,7 +851,7 @@ class OpenCLPooledAllocator final : public memory::PooledAllocator { return buf; } - Buffer Alloc(Device dev, ShapeTuple shape, DLDataType type_hint, + Buffer Alloc(Device dev, ffi::Shape shape, DLDataType type_hint, const std::string& mem_scope) override { if (AllowMemoryScope(mem_scope)) { size_t size = ffi::GetDataSize(shape.Product(), type_hint); @@ -881,7 +881,7 @@ class OpenCLPooledAllocator final : public memory::PooledAllocator { VLOG(1) << "reclaim buffer " << buffer.size; } - void* CreateView(const Buffer& buffer, ShapeTuple shape, DLDataType type_hint, + void* CreateView(const Buffer& buffer, ffi::Shape shape, DLDataType type_hint, const std::string& mem_scope) final { OpenCLWorkspace* ws_ = OpenCLWorkspace::Global(); return ws_->AllocDataSpaceView(buffer.device, buffer.data, shape, type_hint, String(mem_scope)); diff --git a/src/runtime/profiling.cc b/src/runtime/profiling.cc index c073056fb320..bb67f6f6eb7b 100644 --- a/src/runtime/profiling.cc +++ b/src/runtime/profiling.cc @@ -283,7 +283,7 @@ String ReportNode::AsCSV() const { s << (*it).second.as()->percent; } else if ((*it).second.as()) { s << (*it).second.as()->ratio; - } else if ((*it).second.as()) { + } else if ((*it).second.as()) { s << "\"" << Downcast((*it).second) << "\""; } } @@ -298,7 +298,7 @@ String ReportNode::AsCSV() const { namespace { void metric_as_json(std::ostream& os, ObjectRef o) { - if (o.as()) { + if (o.as()) { os << "{\"string\":" << "\"" << Downcast(o) << "\"" << "}"; @@ -412,7 +412,7 @@ ObjectRef AggregateMetric(const std::vector& metrics) { sum += metric.as()->ratio; } return ObjectRef(make_object(sum / metrics.size())); - } else if (metrics[0].as()) { + } else if (metrics[0].as()) { for (auto& m : metrics) { if (Downcast(metrics[0]) != Downcast(m)) { return ObjectRef(String("")); @@ -461,7 +461,7 @@ static String print_metric(ObjectRef metric) { set_locale_for_separators(s); s << std::setprecision(2) << metric.as()->ratio; val = s.str(); - } else if (metric.as()) { + } else if (metric.as()) { val = Downcast(metric); } else { LOG(FATAL) << "Cannot print metric of type " << metric->GetTypeKey(); diff --git a/src/runtime/registry.cc b/src/runtime/registry.cc index 1045dc20ef0d..443b625d1cb4 100644 --- a/src/runtime/registry.cc +++ b/src/runtime/registry.cc @@ -212,7 +212,7 @@ WrappedPythonObject& WrappedPythonObject::operator=(std::nullptr_t) { /*! \brief entry to easily hold returning information */ struct TVMFuncThreadLocalEntry { /*! \brief result holder for returning strings */ - std::vector ret_vec_str; + std::vector ret_vec_str; /*! \brief result holder for returning string pointers */ std::vector ret_vec_charp; }; diff --git a/src/runtime/relax_vm/attn_backend.h b/src/runtime/relax_vm/attn_backend.h index 4d3a3ce9d832..dd8127525c9c 100644 --- a/src/runtime/relax_vm/attn_backend.h +++ b/src/runtime/relax_vm/attn_backend.h @@ -25,7 +25,8 @@ #ifndef TVM_RUNTIME_RELAX_VM_ATTN_BACKEND_H_ #define TVM_RUNTIME_RELAX_VM_ATTN_BACKEND_H_ -#include +#include +#include #include #include diff --git a/src/runtime/relax_vm/attn_utils.h b/src/runtime/relax_vm/attn_utils.h index 3e53d6bbc215..547d32c1208e 100644 --- a/src/runtime/relax_vm/attn_utils.h +++ b/src/runtime/relax_vm/attn_utils.h @@ -65,7 +65,7 @@ enum class AttnKind : int { }; /*! \brief Given the attention kind and other metadata, return the one-layer KV cache shape. */ -inline ShapeTuple GetKVCacheShape(AttnKind attn_kind, int64_t num_total_pages, int num_sequence, +inline ffi::Shape GetKVCacheShape(AttnKind attn_kind, int64_t num_total_pages, int num_sequence, int64_t num_kv_heads, int64_t page_size, int64_t qk_head_dim, int64_t v_head_dim) { if (attn_kind == AttnKind::kMHA) { @@ -77,7 +77,7 @@ inline ShapeTuple GetKVCacheShape(AttnKind attn_kind, int64_t num_total_pages, i return {num_sequence, num_kv_heads, qk_head_dim, v_head_dim}; } ICHECK(false); - return ShapeTuple(); + return ffi::Shape(); } /*! @@ -662,7 +662,7 @@ class PlainPagedKVCacheAuxDataManager : public PagedKVCacheAuxDataManager { int n_elem = last_page_len->size(); ICHECK_GT(n_elem, 0); NDArray view = length_info_on_depths_device_[depth].CreateView({3, n_elem}, dtype_aux_); - ShapeTuple copy_shape{n_elem}; + ffi::Shape copy_shape{n_elem}; CopyVecDataToArray(view, last_page_len->data(), copy_shape); CopyVecDataToArray(view, sliding_window_offset->data(), copy_shape, /*dst_elem_offset=*/n_elem); @@ -689,7 +689,7 @@ class PlainPagedKVCacheAuxDataManager : public PagedKVCacheAuxDataManager { ICHECK_GT(n_elem, 0); NDArray view = commit_copy_src_dst_pos_in_page_table_device_.CreateView({2, n_elem}, dtype_aux_); - ShapeTuple copy_shape{n_elem}; + ffi::Shape copy_shape{n_elem}; CopyVecDataToArray(view, src_data->data(), copy_shape); CopyVecDataToArray(view, dst_data->data(), copy_shape, /*dst_elem_offset=*/n_elem); @@ -705,8 +705,8 @@ class PlainPagedKVCacheAuxDataManager : public PagedKVCacheAuxDataManager { * It optionally supports specifying the shape of copy and the element * offset to the destination NDArray. */ - void CopyVecDataToArray(NDArray array, int32_t* vec_data, Optional shape = NullOpt, - int dst_elem_offset = 0) { + void CopyVecDataToArray(NDArray array, int32_t* vec_data, + Optional shape = std::nullopt, int dst_elem_offset = 0) { if (array->shape[0] == 0) { return; } diff --git a/src/runtime/relax_vm/builtin.cc b/src/runtime/relax_vm/builtin.cc index 29adde567ad7..399109131af4 100644 --- a/src/runtime/relax_vm/builtin.cc +++ b/src/runtime/relax_vm/builtin.cc @@ -20,12 +20,12 @@ * \file src/runtime/relax_vm/builtin.cc */ #include -#include -#include +#include +#include +#include #include #include #include -#include #include #include #include @@ -117,11 +117,11 @@ TVM_REGISTER_GLOBAL("vm.builtin.match_prim_value").set_body_typed(MatchPrimValue */ void MatchShape(ffi::PackedArgs args, Any* rv) { // input shape the first argument can take in tensor or shape. - ShapeTuple input_shape; + ffi::Shape input_shape; if (auto opt_nd = args[0].as()) { input_shape = opt_nd.value().Shape(); } else { - input_shape = args[0].cast(); + input_shape = args[0].cast(); } auto heap = args[1].as(); int64_t* heap_data = heap.has_value() ? static_cast((*heap)->data) : nullptr; @@ -209,7 +209,7 @@ void MakeShape(ffi::PackedArgs args, Any* rv) { shape[i] = heap_data[reg]; } } - *rv = ShapeTuple(std::move(shape)); + *rv = ffi::Shape(std::move(shape)); } TVM_REGISTER_GLOBAL("vm.builtin.make_shape").set_body_packed(MakeShape); @@ -262,7 +262,7 @@ TVM_REGISTER_GLOBAL("vm.builtin.check_tensor_info").set_body_packed(CheckTensorI */ void CheckShapeInfo(ObjectRef arg, int ndim, Optional err_ctx) { // a function that lazily get context for error reporting - auto* ptr = arg.as(); + auto* ptr = arg.as(); CHECK(ptr != nullptr) << "TypeError: " << err_ctx.value_or("") << " expect a Shape but get " << arg->GetTypeKey(); if (ndim != -1) { @@ -336,7 +336,7 @@ TVM_REGISTER_GLOBAL("vm.builtin.check_func_info").set_body_typed(CheckFuncInfo); //------------------------------------------------- // Storage management. //------------------------------------------------- -Storage VMAllocStorage(void* ctx_ptr, ShapeTuple buffer_shape, Index device_index, +Storage VMAllocStorage(void* ctx_ptr, ffi::Shape buffer_shape, Index device_index, DLDataType dtype_hint, String mem_scope) { VirtualMachine* vm = static_cast(ctx_ptr); @@ -383,7 +383,7 @@ TVM_REGISTER_GLOBAL("vm.builtin.invoke_closure").set_body_packed([](ffi::PackedA TVM_REGISTER_GLOBAL("vm.builtin.call_tir_dyn").set_body_packed([](ffi::PackedArgs args, Any* rv) { ffi::Function func = args[0].cast(); - ShapeTuple to_unpack = args[args.size() - 1].cast(); + ffi::Shape to_unpack = args[args.size() - 1].cast(); size_t num_tensor_args = args.size() - 2; std::vector packed_args(num_tensor_args + to_unpack.size()); @@ -402,7 +402,7 @@ TVM_REGISTER_GLOBAL("vm.builtin.shape_of").set_body_method(&NDArray::Shape); TVM_REGISTER_GLOBAL("vm.builtin.copy").set_body_typed([](Any a) -> Any { return a; }); -TVM_REGISTER_GLOBAL("vm.builtin.reshape").set_body_typed([](NDArray data, ShapeTuple new_shape) { +TVM_REGISTER_GLOBAL("vm.builtin.reshape").set_body_typed([](NDArray data, ffi::Shape new_shape) { return data.CreateView(new_shape, data->dtype); }); @@ -491,8 +491,9 @@ TVM_REGISTER_GLOBAL("vm.builtin.invoke_debug_func") //------------------------------------- // Data structure API //------------------------------------- -TVM_REGISTER_GLOBAL("vm.builtin.tuple_getitem") - .set_body_typed([](runtime::Array arr, int64_t index) { return arr[index]; }); +TVM_REGISTER_GLOBAL("vm.builtin.tuple_getitem").set_body_typed([](Array arr, int64_t index) { + return arr[index]; +}); TVM_REGISTER_GLOBAL("vm.builtin.tuple_reset_item") .set_body_typed([](const ffi::ArrayObj* arr, int64_t index) { @@ -500,7 +501,7 @@ TVM_REGISTER_GLOBAL("vm.builtin.tuple_reset_item") }); TVM_REGISTER_GLOBAL("vm.builtin.make_tuple").set_body_packed([](ffi::PackedArgs args, Any* rv) { - runtime::Array arr; + Array arr; for (int i = 0; i < args.size(); ++i) { arr.push_back(args[i]); } @@ -538,7 +539,7 @@ TVM_REGISTER_GLOBAL("vm.builtin.tensor_to_shape").set_body_typed([](NDArray data } out_shape.push_back(result); } - return ShapeTuple(out_shape); + return ffi::Shape(out_shape); }); TVM_REGISTER_GLOBAL("vm.builtin.ensure_zero_offset").set_body_typed([](NDArray data) { diff --git a/src/runtime/relax_vm/cuda/cuda_graph_builtin.cc b/src/runtime/relax_vm/cuda/cuda_graph_builtin.cc index 0c0c8eda493c..501f7925de2d 100644 --- a/src/runtime/relax_vm/cuda/cuda_graph_builtin.cc +++ b/src/runtime/relax_vm/cuda/cuda_graph_builtin.cc @@ -22,7 +22,7 @@ * \brief The CUDA graph related builtin functions for Relax virtual machine. */ -#include +#include #include #include #include @@ -41,9 +41,9 @@ struct CUDAGraphCaptureKey { // The symbolic variables the capture function depends on. When the capture function is ran with // different symbolic variable values, the CUDA graph will be re-captured as a different version, // identified by this shape tuple. This is default constructed as an empty tuple. - ShapeTuple shape_expr; + ffi::Shape shape_expr; - CUDAGraphCaptureKey(int64_t index, const Optional& shape_expr) : index(index) { + CUDAGraphCaptureKey(int64_t index, const Optional& shape_expr) : index(index) { if (shape_expr) { this->shape_expr = shape_expr.value(); } @@ -150,7 +150,7 @@ class CUDAGraphExtensionNode : public VMExtensionNode { * \return The return value of the capture function. */ ObjectRef RunOrCapture(VirtualMachine* vm, const ObjectRef& capture_func, ObjectRef args, - int64_t entry_index, Optional shape_expr) { + int64_t entry_index, Optional shape_expr) { CUDAGraphCaptureKey entry_key{entry_index, shape_expr}; if (auto it = capture_cache_.find(entry_key); it != capture_cache_.end()) { // Launch CUDA graph @@ -249,9 +249,9 @@ TVM_REGISTER_GLOBAL("vm.builtin.cuda_graph.run_or_capture") auto capture_func = args[1].cast(); auto func_args = args[2].cast(); int64_t entry_index = args[3].cast(); - Optional shape_expr = NullOpt; + Optional shape_expr = std::nullopt; if (args.size() == 5) { - shape_expr = args[4].cast(); + shape_expr = args[4].cast(); } *rv = extension->RunOrCapture(vm, capture_func, func_args, entry_index, shape_expr); }); diff --git a/src/runtime/relax_vm/executable.cc b/src/runtime/relax_vm/executable.cc index 07d37bb4d3ea..ff6f99c4d262 100644 --- a/src/runtime/relax_vm/executable.cc +++ b/src/runtime/relax_vm/executable.cc @@ -38,16 +38,6 @@ namespace relax_vm { /*! \brief The magic number for the serialized VM bytecode file */ constexpr uint64_t kTVMVMBytecodeMagic = 0xD225DE2F4214151D; -/*! \brief Possible types in the constant pool */ -enum ConstantType : int { - kNDArray = 0, - kDLDataType = 1, - kShapeTuple = 2, - kString = 3, - kInt = 4, - kFloat = 5, -}; - #define STREAM_CHECK(val, section) \ ICHECK(val) << "Invalid VM file format in the " << section << " section." \ << "\n"; @@ -75,8 +65,8 @@ std::string VMExecutable::Stats() const { } oss.seekp(-2, oss.cur); oss << "], "; - } else if (auto opt_shape = it.as()) { - ShapeTuple shape = opt_shape.value(); + } else if (auto opt_shape = it.as()) { + ffi::Shape shape = opt_shape.value(); oss << "shapetuple["; for (size_t i = 0; i < shape.size(); ++i) { oss << shape.at(i) << ", "; @@ -264,30 +254,30 @@ void VMExecutable::SaveConstantSection(dmlc::Stream* strm) { strm->Write(static_cast(this->constants.size())); for (const auto& it : this->constants) { if (auto opt_nd = it.as()) { - strm->Write(ConstantType::kNDArray); + strm->Write(ffi::TypeIndex::kTVMFFINDArray); runtime::SaveDLTensor(strm, opt_nd.value().operator->()); - } else if (auto opt_shape = it.as()) { - ShapeTuple shape = opt_shape.value(); - strm->Write(ConstantType::kShapeTuple); + } else if (auto opt_shape = it.as()) { + ffi::Shape shape = opt_shape.value(); + strm->Write(ffi::TypeIndex::kTVMFFIShape); strm->Write(shape.size()); for (size_t i = 0; i < shape.size(); ++i) { strm->Write(shape.at(i)); } } else if (auto opt_str = it.as()) { String str = opt_str.value(); - strm->Write(ConstantType::kString); + strm->Write(ffi::TypeIndex::kTVMFFIStr); strm->Write(str.size()); for (size_t i = 0; i < str.size(); ++i) { strm->Write(str.at(i)); } } else if (auto opt_int = it.as()) { - strm->Write(ConstantType::kInt); + strm->Write(ffi::TypeIndex::kTVMFFIInt); strm->Write(opt_int.value()); } else if (auto opt_float = it.as()) { - strm->Write(ConstantType::kFloat); + strm->Write(ffi::TypeIndex::kTVMFFIFloat); strm->Write(opt_float.value()); } else if (auto opt_dtype = it.as()) { - strm->Write(ConstantType::kDLDataType); + strm->Write(ffi::TypeIndex::kTVMFFIDataType); strm->Write(opt_dtype.value()); } else { LOG(FATAL) << "Unsupported constant pool type " << it.GetTypeKey(); @@ -320,27 +310,27 @@ void VMExecutable::LoadConstantSection(dmlc::Stream* strm) { for (size_t i = 0; i < size; i++) { int constant_type; STREAM_CHECK(strm->Read(&constant_type, sizeof(constant_type)), "constant"); - if (constant_type == ConstantType::kNDArray) { + if (constant_type == ffi::TypeIndex::kTVMFFINDArray) { ndarray.Load(strm); ffi::Any cell; cell = ndarray; this->constants.push_back(cell); - } else if (constant_type == ConstantType::kShapeTuple) { + } else if (constant_type == ffi::TypeIndex::kTVMFFIShape) { uint64_t size; strm->Read(&size); - std::vector data(size); + std::vector data(size); for (size_t i = 0; i < size; ++i) { strm->Read(&(data[i])); } ffi::Any cell; - cell = ShapeTuple(data); + cell = ffi::Shape(data); this->constants.push_back(cell); - } else if (constant_type == ConstantType::kDLDataType) { + } else if (constant_type == ffi::TypeIndex::kTVMFFIDataType) { strm->Read(&dtype); ffi::Any cell; cell = dtype; this->constants.push_back(cell); - } else if (constant_type == ConstantType::kString) { + } else if (constant_type == ffi::TypeIndex::kTVMFFIStr) { uint64_t size; strm->Read(&size); std::vector data(size); @@ -350,13 +340,13 @@ void VMExecutable::LoadConstantSection(dmlc::Stream* strm) { ffi::Any cell; cell = String(std::string(data.begin(), data.end())); this->constants.push_back(cell); - } else if (constant_type == ConstantType::kInt) { + } else if (constant_type == ffi::TypeIndex::kTVMFFIInt) { int64_t value; strm->Read(&value); ffi::Any cell; cell = value; this->constants.push_back(cell); - } else if (constant_type == ConstantType::kFloat) { + } else if (constant_type == ffi::TypeIndex::kTVMFFIFloat) { double value; strm->Read(&value); ffi::Any cell; diff --git a/src/runtime/relax_vm/kv_state.cc b/src/runtime/relax_vm/kv_state.cc index 1af7cf78c944..f9689d64c647 100644 --- a/src/runtime/relax_vm/kv_state.cc +++ b/src/runtime/relax_vm/kv_state.cc @@ -42,11 +42,11 @@ TVM_REGISTER_GLOBAL("vm.builtin.kv_state_begin_forward") CHECK(args.size() == 3 || args.size() == 4) << "KVState BeginForward only accepts 3 or 4 arguments"; KVState kv_state = args[0].cast(); - IntTuple seq_ids = args[1].cast(); - IntTuple append_lengths = args[2].cast(); - Optional token_tree_parent_ptr; + ffi::Shape seq_ids = args[1].cast(); + ffi::Shape append_lengths = args[2].cast(); + Optional token_tree_parent_ptr; if (args.size() == 4) { - token_tree_parent_ptr = args[3].cast>(); + token_tree_parent_ptr = args[3].cast>(); } kv_state->BeginForward(seq_ids, append_lengths, token_tree_parent_ptr); }); @@ -76,8 +76,8 @@ TVM_REGISTER_GLOBAL("vm.builtin.attention_kv_cache_debug_get_kv_mla") TVM_REGISTER_GLOBAL("vm.builtin.attention_kv_cache_attention_with_fused_qkv") .set_body_typed([](AttentionKVCache kv_cache, int64_t layer_id, double sm_scale, NDArray qkv_data, NDArray o_data) { - kv_cache->AttentionWithFusedQKV(layer_id, std::move(qkv_data), NullOpt, std::move(o_data), - sm_scale); + kv_cache->AttentionWithFusedQKV(layer_id, std::move(qkv_data), std::nullopt, + std::move(o_data), sm_scale); }); TVM_REGISTER_GLOBAL("vm.builtin.attention_kv_cache_self_attention") .set_body_typed([](AttentionKVCache kv_cache, int64_t layer_id, double sm_scale, NDArray q_data, diff --git a/src/runtime/relax_vm/kv_state.h b/src/runtime/relax_vm/kv_state.h index 493fceaae9a2..3ddc9f6e0c9a 100644 --- a/src/runtime/relax_vm/kv_state.h +++ b/src/runtime/relax_vm/kv_state.h @@ -18,14 +18,14 @@ */ #ifndef TVM_RUNTIME_RELAX_VM_KV_STATE_H_ #define TVM_RUNTIME_RELAX_VM_KV_STATE_H_ -#include +#include #include +#include #include #include +#include #include -#include "tvm/runtime/object.h" - namespace tvm { namespace runtime { namespace relax_vm { @@ -95,7 +95,7 @@ class KVStateObj : public Object { * is a chain. */ virtual void BeginForward(const IntTuple& seq_ids, const IntTuple& append_lengths, - const Optional& token_tree_parent_ptr = NullOpt) = 0; + const Optional& token_tree_parent_ptr = std::nullopt) = 0; /*! * \brief Mark the start of the forward function. diff --git a/src/runtime/relax_vm/lm_support.cc b/src/runtime/relax_vm/lm_support.cc index 44079b48d1c5..45d8904d1932 100644 --- a/src/runtime/relax_vm/lm_support.cc +++ b/src/runtime/relax_vm/lm_support.cc @@ -35,11 +35,11 @@ * * We can evolve this implementation as we build more LM verticals. */ -#include -#include +#include +#include +#include #include #include -#include #include #include #include @@ -81,7 +81,7 @@ class AttentionKVCacheLegacyObj : public Object { * \brief View all current cached values as one array. * \param shape The cached values. */ - NDArray View(const ShapeTuple& shape) { + NDArray View(const ffi::Shape& shape) { CHECK_EQ(shape[0], fill_count) << "Requested shape do not match the filled count"; for (int i = 1; i < this->data->ndim; ++i) { CHECK_EQ(shape[i], data->shape[i]) << "Dimension " << i << " mismatch"; @@ -237,7 +237,7 @@ class AttentionKVCacheLegacy : public ObjectRef { * \brief Create the attention kv cache. * \param init_data The initial reserved. */ - static AttentionKVCacheLegacy Create(NDArray init_data, ShapeTuple reserve_shape, + static AttentionKVCacheLegacy Create(NDArray init_data, ffi::Shape reserve_shape, int init_fill_count) { auto n = make_object(); n->data = NDArray::Empty(reserve_shape, init_data->dtype, init_data->device); @@ -296,7 +296,7 @@ AttentionKVCacheLegacy AttentionKVCacheWindowOverrideWithSinks(AttentionKVCacheL TVM_REGISTER_GLOBAL("vm.builtin.attention_kv_cache_window_override_with_sinks") .set_body_typed(AttentionKVCacheWindowOverrideWithSinks); -NDArray AttentionKVCacheView(AttentionKVCacheLegacy cache, ShapeTuple shape) { +NDArray AttentionKVCacheView(AttentionKVCacheLegacy cache, ffi::Shape shape) { return cache->View(shape); } @@ -307,15 +307,15 @@ TVM_REGISTER_GLOBAL("vm.builtin.attention_kv_cache_view") << args.size() << "."; AttentionKVCacheLegacy cache = args[0].cast(); if (args.size() == 2) { - ShapeTuple shape = args[1].cast(); + ffi::Shape shape = args[1].cast(); *rv = cache->View(shape); } else { - std::vector shape; + std::vector shape; shape.push_back(cache->fill_count); for (int i = 1; i < cache->data->ndim; ++i) { shape.push_back(cache->data->shape[i]); } - *rv = cache->View(ShapeTuple(shape)); + *rv = cache->View(ffi::Shape(shape)); } }); diff --git a/src/runtime/relax_vm/ndarray_cache_support.cc b/src/runtime/relax_vm/ndarray_cache_support.cc index fc6eb6bf360f..427af3cdeb52 100644 --- a/src/runtime/relax_vm/ndarray_cache_support.cc +++ b/src/runtime/relax_vm/ndarray_cache_support.cc @@ -65,7 +65,7 @@ inline ValueType GetValue(const picojson::object& json, const std::string& key) } NDArrayCacheMetadata::FileRecord::ParamRecord JSONAsParamRecord(const picojson::object& json) { - std::vector shape; + std::vector shape; { picojson::array shape_json = GetValue(json, "shape"); shape.reserve(shape_json.size()); @@ -80,7 +80,7 @@ NDArrayCacheMetadata::FileRecord::ParamRecord JSONAsParamRecord(const picojson:: result.format = GetValue(json, "format"); result.nbytes = GetValue(json, "nbytes"); result.byte_offset = GetValue(json, "byteOffset"); - result.shape = ShapeTuple(std::move(shape)); + result.shape = ffi::Shape(std::move(shape)); return result; } @@ -153,7 +153,7 @@ void CopyNDArrayFromBytes(NDArray param, const void* data, size_t nbytes, if (staging_buffer->defined()) { size_t curr_size = runtime::GetDataSize(*(staging_buffer->value().operator->())); if (curr_size < nbytes) { - *staging_buffer = NullOpt; + *staging_buffer = std::nullopt; } } if (!staging_buffer->defined()) { @@ -225,7 +225,7 @@ class NDArrayCache { if (it != pool->pool_.end()) { return (*it).second; } else { - return NullOpt; + return std::nullopt; } } diff --git a/src/runtime/relax_vm/paged_kv_cache.cc b/src/runtime/relax_vm/paged_kv_cache.cc index c9fc851ea772..b8444e03cf02 100644 --- a/src/runtime/relax_vm/paged_kv_cache.cc +++ b/src/runtime/relax_vm/paged_kv_cache.cc @@ -155,9 +155,9 @@ class PagedAttentionKVCacheObj : public AttentionKVCacheObj { /*! \brief The batch size of the current round of forwarding. */ int64_t cur_batch_size_; /*! \brief The ids of the sequences in the current round of forwarding. */ - IntTuple cur_seq_ids_; + ffi::Shape cur_seq_ids_; /*! \brief The append lengths of the sequences in the current round of forwarding. */ - IntTuple cur_append_lengths_; + ffi::Shape cur_append_lengths_; /*! \brief Whether the current batch of sequences are token chains (not token trees). */ std::vector is_chain_on_depths_; /*! \brief Number of fork depth in the current round of forward. */ @@ -244,7 +244,7 @@ class PagedAttentionKVCacheObj : public AttentionKVCacheObj { Optional f_transpose_append_mha_; Optional f_transpose_append_mla_; Optional f_transfer_kv_; - Optional f_transfer_kv_page_to_page_ = NullOpt; + Optional f_transfer_kv_page_to_page_ = std::nullopt; ffi::Function f_compact_copy_; std::unique_ptr f_attention_prefill_ragged_; std::unique_ptr f_attention_prefill_; @@ -343,7 +343,7 @@ class PagedAttentionKVCacheObj : public AttentionKVCacheObj { ICHECK(f_nvshmem_empty.has_value()); nvshmem_pages_ = (*f_nvshmem_empty)( - ShapeTuple({num_layers, num_total_pages, 2, num_kv_heads, page_size, qk_head_dim}), + ffi::Shape({num_layers, num_total_pages, 2, num_kv_heads, page_size, qk_head_dim}), dtype, device) .cast(); for (int i = 0; i < num_layers; ++i) { @@ -362,7 +362,7 @@ class PagedAttentionKVCacheObj : public AttentionKVCacheObj { f_transfer_kv_page_to_page_ = *f_transfer_kv_page_to_page_ptr; } else { for (int i = 0; i < num_layers; ++i) { - ShapeTuple kv_cache_shape = + ffi::Shape kv_cache_shape = GetKVCacheShape(attn_kinds_[layer_id_begin_offset_ + i], num_total_pages, reserved_num_seqs, num_kv_heads, page_size, qk_head_dim, v_head_dim); pages_.push_back(NDArray::Empty(kv_cache_shape, dtype, device)); @@ -821,8 +821,8 @@ class PagedAttentionKVCacheObj : public AttentionKVCacheObj { /************** Attention **************/ - void BeginForward(const IntTuple& seq_ids, const IntTuple& append_lengths, - const Optional& opt_token_tree_parent_ptr) final { + void BeginForward(const ffi::Shape& seq_ids, const ffi::Shape& append_lengths, + const Optional& opt_token_tree_parent_ptr) final { // Note: MLA does not supported tree attention for now. if (attn_kinds_[0] == AttnKind::kMLA) { CHECK(!opt_token_tree_parent_ptr.defined()) << "Tree attention is not supported yet for MLA"; @@ -1101,11 +1101,11 @@ class PagedAttentionKVCacheObj : public AttentionKVCacheObj { } } - IntTuple DisaggPrepareRecv(int64_t seq_id, int append_length) final { + ffi::Shape DisaggPrepareRecv(int64_t seq_id, int append_length) final { // No CPU to GPU copy is needed. // Essentially we // (step 1.) redirect the preparation to BeginForward. - BeginForward({seq_id}, {append_length}, /*opt_token_tree_parent_ptr=*/NullOpt); + BeginForward({seq_id}, {append_length}, /*opt_token_tree_parent_ptr=*/std::nullopt); // (step 2.) fetch the append_position_map, compress and return. // Compression format: [n, begin_1, length_1, begin_2, length_2, ..., begin_n, length_n] // The compressed format will be decompressed to: @@ -1128,11 +1128,11 @@ class PagedAttentionKVCacheObj : public AttentionKVCacheObj { compressed_append_pos_map.back() + 1); // The compressed array size should be "num_segments * 2 + 1". CHECK_EQ(compressed_append_pos_map.size(), compressed_append_pos_map[0] * 2 + 1); - return IntTuple{compressed_append_pos_map}; + return ffi::Shape{compressed_append_pos_map}; } - void DisaggMarkSend(int64_t seq_id, int64_t begin, const IntTuple& compressed_remote_position_map, - int32_t recver_pe_offset) { + void DisaggMarkSend(int64_t seq_id, int64_t begin, + const ffi::Shape& compressed_remote_position_map, int32_t recver_pe_offset) { ICHECK(f_transfer_kv_.defined()); auto it = seq_map_.find(seq_id); CHECK(it != seq_map_.end()) << "The sequence \"" << seq_id << "\" cannot be found in KV cache."; @@ -1404,7 +1404,8 @@ class PagedAttentionKVCacheObj : public AttentionKVCacheObj { // Todo(ruihang): implement it } - void CommitAcceptedTokenTreeNodes(const IntTuple& seq_ids, const IntTuple& leaf_indices) final { + void CommitAcceptedTokenTreeNodes(const ffi::Shape& seq_ids, + const ffi::Shape& leaf_indices) final { CHECK_EQ(seq_ids.size(), leaf_indices.size()) << "The given seq_ids and leaf_indices have different size."; int num_seq_to_commit = seq_ids.size(); @@ -1631,7 +1632,7 @@ class PagedAttentionKVCacheObj : public AttentionKVCacheObj { } void ConstructTokenTreeMask(const std::vector& sequences, - const IntTuple& token_tree_parent_ptr, + const ffi::Shape& token_tree_parent_ptr, const std::vector>& block_ids_on_depths, const std::vector>& trailing_blocks) { // Check whether the token tree of a sequence should be handled at the current depth. @@ -2288,8 +2289,8 @@ TVM_REGISTER_GLOBAL("vm.builtin.paged_attention_kv_cache_create") // Todo: cuda graph arg CHECK(args.size() == 28 || args.size() == 29) << "Invalid number of KV cache constructor args: " << args.size(); - ShapeTuple cache_config = args[0].cast(); - ShapeTuple layer_indptr_tuple = args[1].cast(); + ffi::Shape cache_config = args[0].cast(); + ffi::Shape layer_indptr_tuple = args[1].cast(); int num_groups = 1; int group_id = 0; if (DiscoWorker* disco_worker = ThreadLocalDiscoWorker::Get()->worker) { @@ -2305,15 +2306,15 @@ TVM_REGISTER_GLOBAL("vm.builtin.paged_attention_kv_cache_create") int64_t num_kv_heads = args[3].cast(); int64_t qk_head_dim = args[4].cast(); int64_t v_head_dim = args[5].cast(); - IntTuple attn_kinds = args[6].cast(); + ffi::Shape attn_kinds = args[6].cast(); bool enable_kv_transfer = args[7].cast(); int rope_mode = args[8].cast(); double rotary_scale = args[9].cast(); double rotary_theta = args[10].cast(); - Optional rope_ext_factors = NullOpt; // args[11] + Optional rope_ext_factors = std::nullopt; // args[11] NDArray init = args[12].cast(); - Optional f_transpose_append_mha = NullOpt; // args[13] - Optional f_transpose_append_mla = NullOpt; // args[14] + Optional f_transpose_append_mha = std::nullopt; // args[13] + Optional f_transpose_append_mla = std::nullopt; // args[14] std::unique_ptr f_attention_prefill_ragged = ConvertRaggedPrefillFunc(args[15].cast>(), AttnKind::kMHA); std::unique_ptr f_attention_prefill = @@ -2343,7 +2344,7 @@ TVM_REGISTER_GLOBAL("vm.builtin.paged_attention_kv_cache_create") if (auto opt_func = args[arg_idx].as()) { return opt_func.value(); } - return NullOpt; + return std::nullopt; }; f_transpose_append_mha = f_convert_optional_packed_func(13); f_transpose_append_mla = f_convert_optional_packed_func(14); diff --git a/src/runtime/relax_vm/rnn_state.cc b/src/runtime/relax_vm/rnn_state.cc index 9468a50d2071..9f134dcace1d 100644 --- a/src/runtime/relax_vm/rnn_state.cc +++ b/src/runtime/relax_vm/rnn_state.cc @@ -103,9 +103,9 @@ class RNNStateImpObj : public RNNStateObj { /*! \brief The batch size of the current round of forwarding. */ int64_t cur_batch_size_; /*! \brief The append lengths of the sequences in the current round of forwarding. */ - IntTuple cur_append_lengths_; + ffi::Shape cur_append_lengths_; /*! \brief The sequence ids of the current round of forwarding. */ - IntTuple cur_seq_ids_; + ffi::Shape cur_seq_ids_; /**************** Auxiliary Arrays on Device *****************/ @@ -173,8 +173,8 @@ class RNNStateImpObj : public RNNStateObj { Array layer_storages; layer_storages.reserve(num_states_per_layer_); for (int64_t state_id = 0; state_id < num_states_per_layer_; ++state_id) { - ShapeTuple state_shape = init_layer_value[state_id].Shape(); - std::vector storage_shape = {reserved_num_seqs, max_history}; + ffi::Shape state_shape = init_layer_value[state_id].Shape(); + std::vector storage_shape = {reserved_num_seqs, max_history}; storage_shape.insert(storage_shape.end(), state_shape.begin(), state_shape.end()); NDArray state_storage = NDArray::Empty(storage_shape, init_layer_value[state_id].DataType(), device); @@ -205,14 +205,14 @@ class RNNStateImpObj : public RNNStateObj { /************** Interaction **************/ - void BeginForward(const IntTuple& seq_ids, const IntTuple& append_lengths, - const Optional& opt_token_tree_parent_ptr) final { + void BeginForward(const ffi::Shape& seq_ids, const ffi::Shape& append_lengths, + const Optional& opt_token_tree_parent_ptr) final { CHECK_EQ(seq_ids.size(), append_lengths.size()) << "The seq_ids size (" << seq_ids.size() << ") and append_lengths size (" << append_lengths.size() << ") mismatch."; if (opt_token_tree_parent_ptr.defined()) { - IntTuple token_tree_parent_ptr = opt_token_tree_parent_ptr.value(); + ffi::Shape token_tree_parent_ptr = opt_token_tree_parent_ptr.value(); int matched_pos = 0; for (int64_t append_length : append_lengths) { for (int64_t i = 0; i < append_length; ++i) { diff --git a/src/runtime/relax_vm/vm.cc b/src/runtime/relax_vm/vm.cc index c92509923b7e..67bb19fb9b55 100644 --- a/src/runtime/relax_vm/vm.cc +++ b/src/runtime/relax_vm/vm.cc @@ -605,7 +605,7 @@ Optional VirtualMachineImpl::GetClosureInternal(const String& func_na } auto it = exec_->func_map.find(func_name); if (it == exec_->func_map.end()) { - if (allow_missing) return NullOpt; + if (allow_missing) return std::nullopt; LOG(FATAL) << "ValueError: Unknown function: " << func_name; } diff --git a/src/runtime/rpc/rpc_module.cc b/src/runtime/rpc/rpc_module.cc index c50c92ee995a..ad42390dc666 100644 --- a/src/runtime/rpc/rpc_module.cc +++ b/src/runtime/rpc/rpc_module.cc @@ -21,7 +21,7 @@ * \file rpc_module.cc * \brief RPC runtime module. */ -#include +#include #include #include #include diff --git a/src/runtime/static_library.cc b/src/runtime/static_library.cc index 47633b326cba..2e469d6e956a 100644 --- a/src/runtime/static_library.cc +++ b/src/runtime/static_library.cc @@ -24,7 +24,7 @@ */ #include "./static_library.h" -#include +#include #include #include #include diff --git a/src/runtime/static_library.h b/src/runtime/static_library.h index 818e77ebd980..196d2448b93f 100644 --- a/src/runtime/static_library.h +++ b/src/runtime/static_library.h @@ -26,7 +26,7 @@ #ifndef TVM_RUNTIME_STATIC_LIBRARY_H_ #define TVM_RUNTIME_STATIC_LIBRARY_H_ -#include +#include #include #include diff --git a/src/runtime/system_library.cc b/src/runtime/system_library.cc index 30fca708b8e8..d3693c82564d 100644 --- a/src/runtime/system_library.cc +++ b/src/runtime/system_library.cc @@ -21,8 +21,8 @@ * \file system_library.cc * \brief Create library module that directly get symbol from the system lib. */ +#include #include -#include #include #include diff --git a/src/runtime/thread_pool.cc b/src/runtime/thread_pool.cc index 457f44799d7c..1e02d6a66154 100644 --- a/src/runtime/thread_pool.cc +++ b/src/runtime/thread_pool.cc @@ -22,9 +22,9 @@ * \brief Threadpool for multi-threading runtime. */ #include +#include #include #include -#include #include #include #include diff --git a/src/runtime/threading_backend.cc b/src/runtime/threading_backend.cc index 01c0f1603fa2..0bea0dac1b70 100644 --- a/src/runtime/threading_backend.cc +++ b/src/runtime/threading_backend.cc @@ -437,7 +437,7 @@ int MaxConcurrency() { // This global function can be used by disco runtime to bind processes // to CPUs. TVM_REGISTER_GLOBAL("tvm.runtime.threading.set_current_thread_affinity") - .set_body_typed([](IntTuple cpu_ids) { + .set_body_typed([](ffi::Shape cpu_ids) { SetThreadAffinity(CURRENT_THREAD_HANDLE, std::vector{cpu_ids.begin(), cpu_ids.end()}); }); diff --git a/src/script/ir_builder/base.cc b/src/script/ir_builder/base.cc index 51df91238954..2edc71cdb1b3 100644 --- a/src/script/ir_builder/base.cc +++ b/src/script/ir_builder/base.cc @@ -46,7 +46,7 @@ void IRBuilderFrameNode::AddCallback(ffi::TypedFunction callback) { IRBuilder::IRBuilder() { ObjectPtr n = make_object(); n->frames.clear(); - n->result = NullOpt; + n->result = std::nullopt; data_ = n; } @@ -60,7 +60,7 @@ void IRBuilder::EnterWithScope() { CHECK(n->frames.empty()) << "ValueError: There are frame(s) left in the builder: " << n->frames.size() << ". Please use a fresh new builder every time building IRs"; - n->result = NullOpt; + n->result = std::nullopt; std::vector* stack = ThreadLocalBuilderStack(); stack->push_back(*this); } diff --git a/src/script/ir_builder/ir/ir.cc b/src/script/ir_builder/ir/ir.cc index 2fb8da1e9f24..e5f8759aec8e 100644 --- a/src/script/ir_builder/ir/ir.cc +++ b/src/script/ir_builder/ir/ir.cc @@ -106,7 +106,7 @@ Optional ModuleGetAttr(const String& key) { return frame->attrs[key].cast(); } } - return NullOpt; + return std::nullopt; } void ModuleSetAttr(const String& key, const Optional& value, bool allow_override) { diff --git a/src/script/ir_builder/relax/ir.cc b/src/script/ir_builder/relax/ir.cc index ff0c301024bf..770a77f1a057 100644 --- a/src/script/ir_builder/relax/ir.cc +++ b/src/script/ir_builder/relax/ir.cc @@ -55,7 +55,7 @@ TVM_STATIC_IR_FUNCTOR(Namer, vtable) FunctionFrame Function(const Bool& is_pure, const Bool& is_private) { ObjectPtr n = make_object(); const IRBuilder& ir_builder = IRBuilder::Current(); - Optional mod = NullOpt; + Optional mod = std::nullopt; if (const Optional mod_frame = ir_builder->GetLastFrame()) { mod = tvm::IRModule(mod_frame.value()->functions); } @@ -254,8 +254,8 @@ TVM_REGISTER_GLOBAL("script.ir_builder.relax.SeqExpr").set_body_typed(SeqExpr); IfFrame If(tvm::relax::Expr condition) { ObjectPtr n = make_object(); n->condition = condition; - n->then_expr = NullOpt; - n->else_expr = NullOpt; + n->then_expr = std::nullopt; + n->else_expr = std::nullopt; return IfFrame(n); } diff --git a/src/script/ir_builder/tir/ir.cc b/src/script/ir_builder/tir/ir.cc index 1d99a1b85252..fe2e3d7d9780 100644 --- a/src/script/ir_builder/tir/ir.cc +++ b/src/script/ir_builder/tir/ir.cc @@ -57,10 +57,10 @@ Buffer BufferDecl(Array shape, DataType dtype, String buffer_name, Opt PrimFuncFrame PrimFunc(bool is_private) { ObjectPtr n = make_object(); - n->name = NullOpt; + n->name = std::nullopt; n->is_private = is_private; n->args.clear(); - n->ret_type = NullOpt; + n->ret_type = std::nullopt; n->buffer_map.clear(); n->attrs = {}; n->env_threads.clear(); @@ -157,14 +157,14 @@ BlockFrame Block(String name, bool no_realize) { ObjectPtr n = make_object(); n->name = name; n->iter_vars.clear(); - n->reads = NullOpt; - n->writes = NullOpt; - n->init = NullOpt; + n->reads = std::nullopt; + n->writes = std::nullopt; + n->init = std::nullopt; n->alloc_buffers.clear(); n->match_buffers.clear(); - n->annotations = NullOpt; + n->annotations = std::nullopt; n->iter_values.clear(); - n->predicate = NullOpt; + n->predicate = std::nullopt; n->no_realize = no_realize; return BlockFrame(n); } @@ -335,7 +335,7 @@ Array Remap(String kinds, Array bindings, DataType dtype) { n->f_make_for_loop = [annotations](Array vars, Array doms, tvm::tir::Stmt body) { \ ICHECK_EQ(vars.size(), 1); \ ICHECK_EQ(doms.size(), 1); \ - return tvm::tir::For(vars[0], doms[0]->min, doms[0]->extent, Kind, body, NullOpt, \ + return tvm::tir::For(vars[0], doms[0]->min, doms[0]->extent, Kind, body, std::nullopt, \ annotations.value_or(Map())); \ }; \ return ForFrame(n); \ @@ -386,7 +386,7 @@ ForFrame Grid(Array extents) { Range dom = doms[i]; Var var = vars[i]; body = For(var, dom->min, dom->extent, ForKind::kSerial, std::move(body), - /*thread_binding=*/NullOpt, /*annotations=*/{}); + /*thread_binding=*/std::nullopt, /*annotations=*/{}); } return body; }; @@ -504,8 +504,8 @@ WhileFrame While(PrimExpr condition) { IfFrame If(PrimExpr condition) { ObjectPtr n = make_object(); n->condition = condition; - n->then_stmts = NullOpt; - n->else_stmts = NullOpt; + n->then_stmts = std::nullopt; + n->else_stmts = std::nullopt; return IfFrame(n); } @@ -531,7 +531,7 @@ Var EnvThread(String thread_tag, DataType dtype) { } void BufferStore(Buffer buffer, PrimExpr value, Array indices, - Optional predicate = NullOpt) { + Optional predicate = std::nullopt) { runtime::DataType buffer_dtype = buffer->dtype; bool is_index_scalable = indices.empty() ? false : indices.back().dtype().is_scalable_vector(); bool is_buffer_dtype_scalable = buffer_dtype.is_scalable_vector(); diff --git a/src/script/printer/doc.cc b/src/script/printer/doc.cc index 615032ea0036..89f517fc44ea 100644 --- a/src/script/printer/doc.cc +++ b/src/script/printer/doc.cc @@ -16,7 +16,7 @@ * specific language governing permissions and limitations * under the License. */ -#include +#include #include #include #include @@ -177,7 +177,7 @@ ScopeDoc::ScopeDoc(Optional lhs, ExprDoc rhs, Array body) { ScopeDoc::ScopeDoc(ExprDoc rhs, Array body) { ObjectPtr n = make_object(); - n->lhs = NullOpt; + n->lhs = std::nullopt; n->rhs = rhs; n->body = body; this->data_ = std::move(n); @@ -354,7 +354,7 @@ TVM_REGISTER_GLOBAL("script.printer.ExprStmtDoc").set_body_typed([](ExprDoc expr TVM_REGISTER_NODE_TYPE(AssertDocNode); TVM_REGISTER_GLOBAL("script.printer.AssertDoc") - .set_body_typed([](ExprDoc test, Optional msg = NullOpt) { + .set_body_typed([](ExprDoc test, Optional msg = std::nullopt) { return AssertDoc(test, msg); }); diff --git a/src/script/printer/ir/distributed.cc b/src/script/printer/ir/distributed.cc index 29e45bc5c598..194c8f52b1aa 100644 --- a/src/script/printer/ir/distributed.cc +++ b/src/script/printer/ir/distributed.cc @@ -26,16 +26,15 @@ namespace script { namespace printer { TVM_STATIC_IR_FUNCTOR(IRDocsifier, vtable) - .set_dispatch( - "", [](runtime::ShapeTuple n, ObjectPath n_p, IRDocsifier d) -> Doc { - int s = n.size(); - Array results; - results.reserve(s); - for (int i = 0; i < s; ++i) { - results.push_back(d->AsDoc(Integer(n[i]), n_p->ArrayIndex(i))); - } - return TupleDoc(results); - }); + .set_dispatch("", [](ffi::Shape n, ObjectPath n_p, IRDocsifier d) -> Doc { + int s = n.size(); + Array results; + results.reserve(s); + for (int i = 0; i < s; ++i) { + results.push_back(d->AsDoc(Integer(n[i]), n_p->ArrayIndex(i))); + } + return TupleDoc(results); + }); } // namespace printer } // namespace script diff --git a/src/script/printer/ir/ir.cc b/src/script/printer/ir/ir.cc index 7187c2d512a4..c8f029d225a8 100644 --- a/src/script/printer/ir/ir.cc +++ b/src/script/printer/ir/ir.cc @@ -100,7 +100,7 @@ TVM_STATIC_IR_FUNCTOR(IRDocsifier, vtable) (*f)->stmts.push_back(func.value()); } else if (auto expr = doc.as()) { ExprDoc lhs = IdDoc(gv->name_hint); - AssignDoc assignment(lhs, expr.value(), NullOpt); + AssignDoc assignment(lhs, expr.value(), std::nullopt); (*f)->stmts.push_back(assignment); } else { LOG(FATAL) << "TypeError: " diff --git a/src/script/printer/ir/misc.cc b/src/script/printer/ir/misc.cc index 05d70ea4dab4..caa5cbe895bd 100644 --- a/src/script/printer/ir/misc.cc +++ b/src/script/printer/ir/misc.cc @@ -49,7 +49,7 @@ TVM_STATIC_IR_FUNCTOR(IRDocsifier, vtable) std::vector items{dict.begin(), dict.end()}; bool is_str_map = true; for (const auto& kv : items) { - if (!kv.first.as()) { + if (!kv.first.as()) { is_str_map = false; break; } diff --git a/src/script/printer/ir_docsifier.cc b/src/script/printer/ir_docsifier.cc index f74e08848920..15762705b418 100644 --- a/src/script/printer/ir_docsifier.cc +++ b/src/script/printer/ir_docsifier.cc @@ -16,7 +16,6 @@ * specific language governing permissions and limitations * under the License. */ -#include #include #include #include @@ -62,14 +61,14 @@ IdDoc IRDocsifierNode::Define(const ObjectRef& obj, const Frame& frame, const St void IRDocsifierNode::Define(const ObjectRef& obj, const Frame& frame, DocCreator doc_factory) { ICHECK(obj2info.find(obj) == obj2info.end()) << "Duplicated object: " << obj; - obj2info.insert({obj, VariableInfo{std::move(doc_factory), NullOpt}}); + obj2info.insert({obj, VariableInfo{std::move(doc_factory), std::nullopt}}); frame->AddExitCallback([this, obj]() { this->RemoveVar(obj); }); } Optional IRDocsifierNode::GetVarDoc(const ObjectRef& obj) const { auto it = obj2info.find(obj); if (it == obj2info.end()) { - return NullOpt; + return std::nullopt; } return it->second.creator(); } @@ -82,7 +81,8 @@ ExprDoc IRDocsifierNode::AddMetadata(const ObjectRef& obj) { if (index == static_cast(array.size())) { array.push_back(obj); } - return IdDoc("metadata")[{LiteralDoc::Str(key, NullOpt)}][{LiteralDoc::Int(index, NullOpt)}]; + return IdDoc( + "metadata")[{LiteralDoc::Str(key, std::nullopt)}][{LiteralDoc::Int(index, std::nullopt)}]; } void IRDocsifierNode::AddGlobalInfo(const String& name, const GlobalInfo& ginfo) { @@ -138,13 +138,13 @@ void IRDocsifierNode::SetCommonPrefix(const ObjectRef& root, } visited_.insert(obj); stack_.push_back(obj); - if (obj->IsInstance()) { - const ArrayObj* array = static_cast(obj); + if (obj->IsInstance()) { + const ffi::ArrayObj* array = static_cast(obj); for (Any element : *array) { this->RecursiveVisitAny(&element); } - } else if (obj->IsInstance()) { - const MapObj* map = static_cast(obj); + } else if (obj->IsInstance()) { + const ffi::MapObj* map = static_cast(obj); for (std::pair kv : *map) { this->RecursiveVisitAny(&kv.first); this->RecursiveVisitAny(&kv.second); diff --git a/src/script/printer/legacy_repr.cc b/src/script/printer/legacy_repr.cc index 27301482ccc4..5e414e90c262 100644 --- a/src/script/printer/legacy_repr.cc +++ b/src/script/printer/legacy_repr.cc @@ -75,8 +75,8 @@ ReprLegacyPrinter& operator<<(ReprLegacyPrinter& out, tir::ForKind type) { // N } TVM_STATIC_IR_FUNCTOR(ReprLegacyPrinter, vtable) - .set_dispatch([](const ObjectRef& node, ReprLegacyPrinter* p) { - auto* op = static_cast(node.get()); + .set_dispatch([](const ObjectRef& node, ReprLegacyPrinter* p) { + auto* op = static_cast(node.get()); (*p) << '['; for (size_t i = 0; i < op->size(); ++i) { if (i != 0) { @@ -88,8 +88,8 @@ TVM_STATIC_IR_FUNCTOR(ReprLegacyPrinter, vtable) }); TVM_STATIC_IR_FUNCTOR(ReprLegacyPrinter, vtable) - .set_dispatch([](const ObjectRef& node, ReprLegacyPrinter* p) { - auto* op = static_cast(node.get()); + .set_dispatch([](const ObjectRef& node, ReprLegacyPrinter* p) { + auto* op = static_cast(node.get()); (*p) << '{'; for (auto it = op->begin(); it != op->end(); ++it) { if (it != op->begin()) { @@ -107,8 +107,8 @@ TVM_STATIC_IR_FUNCTOR(ReprLegacyPrinter, vtable) }); TVM_STATIC_IR_FUNCTOR(ReprLegacyPrinter, vtable) - .set_dispatch([](const ObjectRef& node, ReprLegacyPrinter* p) { - auto* op = static_cast(node.get()); + .set_dispatch([](const ObjectRef& node, ReprLegacyPrinter* p) { + auto* op = static_cast(node.get()); (*p) << '['; for (size_t i = 0; i < op->size; ++i) { if (i != 0) { diff --git a/src/script/printer/relax/binding.cc b/src/script/printer/relax/binding.cc index c8b616b4bcb5..22baf1c21c74 100644 --- a/src/script/printer/relax/binding.cc +++ b/src/script/printer/relax/binding.cc @@ -44,7 +44,7 @@ TVM_STATIC_IR_FUNCTOR(IRDocsifier, vtable) "", [](relax::MatchCast n, ObjectPath n_p, IRDocsifier d) -> Doc { using relax::StructInfo; using relax::MatchStructInfo; - Optional ann = NullOpt; + Optional ann = std::nullopt; if (d->cfg->show_all_struct_info) { ann = StructInfoAsAnn(n->var, n_p->Attr("var"), d, n->value); } @@ -83,7 +83,7 @@ TVM_STATIC_IR_FUNCTOR(IRDocsifier, vtable) TVM_STATIC_IR_FUNCTOR(IRDocsifier, vtable) .set_dispatch("", [](relax::If n, ObjectPath n_p, IRDocsifier d) -> Doc { - return PrintIfExpr(n, n_p, d, NullOpt, NullOpt); + return PrintIfExpr(n, n_p, d, std::nullopt, std::nullopt); }); TVM_SCRIPT_REPR(relax::MatchCastNode, ReprPrintRelax); diff --git a/src/script/printer/relax/call.cc b/src/script/printer/relax/call.cc index bd259609127f..82c2083044ec 100644 --- a/src/script/printer/relax/call.cc +++ b/src/script/printer/relax/call.cc @@ -122,7 +122,7 @@ Optional PrintCallTIRDPSPacked(const relax::Call& n, const ObjectPath& if (!n->op.same_as(call_tir_op) && !n->op.same_as(call_dps_packed_op) && !n->op.same_as(call_tir_with_grad_op) && !n->op.same_as(call_tir_local_view) && !n->op.same_as(call_tir_inplace_op)) { - return NullOpt; + return std::nullopt; } ICHECK(n->args.size() == 2 || n->args.size() == 3); ICHECK(n->sinfo_args.size() == 1); @@ -206,7 +206,7 @@ Optional PrintCallTIRDPSPacked(const relax::Call& n, const ObjectPath& Optional PrintAssertOp(const relax::Call& n, const ObjectPath& n_p, const IRDocsifier& d) { static const Op& assert_op = Op::Get("relax.assert_op"); if (!n->op.same_as(assert_op)) { - return NullOpt; + return std::nullopt; } ICHECK(n->args.size() >= 2); // special handling: it is important to indicate that the format string (second argument) @@ -226,7 +226,7 @@ Optional PrintHintOnDevice(const relax::Call& n, const ObjectPath& n_p, const IRDocsifier& d) { static const Op& hint_on_device_op = Op::Get("relax.hint_on_device"); if (!n->op.same_as(hint_on_device_op)) { - return NullOpt; + return std::nullopt; } Array args; @@ -246,7 +246,7 @@ Optional PrintToVDevice(const relax::Call& n, const ObjectPath& n_p, const IRDocsifier& d) { static const Op& to_vdevice_op = Op::Get("relax.to_vdevice"); if (!n->op.same_as(to_vdevice_op)) { - return NullOpt; + return std::nullopt; } Array args; @@ -269,7 +269,7 @@ Optional PrintRelaxPrint(const relax::Call& n, const ObjectPath& n_p, const IRDocsifier& d) { static const Op& print_op = Op::Get("relax.print"); if (!n->op.same_as(print_op)) { - return NullOpt; + return std::nullopt; } ICHECK(n->args.size() >= 1); // special handling: it is important to indicate that the format string (first argument) diff --git a/src/script/printer/relax/expr.cc b/src/script/printer/relax/expr.cc index f6cbde0b4b23..808177b15020 100644 --- a/src/script/printer/relax/expr.cc +++ b/src/script/printer/relax/expr.cc @@ -83,7 +83,7 @@ Optional SpecialScalar(const runtime::NDArray& n, const ObjectPath& p) DataType dtype = n.DataType(); const void* data = n->data; if (n->ndim != 0 || n->device.device_type != kDLCPU) { - return NullOpt; + return std::nullopt; } if (dtype == DataType::Int(8)) { @@ -128,7 +128,7 @@ Optional SpecialScalar(const runtime::NDArray& n, const ObjectPath& p) } else if (dtype == DataType::Bool()) { return LiteralDoc::Boolean(*reinterpret_cast(data), p); } else { - return NullOpt; + return std::nullopt; } } @@ -154,7 +154,7 @@ Doc PrintRelaxVar(relax::Var n, ObjectPath p, IRDocsifier d) { ExprDoc ann = d->AsDoc(n->struct_info_, p->Attr("struct_info_")); Frame f = d->frames.back(); ExprDoc var = DefineVar(n, f, d); - f->stmts.push_back(AssignDoc(var, NullOpt, ann)); + f->stmts.push_back(AssignDoc(var, std::nullopt, ann)); } return d->GetVarDoc(n).value(); } diff --git a/src/script/printer/relax/function.cc b/src/script/printer/relax/function.cc index 655e03d3b2f5..99e30ab520a5 100644 --- a/src/script/printer/relax/function.cc +++ b/src/script/printer/relax/function.cc @@ -56,7 +56,7 @@ TVM_STATIC_IR_FUNCTOR(IRDocsifier, vtable) (*f)->is_func = true; (*f)->func_vars = &func_vars; // Step 1. Print the return type - Optional ret_type = NullOpt; + Optional ret_type = std::nullopt; if (const auto& func_sinfo = relax::MatchStructInfo(n)) { ret_type = d->AsDoc(func_sinfo.value()->ret, // n_p->Attr("struct_info_")->Attr("ret")); @@ -68,7 +68,8 @@ TVM_STATIC_IR_FUNCTOR(IRDocsifier, vtable) for (int i = 0, l = n->params.size(); i < l; ++i) { params.push_back(AssignDoc( /*lhs=*/DefineVar(n->params[i], *f, d), - /*rhs=*/NullOpt, StructInfoAsAnn(n->params[i], params_p->ArrayIndex(i), d, NullOpt))); + /*rhs=*/std::nullopt, + StructInfoAsAnn(n->params[i], params_p->ArrayIndex(i), d, std::nullopt))); } } // Step 3. Clean up func variables diff --git a/src/script/printer/relax/region.cc b/src/script/printer/relax/region.cc index 1ac0b5ba14df..c0010034e436 100644 --- a/src/script/printer/relax/region.cc +++ b/src/script/printer/relax/region.cc @@ -88,7 +88,7 @@ TVM_STATIC_IR_FUNCTOR(IRDocsifier, vtable) Array non_dataflow_vars; Array stmts = PrintBindingBlock(n, n_p, d, &non_dataflow_vars); stmts.push_back(ExprStmtDoc(Relax(d, "output")->Call(non_dataflow_vars))); - return ScopeDoc(NullOpt, Relax(d, "dataflow")->Call({}), stmts); + return ScopeDoc(std::nullopt, Relax(d, "dataflow")->Call({}), stmts); }); TVM_SCRIPT_REPR(relax::SeqExprNode, ReprPrintRelax); diff --git a/src/script/printer/relax/tir.cc b/src/script/printer/relax/tir.cc index 2ae5663385f3..eafd67365dad 100644 --- a/src/script/printer/relax/tir.cc +++ b/src/script/printer/relax/tir.cc @@ -60,7 +60,7 @@ Doc PrintTIRVar(tir::Var n, ObjectPath n_p, IRDocsifier d) { } IdDoc var = d->Define(n, GetRef(f), n->name_hint.empty() ? "v" : n->name_hint); var->source_paths.push_back(n_p); - f->stmts.push_back(AssignDoc(var, PrintVarCreation(n, n_p, d), NullOpt)); + f->stmts.push_back(AssignDoc(var, PrintVarCreation(n, n_p, d), std::nullopt)); } if (Optional doc = d->GetVarDoc(n)) { return doc.value(); @@ -110,7 +110,7 @@ TVM_STATIC_IR_FUNCTOR(IRDocsifier, vtable) "under relax's dispatch token"; if (!f->module_alias_printed) { // If the module_alias is not defined before, define it. - f->stmts.push_back(AssignDoc(IdDoc(d->cfg->module_alias), doc.value(), NullOpt)); + f->stmts.push_back(AssignDoc(IdDoc(d->cfg->module_alias), doc.value(), std::nullopt)); f->module_alias_printed = true; } return IdDoc(d->cfg->module_alias); diff --git a/src/script/printer/relax/utils.h b/src/script/printer/relax/utils.h index 989e9a63b1d9..e28fd9c8036b 100644 --- a/src/script/printer/relax/utils.h +++ b/src/script/printer/relax/utils.h @@ -82,7 +82,7 @@ inline IdDoc DefineVar(const relax::Var& var, const Frame& frame, const IRDocsif inline Optional StructInfoAsAnn(const relax::Var& v, const ObjectPath& v_p, const IRDocsifier& d, const Optional& rhs) { if (!v->struct_info_.defined()) { - return NullOpt; + return std::nullopt; } bool attempt_to_hide_struct_info = !d->cfg->show_all_struct_info; @@ -94,7 +94,7 @@ inline Optional StructInfoAsAnn(const relax::Var& v, const ObjectPath& } } if (attempt_to_hide_struct_info) { - Optional inferred_sinfo = NullOpt; + Optional inferred_sinfo = std::nullopt; if (auto opt = rhs.as()) { auto call = opt.value(); if (auto opt = call->op.as()) { @@ -103,10 +103,10 @@ inline Optional StructInfoAsAnn(const relax::Var& v, const ObjectPath& static auto op_map_infer_struct_info = Op::GetAttrMap("FInferStructInfo"); - auto temp_builder = relax::BlockBuilder::Create(NullOpt); + auto temp_builder = relax::BlockBuilder::Create(std::nullopt); inferred_sinfo = op_map_infer_struct_info[op](call, temp_builder); } else if (auto opt = call->op.as()) { - auto temp_builder = relax::BlockBuilder::Create(NullOpt); + auto temp_builder = relax::BlockBuilder::Create(std::nullopt); inferred_sinfo = DeriveCallRetStructInfo(opt.value(), call, temp_builder, temp_builder->GetAnalyzer()); } @@ -125,7 +125,7 @@ inline Optional StructInfoAsAnn(const relax::Var& v, const ObjectPath& } if (inferred_sinfo && StructuralEqual()(inferred_sinfo, v->struct_info_)) { - return NullOpt; + return std::nullopt; } } return d->AsDoc(v->struct_info_, v_p->Attr("struct_info_")); diff --git a/src/script/printer/tir/block.cc b/src/script/printer/tir/block.cc index 178ed4fe75fa..519bc9d66ca6 100644 --- a/src/script/printer/tir/block.cc +++ b/src/script/printer/tir/block.cc @@ -99,7 +99,7 @@ Doc PrintBlock(IRDocsifier d, tir::Block block, ObjectPath block_p, // } else { rhs = rhs->Call({dom}); } - (*frame)->stmts.push_back(AssignDoc(DefineVar(iter_var->var, *frame, d), rhs, NullOpt)); + (*frame)->stmts.push_back(AssignDoc(DefineVar(iter_var->var, *frame, d), rhs, std::nullopt)); }; auto print_remapped_iter_var = [&]() { @@ -129,10 +129,10 @@ Doc PrintBlock(IRDocsifier d, tir::Block block, ObjectPath block_p, // binding_type += iter_var->iter_type == tir::IterVarType::kDataPar ? "S" : "R"; } ExprDoc rhs = TIR(d, "axis")->Attr("remap"); - ExprDoc binding_str = LiteralDoc::Str(binding_type, NullOpt); + ExprDoc binding_str = LiteralDoc::Str(binding_type, std::nullopt); binding_str->source_paths = std::move(binding_paths); rhs = rhs->Call({binding_str, ListDoc(loop_var_doc)}); - (*frame)->stmts.push_back(AssignDoc(TupleDoc(lhs), rhs, NullOpt)); + (*frame)->stmts.push_back(AssignDoc(TupleDoc(lhs), rhs, std::nullopt)); remap_vars_indices.clear(); } }; @@ -182,7 +182,7 @@ Doc PrintBlock(IRDocsifier d, tir::Block block, ObjectPath block_p, // IdDoc lhs = DefineBuffer(buffer, *frame, d); ExprDoc rhs = BufferDecl(buffer, "alloc_buffer", {}, buffer_p, *frame, d, BufferVarDefinition::DataPointer); - (*frame)->stmts.push_back(AssignDoc(lhs, rhs, NullOpt)); + (*frame)->stmts.push_back(AssignDoc(lhs, rhs, std::nullopt)); } // Step 6. Handle `match_buffer` for (int i = 0, n = block->match_buffers.size(); i < n; ++i) { @@ -196,7 +196,8 @@ Doc PrintBlock(IRDocsifier d, tir::Block block, ObjectPath block_p, // tir::Stmt init = block->init.value(); With init_frame(d, init); AsDocBody(init, block_p->Attr("init"), init_frame->get(), d); - (*frame)->stmts.push_back(ScopeDoc(NullOpt, TIR(d, "init")->Call({}), (*init_frame)->stmts)); + (*frame)->stmts.push_back( + ScopeDoc(std::nullopt, TIR(d, "init")->Call({}), (*init_frame)->stmts)); } // Step 8. Handle block body AsDocBody(block->body, block_p->Attr("body"), frame->get(), d); @@ -204,9 +205,9 @@ Doc PrintBlock(IRDocsifier d, tir::Block block, ObjectPath block_p, // Array kwargs_values; if (!realize) { kwargs_keys.push_back("no_realize"); - kwargs_values.push_back(LiteralDoc::Boolean(true, NullOpt)); + kwargs_values.push_back(LiteralDoc::Boolean(true, std::nullopt)); } - return ScopeDoc(NullOpt, + return ScopeDoc(std::nullopt, TIR(d, "block") // ->Call({LiteralDoc::Str(block->name_hint, block_p->Attr("name_hint"))}, kwargs_keys, kwargs_values), @@ -225,7 +226,7 @@ TVM_STATIC_IR_FUNCTOR(IRDocsifier, vtable) TVM_STATIC_IR_FUNCTOR(IRDocsifier, vtable) .set_dispatch("", [](tir::Block block, ObjectPath p, IRDocsifier d) -> Doc { - return PrintBlock(d, block, p, NullOpt, NullOpt); + return PrintBlock(d, block, p, std::nullopt, std::nullopt); }); TVM_SCRIPT_REPR(tir::BlockNode, ReprPrintTIR); diff --git a/src/script/printer/tir/buffer.cc b/src/script/printer/tir/buffer.cc index 18c7afe50454..0427c359049b 100644 --- a/src/script/printer/tir/buffer.cc +++ b/src/script/printer/tir/buffer.cc @@ -119,7 +119,7 @@ Map BufferAttrs(tir::Buffer buffer, const ObjectPath& buffer_p, if (is_new_var(e)) { if (try_inline_def(e, e_p, [=]() { return d->AsDoc(buffer, buffer_p) - ->Attr("strides")[{LiteralDoc::Int(i, NullOpt)}]; + ->Attr("strides")[{LiteralDoc::Int(i, std::nullopt)}]; })) { results.push_back(LiteralDoc::Str(Downcast(e)->name_hint, e_p)); continue; @@ -175,9 +175,9 @@ Map BufferAttrs(tir::Buffer buffer, const ObjectPath& buffer_p, d->AsDoc(buffer->axis_separators, buffer_p->Attr("axis_separators"))); } if (var_def_lhs.size() == 1) { - frame->stmts.push_back(AssignDoc(var_def_lhs[0], var_def_rhs[0], NullOpt)); + frame->stmts.push_back(AssignDoc(var_def_lhs[0], var_def_rhs[0], std::nullopt)); } else if (var_def_lhs.size() > 1) { - frame->stmts.push_back(AssignDoc(TupleDoc(var_def_lhs), TupleDoc(var_def_rhs), NullOpt)); + frame->stmts.push_back(AssignDoc(TupleDoc(var_def_lhs), TupleDoc(var_def_rhs), std::nullopt)); } return kwargs; } @@ -231,7 +231,7 @@ Array BufferIndices(const Array& indices, const ObjectPath& p, ramp_p->Attr("base")); ExprDoc stop = d->AsDoc(ramp->base + ramp->lanes * ramp->stride, // ramp_p->Attr("lanes")); - Optional step = NullOpt; + Optional step = std::nullopt; if (stride->value != 1) { step = d->AsDoc(ramp->stride, ramp_p->Attr("stride")); } @@ -256,7 +256,7 @@ Array BufferSlices(const Array& region, const ObjectPath& p, const I indices.push_back(min); } else { ExprDoc max = d->AsDoc(range->min + range->extent, range_p->Attr("extent")); - indices.push_back(SliceDoc(min, max, NullOpt)); + indices.push_back(SliceDoc(min, max, std::nullopt)); } } return indices; @@ -285,7 +285,7 @@ TVM_STATIC_IR_FUNCTOR(IRDocsifier, vtable) return AssignDoc( /*lhs=*/buffer[BufferIndices(store->indices, p->Attr("indices"), d)], - /*rhs=*/value, NullOpt); + /*rhs=*/value, std::nullopt); }); TVM_STATIC_IR_FUNCTOR(IRDocsifier, vtable) @@ -310,7 +310,7 @@ TVM_STATIC_IR_FUNCTOR(IRDocsifier, vtable) // ExprDoc lhs = DefineBuffer(buffer, opt_f.value(), d); ExprDoc rhs = BufferDecl(buffer, "Buffer", {}, p, opt_f.value(), d, BufferVarDefinition::DataPointer); - opt_f.value()->stmts.push_back(AssignDoc(lhs, rhs, NullOpt)); + opt_f.value()->stmts.push_back(AssignDoc(lhs, rhs, std::nullopt)); } } if (Optional doc = d->GetVarDoc(buffer)) { @@ -328,7 +328,7 @@ TVM_STATIC_IR_FUNCTOR(IRDocsifier, vtable) ExprDoc src_buffer = d->AsDoc(stmt->source, p->Attr("source")); ExprDoc rhs = BufferDecl(stmt->buffer, "match_buffer", {src_buffer}, p->Attr("buffer"), d->frames.back(), d, BufferVarDefinition::MatchBuffer); - return AssignDoc(lhs, rhs, NullOpt); + return AssignDoc(lhs, rhs, std::nullopt); }); TVM_STATIC_IR_FUNCTOR(IRDocsifier, vtable) @@ -343,7 +343,7 @@ TVM_STATIC_IR_FUNCTOR(IRDocsifier, vtable) "", [](tir::ProducerStore store, ObjectPath p, IRDocsifier d) -> Doc { ExprDoc prefix = IdDoc(store->producer->GetNameHint()); prefix = prefix[BufferIndices(store->indices, p->Attr("indices"), d)]; - return AssignDoc(prefix, d->AsDoc(store->value, p->Attr("value")), NullOpt); + return AssignDoc(prefix, d->AsDoc(store->value, p->Attr("value")), std::nullopt); }); TVM_STATIC_IR_FUNCTOR(IRDocsifier, vtable) @@ -355,7 +355,7 @@ TVM_STATIC_IR_FUNCTOR(IRDocsifier, vtable) ->Call({prefix, d->AsDoc(stmt->condition, p->Attr("condition"))}); With f(d, stmt); AsDocBody(stmt->body, p->Attr("body"), f->get(), d); - return ScopeDoc(NullOpt, prefix, (*f)->stmts); + return ScopeDoc(std::nullopt, prefix, (*f)->stmts); }); TVM_SCRIPT_REPR(tir::BufferRegionNode, ReprPrintTIR); diff --git a/src/script/printer/tir/expr.cc b/src/script/printer/tir/expr.cc index b81c8ef5af36..549247449e33 100644 --- a/src/script/printer/tir/expr.cc +++ b/src/script/printer/tir/expr.cc @@ -33,7 +33,7 @@ ExprDoc PrintVarCreation(const tir::Var& var, const ObjectPath& var_p, const IRD if (var->IsInstance()) { kwargs_keys.push_back("is_size_var"); - kwargs_values.push_back(LiteralDoc::Boolean(true, NullOpt)); + kwargs_values.push_back(LiteralDoc::Boolean(true, std::nullopt)); } if (const auto* ptr_type = type.as()) { @@ -65,7 +65,7 @@ Doc PrintVar(const tir::Var& var, const ObjectPath& var_p, const IRDocsifier& d) if (Optional opt_f = FindLowestVarDef(var, d)) { ExprDoc lhs = DefineVar(var, opt_f.value(), d); ExprDoc rhs = PrintVarCreation(var, var_p, d); - opt_f.value()->stmts.push_back(AssignDoc(lhs, rhs, NullOpt)); + opt_f.value()->stmts.push_back(AssignDoc(lhs, rhs, std::nullopt)); } else { LOG(WARNING) << "Didn't find variable definition for: " << var->name_hint; } diff --git a/src/script/printer/tir/for_loop.cc b/src/script/printer/tir/for_loop.cc index 107521c94791..0df53c481f0c 100644 --- a/src/script/printer/tir/for_loop.cc +++ b/src/script/printer/tir/for_loop.cc @@ -65,10 +65,10 @@ TVM_STATIC_IR_FUNCTOR(IRDocsifier, vtable) } // Step 3. If not `T.grid`, print loop kind accordingly ExprDoc lhs = DefineVar(loop->loop_var, *f, d); - Optional min = NullOpt; - Optional max = NullOpt; - Optional annotations = NullOpt; - Optional thread = NullOpt; + Optional min = std::nullopt; + Optional max = std::nullopt; + Optional annotations = std::nullopt; + Optional thread = std::nullopt; if (tir::is_zero(loop->min)) { max = d->AsDoc(loop->extent, loop_p->Attr("extent")); } else { diff --git a/src/script/printer/tir/function.cc b/src/script/printer/tir/function.cc index 61b1c54cf5dd..10f7bd74520b 100644 --- a/src/script/printer/tir/function.cc +++ b/src/script/printer/tir/function.cc @@ -95,13 +95,13 @@ TVM_STATIC_IR_FUNCTOR(IRDocsifier, vtable) ObjectPath buffer_p = p->Attr("buffer_map")->MapValue(var); IdDoc lhs = DefineBuffer(buffer, *f, d); ExprDoc annotation = BufferAttn(buffer, buffer_p, *f, d); - args.push_back(AssignDoc(lhs, NullOpt, annotation)); + args.push_back(AssignDoc(lhs, std::nullopt, annotation)); buffer_inlined.insert(buffer.get()); continue; } } ExprDoc a = d->AsDoc(var->type_annotation, var_p->Attr("type_annotation")); - args.push_back(AssignDoc(DefineVar(var, *f, d), NullOpt, a)); + args.push_back(AssignDoc(DefineVar(var, *f, d), std::nullopt, a)); } // Step 2. Handle `func->attrs` if (func->attrs.defined() && !func->attrs->dict.empty()) { @@ -138,7 +138,7 @@ TVM_STATIC_IR_FUNCTOR(IRDocsifier, vtable) ExprDoc lhs = DefineBuffer(buffer, *f, d); ExprDoc rhs = BufferDecl(buffer, "match_buffer", {param_doc}, buffer_p, *f, d, BufferVarDefinition::MatchBuffer); - (*f)->stmts.push_back(AssignDoc(lhs, rhs, NullOpt)); + (*f)->stmts.push_back(AssignDoc(lhs, rhs, std::nullopt)); } } // Step 4. Handle `func->body` @@ -159,7 +159,7 @@ TVM_STATIC_IR_FUNCTOR(IRDocsifier, vtable) } } } - return NullOpt; + return std::nullopt; }(); if (d->cfg->syntax_sugar && implicit_root_block) { tir::Block root_block = implicit_root_block.value(); @@ -172,13 +172,13 @@ TVM_STATIC_IR_FUNCTOR(IRDocsifier, vtable) IdDoc lhs = DefineBuffer(buffer, *f, d); ExprDoc rhs = BufferDecl(buffer, "alloc_buffer", {}, buffer_p, *f, d, BufferVarDefinition::DataPointer); - (*f)->stmts.push_back(AssignDoc(lhs, rhs, NullOpt)); + (*f)->stmts.push_back(AssignDoc(lhs, rhs, std::nullopt)); } AsDocBody(root_block->body, root_block_p->Attr("body"), f->get(), d); } else { AsDocBody(func->body, p->Attr("body"), f->get(), d); } - Optional ret_type = NullOpt; + Optional ret_type = std::nullopt; if (func->ret_type.defined()) { const auto* as_tuple = func->ret_type.as(); if (!as_tuple || as_tuple->fields.size()) { diff --git a/src/script/printer/tir/stmt.cc b/src/script/printer/tir/stmt.cc index b7ba456dc2b5..1d310c2a5a9f 100644 --- a/src/script/printer/tir/stmt.cc +++ b/src/script/printer/tir/stmt.cc @@ -27,7 +27,7 @@ Doc DoConciseScoping(const Optional& lhs, const ExprDoc& rhs, Arrayinsert(stmts->begin(), AssignDoc(lhs.value(), rhs, NullOpt)); + stmts->insert(stmts->begin(), AssignDoc(lhs.value(), rhs, std::nullopt)); } else { stmts->insert(stmts->begin(), ExprStmtDoc(rhs)); } @@ -66,14 +66,14 @@ bool IsAncestorOfAllVarUse(const tir::Stmt& node, const ObjectRef& var, const IR Optional FindReturnValue(const tir::Stmt& node) { auto eval = node.as(); - if (!eval) return NullOpt; + if (!eval) return std::nullopt; auto call = eval->value.as(); - if (!call) return NullOpt; + if (!call) return std::nullopt; - if (!call->op.same_as(tir::builtin::ret())) return NullOpt; + if (!call->op.same_as(tir::builtin::ret())) return std::nullopt; - if (call->args.size() != 1) return NullOpt; + if (call->args.size() != 1) return std::nullopt; return call->args[0]; } @@ -103,7 +103,7 @@ TVM_STATIC_IR_FUNCTOR(IRDocsifier, vtable) p->Attr("var")->Attr("type_annotation")); if (const auto* tuple_type = stmt->var->type_annotation.as()) { if (tuple_type->fields.empty()) { - type_doc = NullOpt; + type_doc = std::nullopt; } } // Step 2. RHS @@ -119,7 +119,7 @@ TVM_STATIC_IR_FUNCTOR(IRDocsifier, vtable) AsDocBody(stmt->body, p->Attr("body"), f->get(), d); // Step 4. Dispatch if (var_defined) { - return ScopeDoc(NullOpt, TIR(d, "LetStmt")->Call({rhs}, {"var"}, {lhs}), *stmts); + return ScopeDoc(std::nullopt, TIR(d, "LetStmt")->Call({rhs}, {"var"}, {lhs}), *stmts); } else if (concise) { stmts->insert(stmts->begin(), AssignDoc(lhs, rhs, type_doc)); return StmtBlockDoc(*stmts); @@ -143,7 +143,7 @@ TVM_STATIC_IR_FUNCTOR(IRDocsifier, vtable) stmts->insert(stmts->begin(), AssertDoc(cond, msg)); return StmtBlockDoc(*stmts); } - return ScopeDoc(NullOpt, TIR(d, "Assert")->Call({cond, msg}), (*f)->stmts); + return ScopeDoc(std::nullopt, TIR(d, "Assert")->Call({cond, msg}), (*f)->stmts); }); TVM_STATIC_IR_FUNCTOR(IRDocsifier, vtable) @@ -275,9 +275,9 @@ ExprDoc PrintNDArray(::tvm::runtime::NDArray arr) { runtime::DataType dtype = arr.DataType(); for (int i = 0; i < tot_dim; i++) { if (dtype.is_float()) { - result.push_back(LiteralDoc::Float(data_ptr[i], NullOpt)); + result.push_back(LiteralDoc::Float(data_ptr[i], std::nullopt)); } else { - result.push_back(LiteralDoc::Int(data_ptr[i], NullOpt)); + result.push_back(LiteralDoc::Int(data_ptr[i], std::nullopt)); } if (i == NUM_PRINT) { break; @@ -354,7 +354,7 @@ ExprDoc DocsifyBufferRealize(const tir::BufferRealizeNode* stmt, OptionalAsDoc(range->min, range_p->Attr("min")), d->AsDoc(range->min + range->extent, range_p->Attr("extent")), // - NullOpt)); + std::nullopt)); } buffer = buffer[bounds]; } @@ -379,7 +379,7 @@ void InsertEnvThread(const tir::IterVar& iter_var, const ObjectPath& iter_var_p, ->Call({LiteralDoc::Str(iter_var->thread_tag, // iter_var_p->Attr("thread_tag"))}); ExprDoc lhs = d->AsDoc(iter_var->var, iter_var_p->Attr("var")); - f->stmts.push_back(AssignDoc(lhs, rhs, NullOpt)); + f->stmts.push_back(AssignDoc(lhs, rhs, std::nullopt)); } ExprDoc DocsifyLaunchThread(const tir::AttrStmt& attr_stmt, const ObjectPath& attr_stmt_p, @@ -408,19 +408,19 @@ TVM_STATIC_IR_FUNCTOR(IRDocsifier, vtable) .set_dispatch( // "", [](tir::BufferRealize stmt, ObjectPath p, IRDocsifier d) -> Doc { bool concise = AllowConciseScoping(d, stmt); - ExprDoc rhs = DocsifyBufferRealize(stmt.get(), NullOpt, p, d); + ExprDoc rhs = DocsifyBufferRealize(stmt.get(), std::nullopt, p, d); With f(d, stmt); AsDocBody(stmt->body, p->Attr("body"), f->get(), d); - return DoConciseScoping(NullOpt, rhs, &(*f)->stmts, concise); + return DoConciseScoping(std::nullopt, rhs, &(*f)->stmts, concise); }); TVM_STATIC_IR_FUNCTOR(IRDocsifier, vtable) .set_dispatch( // "", [](tir::AttrStmt stmt, ObjectPath stmt_p, IRDocsifier d) -> Doc { bool concise = AllowConciseScoping(d, stmt); - Optional lhs = NullOpt; - Optional rhs = NullOpt; - Optional define_var = NullOpt; + Optional lhs = std::nullopt; + Optional rhs = std::nullopt; + Optional define_var = std::nullopt; tir::Stmt body = stmt->body; ObjectPath body_p = stmt_p->Attr("body"); if (stmt->attr_key == "realize_scope") { diff --git a/src/script/printer/tir/utils.h b/src/script/printer/tir/utils.h index 7bdba2b1c6d5..d1bc56d13960 100644 --- a/src/script/printer/tir/utils.h +++ b/src/script/printer/tir/utils.h @@ -139,7 +139,7 @@ inline void AsDocBody(const tir::Stmt& stmt, ObjectPath p, TIRFrameNode* f, cons */ inline Optional FindLowestVarDef(const ObjectRef& var, const IRDocsifier& d) { if (!d->common_prefix.count(var.get())) { - return NullOpt; + return std::nullopt; } int n_frames = d->frames.size(); std::unordered_map tir_to_frame; @@ -163,7 +163,7 @@ inline Optional FindLowestVarDef(const ObjectRef& var, const IRDocsifier& if (fallback_frame != nullptr) { return GetRef(fallback_frame); } - return NullOpt; + return std::nullopt; } /*! \brief Redirected method for the ReprPrinter */ diff --git a/src/script/printer/utils.h b/src/script/printer/utils.h index 9ca9e87c1f14..03341c4cd90f 100644 --- a/src/script/printer/utils.h +++ b/src/script/printer/utils.h @@ -40,7 +40,7 @@ namespace printer { inline void RedirectedReprPrinterMethod(const ObjectRef& obj, ReprPrinter* p) { try { - p->stream << TVMScriptPrinter::Script(obj, NullOpt); + p->stream << TVMScriptPrinter::Script(obj, std::nullopt); } catch (const tvm::Error& e) { if (ReprLegacyPrinter::CanDispatch(obj)) { LOG(WARNING) << "TVMScript printer falls back to the legacy ReprPrinter with the error:\n" @@ -148,7 +148,8 @@ inline bool HasMultipleLines(const std::string& str) { } inline Optional GetBindingName(const IRDocsifier& d) { - return d->cfg->binding_names.empty() ? Optional(NullOpt) : d->cfg->binding_names.back(); + return d->cfg->binding_names.empty() ? Optional(std::nullopt) + : d->cfg->binding_names.back(); } inline Optional FindFunctionName(const IRDocsifier& d, const BaseFunc& f) { @@ -158,7 +159,7 @@ inline Optional FindFunctionName(const IRDocsifier& d, const BaseFunc& f if (Optional sym = f->GetAttr(tvm::attr::kGlobalSymbol)) { return sym.value(); } - return NullOpt; + return std::nullopt; } inline String GenerateUniqueName(std::string name_hint, diff --git a/src/support/array.h b/src/support/array.h index 6fd30503f016..f49439aeb3ff 100644 --- a/src/support/array.h +++ b/src/support/array.h @@ -18,8 +18,8 @@ */ #ifndef TVM_SUPPORT_ARRAY_H_ #define TVM_SUPPORT_ARRAY_H_ +#include #include -#include #include #include @@ -70,7 +70,7 @@ inline bool ArrayWithSameContent(const std::vector& a, const std::vector } /*! - * \brief Convert a tvm::runtime::Array to std::vector + * \brief Convert a tvm::Array to std::vector * \tparam TSrc The type of elements in the source Array * \tparam TDst The type of elements in the result vector * \return The result vector @@ -79,7 +79,7 @@ template inline std::vector AsVector(const Array& vec); /*! - * \brief Convert a std::vector to tvm::runtime::Array + * \brief Convert a std::vector to tvm::Array * \tparam TSrc The type of elements in the source vector * \tparam TDst The type of elements in the result Array * \return The result Array @@ -88,7 +88,7 @@ template inline Array AsArray(const std::vector& vec); /*! - * \brief Convert a tvm::runtime::Array to std::list + * \brief Convert a tvm::Array to std::list * \tparam T The type of elements in the source array * \return The result list */ @@ -100,7 +100,7 @@ inline std::list AsList(const Array& array) { } /*! - * \brief Convert a std::list to tvm::runtime::Array + * \brief Convert a std::list to tvm::Array * \tparam T The type of elements in the source list * \return The result list */ @@ -116,10 +116,10 @@ inline Array AsArray(const std::list& list) { * \param shape The shape tuple * \return An array of the shape tuple */ -inline Array AsArray(const ShapeTuple& shape) { +inline Array AsArray(const ffi::Shape& shape) { Array result; result.reserve(shape->size); - for (ShapeTuple::index_type i : shape) { + for (ffi::Shape::index_type i : shape) { result.push_back(Integer(i)); } return result; diff --git a/src/support/ffi_testing.cc b/src/support/ffi_testing.cc index 4482272ced53..baf374065d05 100644 --- a/src/support/ffi_testing.cc +++ b/src/support/ffi_testing.cc @@ -21,9 +21,9 @@ * FFI registration code used for frontend testing purposes. * \file ffi_testing.cc */ +#include #include #include -#include #include #include #include diff --git a/src/support/utils.h b/src/support/utils.h index c855ae736ade..eb0d4b9a8827 100644 --- a/src/support/utils.h +++ b/src/support/utils.h @@ -32,7 +32,7 @@ #endif // __hexagon__ #endif // _WIN32 -#include +#include #include #include diff --git a/src/target/codegen.cc b/src/target/codegen.cc index d7db5cc8e9e2..a6b5b4b041c8 100644 --- a/src/target/codegen.cc +++ b/src/target/codegen.cc @@ -371,7 +371,7 @@ TVM_REGISTER_GLOBAL("runtime.ModuleImportsBlobName").set_body_typed([]() -> std: TVM_REGISTER_GLOBAL("runtime.ModulePackImportsToNDArray") .set_body_typed([](const runtime::Module& mod) { std::string buffer = PackImportsToBytes(mod); - ShapeTuple::index_type size = buffer.size(); + ffi::Shape::index_type size = buffer.size(); DLDataType uchar; uchar.code = kDLUInt; uchar.bits = 8; diff --git a/src/target/llvm/codegen_amdgpu.cc b/src/target/llvm/codegen_amdgpu.cc index a1cff52beb2a..35b5d1378423 100644 --- a/src/target/llvm/codegen_amdgpu.cc +++ b/src/target/llvm/codegen_amdgpu.cc @@ -273,13 +273,13 @@ runtime::Module BuildAMDGPU(IRModule mod, Target target) { #endif auto cg = std::make_unique(); - cg->Init("TVMAMDGPUModule", llvm_target.get(), NullOpt, false, false); + cg->Init("TVMAMDGPUModule", llvm_target.get(), std::nullopt, false, false); cg->AddFunctionsOrdered(mod->functions.begin(), mod->functions.end()); llvm::TargetMachine* tm = llvm_target->GetOrCreateTargetMachine(); auto fbitcode = tvm::ffi::Function::GetGlobalRequired("tvm_callback_rocm_bitcode_path"); - auto bitcode_files = fbitcode().cast>(); + auto bitcode_files = fbitcode().cast>(); for (auto& bitcode_path : bitcode_files) { std::unique_ptr mlib = llvm_instance.LoadIR(bitcode_path); diff --git a/src/target/llvm/codegen_hexagon.cc b/src/target/llvm/codegen_hexagon.cc index 22708c61178a..68bf973439f3 100644 --- a/src/target/llvm/codegen_hexagon.cc +++ b/src/target/llvm/codegen_hexagon.cc @@ -499,7 +499,7 @@ runtime::Module BuildHexagon(IRModule mod, Target target) { } } - cg->Init("TVMHexagonModule", llvm_target.get(), NullOpt, false, false); + cg->Init("TVMHexagonModule", llvm_target.get(), std::nullopt, false, false); cg->AddFunctionsOrdered(mod->functions.begin(), mod->functions.end()); if (entry_func.length() != 0) { cg->AddMainFunction(entry_func); diff --git a/src/target/llvm/codegen_llvm.h b/src/target/llvm/codegen_llvm.h index 530d1772df31..f7e4e819030e 100644 --- a/src/target/llvm/codegen_llvm.h +++ b/src/target/llvm/codegen_llvm.h @@ -117,7 +117,7 @@ class CodeGenLLVM : public ExprFunctor, * \param module_name The name of the module. * \param tm Target machine model * \param ctx The context. - * \param system_lib_prefix If the value is not NullOpt, insert system lib registration. + * \param system_lib_prefix If the value is not std::nullopt, insert system lib registration. * The value corresponds to the prefix of the system lib symbols. * \param dynamic_lookup Whether dynamically lookup runtime function * or use the runtime function table passed by caller. diff --git a/src/target/llvm/codegen_nvptx.cc b/src/target/llvm/codegen_nvptx.cc index fa035367408c..865b383cd334 100644 --- a/src/target/llvm/codegen_nvptx.cc +++ b/src/target/llvm/codegen_nvptx.cc @@ -324,7 +324,7 @@ runtime::Module BuildNVPTX(IRModule mod, Target target) { int compute_ver = GetCUDAComputeVersion(target); auto cg = std::make_unique(); - cg->Init("TVMPTXModule", llvm_target.get(), NullOpt, false, false); + cg->Init("TVMPTXModule", llvm_target.get(), std::nullopt, false, false); cg->AddFunctionsOrdered(mod->functions.begin(), mod->functions.end()); diff --git a/src/target/llvm/llvm_instance.cc b/src/target/llvm/llvm_instance.cc index b6191f5e854c..6efbb296d9aa 100644 --- a/src/target/llvm/llvm_instance.cc +++ b/src/target/llvm/llvm_instance.cc @@ -65,10 +65,10 @@ #else #include #endif -#include -#include -#include -#include +#include +#include +#include +#include #include #include #include diff --git a/src/target/llvm/llvm_instance.h b/src/target/llvm/llvm_instance.h index 36d15b3a7715..f2468a8ef99f 100644 --- a/src/target/llvm/llvm_instance.h +++ b/src/target/llvm/llvm_instance.h @@ -32,10 +32,10 @@ #endif #include #include +#include +#include +#include #include -#include -#include -#include #include #include diff --git a/src/target/llvm/llvm_module.cc b/src/target/llvm/llvm_module.cc index 396b02063b34..db8961de3010 100644 --- a/src/target/llvm/llvm_module.cc +++ b/src/target/llvm/llvm_module.cc @@ -53,9 +53,9 @@ #include #include #include +#include +#include #include -#include -#include #include #include #include diff --git a/src/target/llvm/llvm_module.h b/src/target/llvm/llvm_module.h index 716a0a6c7007..2070d7da3e0c 100644 --- a/src/target/llvm/llvm_module.h +++ b/src/target/llvm/llvm_module.h @@ -27,7 +27,7 @@ #ifdef TVM_LLVM_VERSION -#include +#include #include #include #include diff --git a/src/target/tag.cc b/src/target/tag.cc index 0f398d6e19b4..1099de85f2b4 100644 --- a/src/target/tag.cc +++ b/src/target/tag.cc @@ -47,7 +47,7 @@ TargetTagRegEntry& TargetTagRegEntry::RegisterOrGet(const String& target_tag_nam Optional TargetTag::Get(const String& target_tag_name) { const TargetTagRegEntry* reg = TargetTagRegistry::Global()->Get(target_tag_name); if (reg == nullptr) { - return NullOpt; + return std::nullopt; } return Target(reg->tag_->config); } diff --git a/src/target/target.cc b/src/target/target.cc index 7a29ca2ef537..c90244654a3d 100644 --- a/src/target/target.cc +++ b/src/target/target.cc @@ -76,7 +76,7 @@ class TargetInternal { static std::string Interpret(const std::string& str); static std::string Uninterpret(const std::string& str); static std::string StringifyAtomicType(const Any& obj); - static std::string StringifyArray(const ArrayObj& array); + static std::string StringifyArray(const ffi::ArrayObj& array); static constexpr char quote = '\''; static constexpr char escape = '\\'; @@ -394,7 +394,7 @@ Any TargetInternal::ParseType(const std::string& str, const TargetKindNode::Valu } else if (info.type_index == Target::ContainerType::RuntimeTypeIndex()) { // Parsing target return Target(TargetInternal::FromString(interp_str)); - } else if (info.type_index == ArrayObj::RuntimeTypeIndex()) { + } else if (info.type_index == ffi::ArrayObj::RuntimeTypeIndex()) { // Parsing array std::vector result; for (const std::string& substr : SplitString(interp_str, ',')) { @@ -428,9 +428,9 @@ Any TargetInternal::ParseType(const Any& obj, const TargetKindNode::ValueTypeInf return opt.value(); } else if (auto str = obj.as()) { return Target(TargetInternal::FromString(str.value())); - } else if (const auto* ptr = obj.as()) { + } else if (const auto* ptr = obj.as()) { for (const auto& kv : *ptr) { - if (!kv.first.as()) { + if (!kv.first.as()) { TVM_FFI_THROW(TypeError) << "Target object requires key of dict to be str, but get: " << kv.first.GetTypeKey(); } @@ -440,9 +440,9 @@ Any TargetInternal::ParseType(const Any& obj, const TargetKindNode::ValueTypeInf } TVM_FFI_THROW(TypeError) << "Expect type 'dict' or 'str' to construct Target, but get: " + obj.GetTypeKey(); - } else if (info.type_index == ArrayObj::RuntimeTypeIndex()) { + } else if (info.type_index == ffi::ArrayObj::RuntimeTypeIndex()) { // Parsing array - const auto* array = ObjTypeCheck(obj, "Array"); + const auto* array = ObjTypeCheck(obj, "Array"); std::vector result; for (const Any& e : *array) { try { @@ -453,9 +453,9 @@ Any TargetInternal::ParseType(const Any& obj, const TargetKindNode::ValueTypeInf } } return Array(result); - } else if (info.type_index == MapObj::RuntimeTypeIndex()) { + } else if (info.type_index == ffi::MapObj::RuntimeTypeIndex()) { // Parsing map - const auto* map = ObjTypeCheck(obj, "Map"); + const auto* map = ObjTypeCheck(obj, "Map"); std::unordered_map result; for (const auto& kv : *map) { Any key, val; @@ -502,7 +502,7 @@ std::string TargetInternal::StringifyAtomicType(const Any& obj) { TVM_FFI_UNREACHABLE(); } -std::string TargetInternal::StringifyArray(const ArrayObj& array) { +std::string TargetInternal::StringifyArray(const ffi::ArrayObj& array) { std::vector elements; for (const Any& item : array) { @@ -531,7 +531,7 @@ Optional TargetInternal::StringifyAttrsToRaw(const Map std::string value; // skip undefined attrs if (obj == nullptr) continue; - if (const auto* array = obj.as()) { + if (const auto* array = obj.as()) { value = String(StringifyArray(*array)); } else { value = StringifyAtomicType(obj); @@ -602,7 +602,7 @@ Target::Target(Target target, Target host) { Target::Target(TargetKind kind, Optional host, String tag, Array keys, Map attrs) { - auto data = runtime::make_object(); + auto data = ffi::make_object(); data->kind = std::move(kind); data->host = std::move(host); data->tag = std::move(tag); @@ -651,7 +651,7 @@ Optional TargetNode::GetHost() const { return this->host.as(); } Target Target::WithoutHost() const { if ((*this)->GetHost()) { auto output = make_object(*get()); - output->host = NullOpt; + output->host = std::nullopt; return Target(output); } else { return *this; @@ -891,7 +891,7 @@ ObjectPtr TargetInternal::FromConfig(Map config) { bool has_user_keys = config.count(kKeys); if (has_user_keys) { // user provided keys - if (const auto* cfg_keys = config[kKeys].as()) { + if (const auto* cfg_keys = config[kKeys].as()) { for (const Any& e : *cfg_keys) { if (auto key = e.as()) { keys.push_back(key.value()); @@ -926,7 +926,7 @@ ObjectPtr TargetInternal::FromConfig(Map config) { target->host = ffi::Function(ConstructorDispatcher)(config[kHost]).cast(); config.erase(kHost); } else { - target->host = NullOpt; + target->host = std::nullopt; } // parse attrs std::unordered_map attrs; diff --git a/src/target/target_kind.cc b/src/target/target_kind.cc index 2a8dad4162cf..ff84bbd665ec 100644 --- a/src/target/target_kind.cc +++ b/src/target/target_kind.cc @@ -90,7 +90,7 @@ const AttrRegistryMapContainerMap& TargetKind::GetAttrMapContainer( Optional TargetKind::Get(const String& target_kind_name) { const TargetKindRegEntry* reg = TargetKindRegistry::Global()->Get(target_kind_name); if (reg == nullptr) { - return NullOpt; + return std::nullopt; } return reg->kind_; } diff --git a/src/te/operation/create_primfunc.cc b/src/te/operation/create_primfunc.cc index d087f845cc0f..0355c8fd9b09 100644 --- a/src/te/operation/create_primfunc.cc +++ b/src/te/operation/create_primfunc.cc @@ -309,7 +309,7 @@ Map GenerateBlockAnnotations(const te::ComputeOp& compute_op, const String& key = pair.first; const Any& value = pair.second; // TensorIR will not allow Tensor data structure - if (value.as()) { + if (value.as()) { const auto array_value = Downcast>(value); annotations.Set(key, array_value.Map(mutate_attr)); } else { @@ -337,7 +337,7 @@ Stmt GenerateInitStmt(const Array& indices, const Array& buffe auto f_transform_and_remap = [&](const PrimExpr& e) { return Substitute(info->transformer(e), var_map); }; - Optional init = NullOpt; + Optional init = std::nullopt; Stmt body; int n_buffers = buffers.size(); Array init_stmts; @@ -521,7 +521,7 @@ Stmt GenerateStmtFromCompute(const te::ComputeOp& compute_op, CreateFuncInfo* in // for the leaf scope, we ensure at least one block var exists IterVar dummy(Range::FromMinExtent(0, 1), Var("vi", DataType::Int(32)), IterVarType::kDataPar); - cur_scope.AddBlockIter(NullOpt, dummy, 0); + cur_scope.AddBlockIter(std::nullopt, dummy, 0); } scopes.push_back(cur_scope); } @@ -569,7 +569,7 @@ Stmt GenerateStmtFromCompute(const te::ComputeOp& compute_op, CreateFuncInfo* in /*writes=*/{}, /*name_hint=*/info->FreshName(buffers[i]->name), /*body=*/body, - /*init=*/NullOpt, + /*init=*/std::nullopt, /*alloc_buffers=*/{}, /*match_buffers=*/{}, /*annotations=*/annotations))); @@ -584,7 +584,7 @@ Stmt GenerateStmtFromCompute(const te::ComputeOp& compute_op, CreateFuncInfo* in auto block_name = info->FreshName(compute_op->name + "_l" + std::to_string(i)); const auto& block_iters = cur.block_iters; - Optional init{NullOpt}; + Optional init{std::nullopt}; if (reduce && std::any_of(block_iters.begin(), block_iters.end(), [](const IterVar& iter) { return iter->iter_type == IterVarType::kCommReduce; })) { @@ -659,7 +659,7 @@ Stmt GenerateStmtFromExternOp(const te::ExternOp& extern_op, CreateFuncInfo* inf /*writes=*/{}, /*name_hint=*/info->FreshName(extern_op->name), /*body=*/std::move(body), - /*init=*/NullOpt, + /*init=*/std::nullopt, /*alloc_buffers=*/{}, /*match_buffers=*/{}, /*annotations=*/extern_op->attrs)); diff --git a/src/te/operation/create_primfunc.h b/src/te/operation/create_primfunc.h index dc045156d114..eb4a6183dd5c 100644 --- a/src/te/operation/create_primfunc.h +++ b/src/te/operation/create_primfunc.h @@ -20,7 +20,7 @@ #ifndef TVM_TE_OPERATION_CREATE_PRIMFUNC_H_ #define TVM_TE_OPERATION_CREATE_PRIMFUNC_H_ -#include +#include #include #include diff --git a/src/te/operation/placeholder_op.cc b/src/te/operation/placeholder_op.cc index 53a001a5bb4d..466def8b3014 100644 --- a/src/te/operation/placeholder_op.cc +++ b/src/te/operation/placeholder_op.cc @@ -21,7 +21,7 @@ * \brief Placeholder op. * \file placeholder_op.cc */ -#include +#include #include #include diff --git a/src/tir/analysis/buffer_access_lca_detector.cc b/src/tir/analysis/buffer_access_lca_detector.cc index dd1fce0fbef7..e8cba6116d65 100644 --- a/src/tir/analysis/buffer_access_lca_detector.cc +++ b/src/tir/analysis/buffer_access_lca_detector.cc @@ -62,7 +62,8 @@ class LCADetector : public StmtExprVisitor { Map> buffer_lca; for (const auto& kv : detector.buffer_lca_) { const Buffer& buffer = GetRef(kv.first); - const Optional stmt = kv.second ? GetRef>(kv.second->stmt) : NullOpt; + const Optional stmt = + kv.second ? GetRef>(kv.second->stmt) : std::nullopt; buffer_lca.Set(buffer, stmt); } return buffer_lca; diff --git a/src/tir/analysis/calculate_allocated_memory.cc b/src/tir/analysis/calculate_allocated_memory.cc index 04d3fc729c71..e304abcdeb7d 100644 --- a/src/tir/analysis/calculate_allocated_memory.cc +++ b/src/tir/analysis/calculate_allocated_memory.cc @@ -22,7 +22,7 @@ * \brief Calculate allocated memory per memory scope required by PrimFuncs. */ #include -#include +#include #include #include #include diff --git a/src/tir/analysis/control_flow_graph.cc b/src/tir/analysis/control_flow_graph.cc index 1065ad3bf1e0..e26d6d12e61f 100644 --- a/src/tir/analysis/control_flow_graph.cc +++ b/src/tir/analysis/control_flow_graph.cc @@ -163,7 +163,7 @@ class BufferConstraintApply : public IRMutatorWithAnalyzer { continue; } - Optional lane_var = NullOpt; + Optional lane_var = std::nullopt; IntImm num_lanes; Array indices = op->indices.Map([&](const auto& index) { @@ -522,9 +522,9 @@ class ControlFlowGraphBuilder final : public IRVisitorWithAnalyzer { ICHECK_LE(to_block, out_->control_flow_.size()); auto& forward = out_->control_flow_[from_block].successors.emplace_back( - ControlFlowGraph::ControlFlowEdge{to_block, {}, NullOpt}); + ControlFlowGraph::ControlFlowEdge{to_block, {}, std::nullopt}); auto& backward = out_->control_flow_[to_block].predecessors.emplace_back( - ControlFlowGraph::ControlFlowEdge{from_block, {}, NullOpt}); + ControlFlowGraph::ControlFlowEdge{from_block, {}, std::nullopt}); return {forward, backward}; } @@ -554,7 +554,7 @@ class ControlFlowGraphBuilder final : public IRVisitorWithAnalyzer { With analyzer_context; size_t old_num_constraints{0}; size_t new_num_constraints{0}; - Optional assume{NullOpt}; + Optional assume{std::nullopt}; // Disable default-generated copy/move assignment and constructors InternalConstraintContext(const InternalConstraintContext&) = delete; @@ -642,7 +642,7 @@ std::pair> ControlFlowGraph::ControlFlowBlock::Make Analyzer local_analyzer; - Optional lane_var = NullOpt; + Optional lane_var = std::nullopt; IntImm num_lanes; Array index_expressions = indices.Map([&](const auto& index) { @@ -1090,7 +1090,7 @@ class BufferRegionCollector : public ExprVisitor { Analyzer local_analyzer; if (!is_zero(unknown_region)) { - new_regions.insert(new_regions.begin(), Known{unknown_region, NullOpt}); + new_regions.insert(new_regions.begin(), Known{unknown_region, std::nullopt}); } std::vector updated_regions; @@ -1329,7 +1329,7 @@ Optional> ControlFlowGraph::GetIndexVariables(const Buffer& buf) cons if (auto it = axis_var_lookup_.find(buf); it != axis_var_lookup_.end()) { return (*it).second; } else { - return NullOpt; + return std::nullopt; } } diff --git a/src/tir/analysis/control_flow_graph.h b/src/tir/analysis/control_flow_graph.h index 543feeecfea1..f4babffbb74c 100644 --- a/src/tir/analysis/control_flow_graph.h +++ b/src/tir/analysis/control_flow_graph.h @@ -24,7 +24,7 @@ #include #include -#include +#include #include #include #include diff --git a/src/tir/analysis/deep_equal.cc b/src/tir/analysis/deep_equal.cc index 86431f1ac2f2..fb4cab759069 100644 --- a/src/tir/analysis/deep_equal.cc +++ b/src/tir/analysis/deep_equal.cc @@ -65,7 +65,7 @@ bool ExprDeepEqual::operator()(const PrimExpr& lhs, const PrimExpr& rhs) const { auto* prhs = rhs.as(); return plhs->dtype == prhs->dtype && plhs->value == prhs->value; } - return DeepCmpSEqualHandler().SEqualReduce(lhs, rhs, false, NullOpt); + return DeepCmpSEqualHandler().SEqualReduce(lhs, rhs, false, std::nullopt); } TVM_REGISTER_GLOBAL("tir.analysis.expr_deep_equal") diff --git a/src/tir/analysis/identify_memcpy.cc b/src/tir/analysis/identify_memcpy.cc index e36bb3a4f379..3ab96f634a31 100644 --- a/src/tir/analysis/identify_memcpy.cc +++ b/src/tir/analysis/identify_memcpy.cc @@ -24,7 +24,7 @@ #include #include -#include +#include #include #include #include diff --git a/src/tir/analysis/stmt_finding.cc b/src/tir/analysis/stmt_finding.cc index 527c7d04c6f3..7acbd2eb6ad2 100644 --- a/src/tir/analysis/stmt_finding.cc +++ b/src/tir/analysis/stmt_finding.cc @@ -144,7 +144,7 @@ TVM_REGISTER_GLOBAL("tir.analysis.find_anchor_block").set_body_typed([](const IR if (ret) { return Optional(GetRef(ret)); } - return Optional(NullOpt); + return Optional(std::nullopt); }); } // namespace tir diff --git a/src/tir/ir/block_dependence_info.cc b/src/tir/ir/block_dependence_info.cc index 13f38c86bf2a..9b1cb079fe28 100644 --- a/src/tir/ir/block_dependence_info.cc +++ b/src/tir/ir/block_dependence_info.cc @@ -92,7 +92,7 @@ TVM_REGISTER_GLOBAL("tir.BlockDependenceInfoGetBlockScope") TVM_REGISTER_GLOBAL("tir.BlockDependenceInfoGetSRef") .set_body_typed([](BlockDependenceInfo self, Stmt stmt) -> Optional { auto it = self->stmt2ref.find(stmt.get()); - return it != self->stmt2ref.end() ? it->second : Optional(NullOpt); + return it != self->stmt2ref.end() ? it->second : Optional(std::nullopt); }); } // namespace tir diff --git a/src/tir/ir/data_type_rewriter.cc b/src/tir/ir/data_type_rewriter.cc index 8a496d06bed8..304fe0bf820f 100644 --- a/src/tir/ir/data_type_rewriter.cc +++ b/src/tir/ir/data_type_rewriter.cc @@ -340,7 +340,7 @@ Stmt IndexDataTypeRewriter::VisitStmt_(const BlockNode* op) { [this](const BufferRegion& buffer_region) { return this->VisitBufferRegion(buffer_region); }); Array new_iter_vars = op->iter_vars.Map([this](const IterVar& iter_var) { return this->VisitIterVar(iter_var); }); - Optional new_init = NullOpt; + Optional new_init = std::nullopt; if (op->init.defined()) { new_init = this->VisitStmt(op->init.value()); } @@ -381,7 +381,7 @@ Map IndexDataTypeRewriter::VisitBlockAnnotations( if (Buffer new_buffer = GetRemappedBuffer(buffer); !new_buffer.same_as(buffer)) { return new_buffer; } - } else if (obj->IsInstance()) { + } else if (obj->IsInstance()) { return Downcast>(obj).Map(f_mutate_obj); } return obj; @@ -521,7 +521,7 @@ Stmt IndexDataTypeRewriter::VisitStmt_(const IfThenElseNode* op) { Stmt then_case = VisitStmt(op->then_case); Optional else_case = - op->else_case.defined() ? Optional{VisitStmt(op->else_case.value())} : NullOpt; + op->else_case.defined() ? Optional{VisitStmt(op->else_case.value())} : std::nullopt; if (!cond.same_as(op->condition) || !then_case.same_as(op->then_case) || !else_case.same_as(op->else_case)) { IfThenElse new_stmt = GetRef(op); diff --git a/src/tir/ir/expr.cc b/src/tir/ir/expr.cc index e89162239a63..4b9dca8989a9 100644 --- a/src/tir/ir/expr.cc +++ b/src/tir/ir/expr.cc @@ -557,37 +557,36 @@ Call::Call(DataType dtype, RelaxExpr op, Array args, Span span) { } TVM_REGISTER_GLOBAL("tir.Call") - .set_body_typed( - [](Optional dtype, RelaxExpr op, - Array> args, - Span span) { - Array prim_expr_args; - for (const auto& it : args) { - if (auto opt_str = it.as()) { - prim_expr_args.push_back(StringImm(opt_str.value())); - } else if (auto opt_dtype = it.as()) { - prim_expr_args.push_back(StringImm(ffi::DLDataTypeToString(opt_dtype.value()))); - } else if (const auto* iter_var = it.as()) { - prim_expr_args.push_back(iter_var->var); - } else if (const auto* br = it.as()) { - Array indices; - for (Range r : br->region) { - if (is_one(r->extent)) { - indices.push_back(r->min); - } else if (r->extent.as()) { - indices.push_back(tir::Ramp(r->min, make_const(r->min->dtype, 1), r->extent)); - } else { - LOG(FATAL) << "ValueError: Cannot convert to BufferLoad: " - << GetRef(br); - } - } - prim_expr_args.push_back(BufferLoad(br->buffer, indices)); + .set_body_typed([](Optional dtype, RelaxExpr op, + Array> args, + Span span) { + Array prim_expr_args; + for (const auto& it : args) { + if (auto opt_str = it.as()) { + prim_expr_args.push_back(StringImm(opt_str.value())); + } else if (auto opt_dtype = it.as()) { + prim_expr_args.push_back(StringImm(ffi::DLDataTypeToString(opt_dtype.value()))); + } else if (const auto* iter_var = it.as()) { + prim_expr_args.push_back(iter_var->var); + } else if (const auto* br = it.as()) { + Array indices; + for (Range r : br->region) { + if (is_one(r->extent)) { + indices.push_back(r->min); + } else if (r->extent.as()) { + indices.push_back(tir::Ramp(r->min, make_const(r->min->dtype, 1), r->extent)); } else { - prim_expr_args.push_back(Downcast(it)); + LOG(FATAL) << "ValueError: Cannot convert to BufferLoad: " + << GetRef(br); } } - return Call(dtype.value_or(DataType::Void()), op, prim_expr_args, span); - }); + prim_expr_args.push_back(BufferLoad(br->buffer, indices)); + } else { + prim_expr_args.push_back(Downcast(it)); + } + } + return Call(dtype.value_or(DataType::Void()), op, prim_expr_args, span); + }); TVM_REGISTER_NODE_TYPE(CallNode); @@ -651,8 +650,8 @@ CommReducer::CommReducer(Array lhs, Array rhs, Array result, << "ValueError: The number of identities must equal to the number of elements in `results`"; // Change the dtype of input vars to adapt to the dtype of identities - ArrayObj* p_lhs = lhs.CopyOnWrite(); - ArrayObj* p_rhs = rhs.CopyOnWrite(); + ffi::ArrayObj* p_lhs = lhs.CopyOnWrite(); + ffi::ArrayObj* p_rhs = rhs.CopyOnWrite(); std::unordered_map var_map; var_map.reserve(n_group * 2); for (int i = 0; i < static_cast(n_group); ++i) { @@ -666,7 +665,7 @@ CommReducer::CommReducer(Array lhs, Array rhs, Array result, p_rhs->SetItem(i, r); } - ArrayObj* p_result = result.CopyOnWrite(); + ffi::ArrayObj* p_result = result.CopyOnWrite(); for (int i = 0; i < static_cast(n_group); ++i) { p_result->SetItem(i, Substitute(result[i], var_map)); } diff --git a/src/tir/ir/function.cc b/src/tir/ir/function.cc index 126b97dcfda3..bbf77b7301ec 100644 --- a/src/tir/ir/function.cc +++ b/src/tir/ir/function.cc @@ -147,7 +147,7 @@ Optional TensorIntrin::Get(String name, bool allow_missing) { auto it = manager->reg.find(name); if (it == manager->reg.end()) { if (allow_missing) { - return NullOpt; + return std::nullopt; } else { LOG(FATAL) << "ValueError: TensorIntrin '" << name << "' is not registered"; } diff --git a/src/tir/ir/functor_common.h b/src/tir/ir/functor_common.h index b9bb43ca6ba6..901a5d5234ca 100644 --- a/src/tir/ir/functor_common.h +++ b/src/tir/ir/functor_common.h @@ -16,7 +16,7 @@ * specific language governing permissions and limitations * under the License. */ -#include +#include /*! * \file tir/ir/functor_common.h diff --git a/src/tir/ir/index_map.cc b/src/tir/ir/index_map.cc index ff948da01289..ceac7e4079ba 100644 --- a/src/tir/ir/index_map.cc +++ b/src/tir/ir/index_map.cc @@ -186,7 +186,7 @@ Array IndexMapNode::MapRanges(const Array& ranges, arith::Analyzer // affine sum. Since the terms are orthogonal, the extent of the // sum is the extent of the largest term. for (const auto& index : iter_map->indices) { - Optional extent = NullOpt; + Optional extent = std::nullopt; for (const auto& term : index->args) { PrimExpr term_extent = term->extent * term->scale; if (extent.defined()) { @@ -351,7 +351,7 @@ IndexMap IndexMap::RenameVariables( [&](const Var& var) { return Downcast(Substitute(var, var_remap)); }); auto new_final_indices = n->final_indices.Map([&](const PrimExpr& expr) { return Substitute(expr, var_remap); }); - Optional new_inverse_index_map = NullOpt; + Optional new_inverse_index_map = std::nullopt; if (n->inverse_index_map.defined()) { new_inverse_index_map = Downcast(n->inverse_index_map).RenameVariables(f_name_map); } @@ -410,7 +410,7 @@ IndexMap Substitute(const IndexMap& index_map, std::function(const Var& var)> f_subst) { Array new_output = index_map->final_indices.Map([&](const PrimExpr& expr) { return Substitute(expr, f_subst); }); - Optional new_inverse_map = NullOpt; + Optional new_inverse_map = std::nullopt; if (index_map->inverse_index_map.defined()) { new_inverse_map = Substitute(Downcast(index_map->inverse_index_map.value()), f_subst); } diff --git a/src/tir/ir/script/script_complete.cc b/src/tir/ir/script/script_complete.cc index e6e942a87ba6..c28f7e2b490d 100644 --- a/src/tir/ir/script/script_complete.cc +++ b/src/tir/ir/script/script_complete.cc @@ -143,7 +143,7 @@ PrimFunc ScriptComplete(PrimFunc func, const Array& root_allocates) { }(); if (should_insert_root) { - Block root_block({}, {}, {}, "root", std::move(res), NullOpt, root_allocates); + Block root_block({}, {}, {}, "root", std::move(res), std::nullopt, root_allocates); res = BlockRealize({}, Bool(true), std::move(root_block)); } diff --git a/src/tir/ir/stmt_functor.cc b/src/tir/ir/stmt_functor.cc index 23dba3ef7233..da7896e40bf0 100644 --- a/src/tir/ir/stmt_functor.cc +++ b/src/tir/ir/stmt_functor.cc @@ -349,7 +349,7 @@ Stmt StmtMutator::VisitStmt_(const DeclBufferNode* op) { Stmt StmtMutator::VisitStmt_(const IfThenElseNode* op) { PrimExpr condition = this->VisitExpr(op->condition); Stmt then_case = this->VisitStmt(op->then_case); - Optional else_case = NullOpt; + Optional else_case = std::nullopt; if (op->else_case) { else_case = this->VisitStmt(op->else_case.value()); } @@ -520,7 +520,7 @@ Stmt StmtMutator::VisitStmt_(const BlockNode* op) { Array reads = Internal::Mutate(this, op->reads); Array writes = Internal::Mutate(this, op->writes); Array match_buffers = Internal::Mutate(this, op->match_buffers); - Optional init = NullOpt; + Optional init = std::nullopt; if (op->init.defined()) { init = VisitStmt(op->init.value()); } diff --git a/src/tir/schedule/analysis.h b/src/tir/schedule/analysis.h index 9cf96bbd6b68..ad890ecb404e 100644 --- a/src/tir/schedule/analysis.h +++ b/src/tir/schedule/analysis.h @@ -264,7 +264,7 @@ void CheckPartialAffineBinding(const ScheduleState& self, Block block, * \return The loop domain */ Map LoopDomainOfSRefTreePath(const StmtSRef& low_inclusive, - const Optional& high_exclusive = NullOpt, + const Optional& high_exclusive = std::nullopt, const runtime::StorageScope& extra_relax_scope = // runtime::StorageScope{runtime::StorageRank::kGlobal, ""}); @@ -762,7 +762,7 @@ class TensorizeInfo : public ObjectRef { * \param block_sref The target block to match against * \param desc_func The prim func describing the computation to be tensorized * \param allow_padding Whether to allow padding the block iters to match the intrinsic description - * \return TensorizeInfo structure if a valid mapping is found, NullOpt otherwise + * \return TensorizeInfo structure if a valid mapping is found, std::nullopt otherwise */ Optional GetTensorizeLoopMapping(const tir::ScheduleState& self, const tir::StmtSRef& block_sref, @@ -809,10 +809,10 @@ class AutoTensorizeMappingInfo : public ObjectRef { * \param self The schedule state * \param block_sref The compute block for auto tensorization * \param desc_func The prim func describing the computation to be tensorized - * \return AutoTensorizeMappingInfo structure if a potential mapping is found, NullOpt otherwise. - * \note Returning a valid AutoTensorizeMappingInfo doesn't guarantee the block can be tensorized. - * We will need to apply the suggested layout transformations and then match against the tensor - * intrinsics. + * \return AutoTensorizeMappingInfo structure if a potential mapping is found, std::nullopt + * otherwise. \note Returning a valid AutoTensorizeMappingInfo doesn't guarantee the block can be + * tensorized. We will need to apply the suggested layout transformations and then match against the + * tensor intrinsics. */ Optional GetAutoTensorizeMappingInfo(const ScheduleState& self, const StmtSRef& block_sref, diff --git a/src/tir/schedule/analysis/analysis.cc b/src/tir/schedule/analysis/analysis.cc index 043bb92ade8d..7de3890c4ad8 100644 --- a/src/tir/schedule/analysis/analysis.cc +++ b/src/tir/schedule/analysis/analysis.cc @@ -614,7 +614,7 @@ void CheckPartialAffineBinding(const ScheduleState& self, Block block, } void CheckAffineBinding(const ScheduleState& self, Block block) { - CheckPartialAffineBinding(self, std::move(block), NullOpt); + CheckPartialAffineBinding(self, std::move(block), std::nullopt); } void CheckBlockHasTrivialBinding(const ScheduleState& self, const StmtSRef& block_sref) { @@ -1267,7 +1267,7 @@ std::pair, bool> GetBufferDefiningSite(const StmtSRef& block_ } // If we cannot find the defining site block, it means that the buffer must be in the function's // buffer_map, which isn't an intermediate buffer. - return {NullOpt, false}; + return {std::nullopt, false}; } /******** SRef Tree Related ********/ @@ -1385,7 +1385,7 @@ AnalyzeReadWritePattern(const BufferRegion& read_region, const BufferRegion& wri } // Case 2. Read index cannot be recognized as `var +/- const` // where `var` is a write index and `const` is an optional constant shift - Optional opt_const = NullOpt; + Optional opt_const = std::nullopt; const VarNode* var = static_cast(AnalyzeVarWithShift(dom->min, &opt_const).get()); if (var == nullptr || !var2idx.count(var)) { @@ -1752,7 +1752,7 @@ Optional GetTensorizeLoopMapping(const tir::ScheduleState& self, block_loops.push_back(loop); block_loop_vars.insert(loop->loop_var.get()); if (!analyzer.CanProve(loop->min == 0)) { - return NullOpt; + return std::nullopt; } } std::reverse(block_loops.begin(), block_loops.end()); @@ -1769,7 +1769,7 @@ Optional GetTensorizeLoopMapping(const tir::ScheduleState& self, std::unordered_map block_index_to_padding; // padding of each block iter if necessary if (offset < 0) { - return NullOpt; + return std::nullopt; } const std::vector iter_types_block = GetBlockVarTypes(block_sref); @@ -1811,7 +1811,7 @@ Optional GetTensorizeLoopMapping(const tir::ScheduleState& self, } } if (desc_loop == nullptr || desc_loop->extent.as() == nullptr) { - return NullOpt; + return std::nullopt; } const IntImmNode* int_desc_extent = desc_loop->extent.as(); @@ -1827,7 +1827,7 @@ Optional GetTensorizeLoopMapping(const tir::ScheduleState& self, } } - if (!block_bind.defined()) return NullOpt; + if (!block_bind.defined()) return std::nullopt; // Step 3.3. Find the corresponding loop of the target block for (int i = 0, n = block_loops.size(); i < n; ++i) { @@ -1851,7 +1851,7 @@ Optional GetTensorizeLoopMapping(const tir::ScheduleState& self, // Check divisibility if (!int_block_extent) { - return NullOpt; + return std::nullopt; } int64_t remainder = int_block_extent->value % int_desc_extent->value; if (remainder != 0) { @@ -1860,7 +1860,7 @@ Optional GetTensorizeLoopMapping(const tir::ScheduleState& self, // divisible if padding is allowed. block_index_to_padding[current_block_ind] = int_desc_extent->value; } else { - return NullOpt; + return std::nullopt; } } @@ -1874,7 +1874,7 @@ Optional GetTensorizeLoopMapping(const tir::ScheduleState& self, } if (!block_index_to_padding.empty()) { if (!allow_padding) { - return NullOpt; + return std::nullopt; } Array paddings; for (int i = 0, n = block->block->iter_vars.size(); i < n; ++i) { @@ -2103,12 +2103,12 @@ Optional GetAutoTensorizeMappingInfo(const tir::Schedu const tir::PrimFunc& desc_func) { AutoTensorizeComparator extractor(self->mod); if (!CheckAutoTensorizeApplicable(self, block_sref, desc_func, &extractor)) { - return NullOpt; + return std::nullopt; } arith::Analyzer analyzer; Array mappings = AutoTensorizeMappingProposer::ProposeMappings(&extractor, &analyzer); if (mappings.empty()) { - return NullOpt; + return std::nullopt; } ObjectPtr ret = make_object(); ret->mappings = std::move(mappings); diff --git a/src/tir/schedule/analysis/layout.cc b/src/tir/schedule/analysis/layout.cc index c31516234131..1daea910377f 100644 --- a/src/tir/schedule/analysis/layout.cc +++ b/src/tir/schedule/analysis/layout.cc @@ -152,7 +152,7 @@ Optional SuggestIndexMap(const Buffer& buffer, const Array& /*index=*/f_flatten_index(indices), input_iters, predicate, /*check_level=*/arith::IterMapLevel::Surjective, analyzer); if (split_exprs.empty()) { - return NullOpt; + return std::nullopt; } // Step 4. Sort the order of the split expressions std::vector order(split_exprs.size(), 0); diff --git a/src/tir/schedule/analysis/verify.cc b/src/tir/schedule/analysis/verify.cc index b29d13c3b9d3..4e3f04e0f389 100644 --- a/src/tir/schedule/analysis/verify.cc +++ b/src/tir/schedule/analysis/verify.cc @@ -68,7 +68,7 @@ class SRefTreeVerifier : public StmtVisitor { << GetRef(block) << "\nIts parent is supposed to be:\n" << GetRef(ancestors_.back()->stmt) << "\nHowever, its parent is incorrect and is:\n" << (sref->parent ? Optional(GetRef(sref->parent->stmt)) - : Optional(NullOpt)); + : Optional(std::nullopt)); ancestors_.push_back(sref.operator->()); if (block->init.defined()) { ++init_block_depth_; @@ -91,13 +91,13 @@ class SRefTreeVerifier : public StmtVisitor { << GetRef(loop); ++n_sref_visited_; const StmtSRef& sref = self_->stmt2ref.at(loop); - Optional stmt = NullOpt; + Optional stmt = std::nullopt; ICHECK(sref->parent == ancestors_.back()) << "InternalError: Parent information mismatch for ForNode:\n" << GetRef(loop) << "\nIts parent is supposed to be:\n" << GetRef(ancestors_.back()->stmt) << "\nHowever, its parent is incorrect and is:\n" << (sref->parent ? Optional(GetRef(sref->parent->stmt)) - : Optional(NullOpt)); + : Optional(std::nullopt)); ancestors_.push_back(sref.operator->()); StmtVisitor::VisitStmt_(loop); ancestors_.pop_back(); diff --git a/src/tir/schedule/concrete_schedule.cc b/src/tir/schedule/concrete_schedule.cc index 48fac7d5eff8..30644c5fd1a0 100644 --- a/src/tir/schedule/concrete_schedule.cc +++ b/src/tir/schedule/concrete_schedule.cc @@ -36,7 +36,7 @@ Schedule Schedule::Concrete(IRModule mod, support::LinearCongruentialEngine::TRa if (FindEntryFunc(mod, &gv) != nullptr) { n->func_working_on_ = gv; } else { - n->func_working_on_ = NullOpt; + n->func_working_on_ = std::nullopt; } return Schedule(std::move(n)); } @@ -930,7 +930,7 @@ Any ConcreteScheduleNode::CheckAndGetAnnotationValue(const ffi::Any& ann_val) { if (const auto* expr = ann_val.as()) { ICHECK(!expr->IsInstance()) - << "TypeError: runtime::String is expected, but gets StringImm"; + << "TypeError: String is expected, but gets StringImm"; auto res_expr = this->Get(GetRef(expr)); // prefer to return int/float literals for annotations if (auto opt_intimm = res_expr.as()) { @@ -941,7 +941,7 @@ Any ConcreteScheduleNode::CheckAndGetAnnotationValue(const ffi::Any& ann_val) { } return res_expr; } - if (const auto* arr = ann_val.as()) { + if (const auto* arr = ann_val.as()) { Array result; result.reserve(arr->size()); for (size_t i = 0; i < arr->size(); i++) { @@ -949,7 +949,7 @@ Any ConcreteScheduleNode::CheckAndGetAnnotationValue(const ffi::Any& ann_val) { } return std::move(result); } - if (const auto* dict = ann_val.as()) { + if (const auto* dict = ann_val.as()) { Map result; for (auto it = dict->begin(); it != dict->end(); ++it) { const auto& key = it->first; diff --git a/src/tir/schedule/concrete_schedule.h b/src/tir/schedule/concrete_schedule.h index c57c6044f5f1..b00d2069ed17 100644 --- a/src/tir/schedule/concrete_schedule.h +++ b/src/tir/schedule/concrete_schedule.h @@ -63,7 +63,7 @@ class ConcreteScheduleNode : public ScheduleNode { public: ScheduleState state() const final { return state_; } - Optional trace() const override { return NullOpt; } + Optional trace() const override { return std::nullopt; } Optional func_working_on() const final { return func_working_on_; } void WorkOn(const String& func_name) final; Schedule Copy() override; @@ -88,14 +88,14 @@ class ConcreteScheduleNode : public ScheduleNode { public: /******** Schedule: Sampling ********/ ExprRV SampleCategorical(const Array& candidates, const Array& probs, - Optional decision = NullOpt) override; + Optional decision = std::nullopt) override; Array SamplePerfectTile(const LoopRV& loop_rv, int n, int max_innermost_factor, - Optional> decision = NullOpt) override; + Optional> decision = std::nullopt) override; Array SamplePartitionedTile(const LoopRV& loop_rv, int n, int partition_pos, int innerpart_factor, - Optional> decision = NullOpt) override; + Optional> decision = std::nullopt) override; LoopRV SampleComputeLocation(const BlockRV& block_rv, - Optional decision = NullOpt) override; + Optional decision = std::nullopt) override; /******** Schedule: Get blocks & loops ********/ BlockRV GetBlock(const String& name, const Optional& func_name) override; Array GetLoops(const BlockRV& block_rv) override; diff --git a/src/tir/schedule/instruction.cc b/src/tir/schedule/instruction.cc index 8e1bce285d06..2a4efe3e8ab4 100644 --- a/src/tir/schedule/instruction.cc +++ b/src/tir/schedule/instruction.cc @@ -65,7 +65,7 @@ TVM_STATIC_IR_FUNCTOR(ReprPrinter, vtable) inputs.push_back(String("None")); } else if (obj.as() || obj.as()) { inputs.push_back(String("_")); - } else if (const auto* str_obj = obj.as()) { + } else if (const auto* str_obj = obj.as()) { inputs.push_back(String('"' + std::string(str_obj->data) + '"')); } else if (obj.type_index() < ffi::TypeIndex::kTVMFFIStaticObjectBegin) { inputs.push_back(obj); diff --git a/src/tir/schedule/instruction_traits.h b/src/tir/schedule/instruction_traits.h index 9f24ee1a3e8b..b22615c4e255 100644 --- a/src/tir/schedule/instruction_traits.h +++ b/src/tir/schedule/instruction_traits.h @@ -190,7 +190,7 @@ class PythonAPICall { * \brief Constructor * \param method_name The name of the schedule API to be called */ - explicit PythonAPICall(String method_name) : method_name_(method_name), output_(NullOpt) {} + explicit PythonAPICall(String method_name) : method_name_(method_name), output_(std::nullopt) {} /*! \brief Add an integer input */ inline void Input(String arg_name, int arg); /*! \brief Add an integer input */ @@ -272,7 +272,7 @@ template struct _IsTVMArray : std::false_type {}; template -struct _IsTVMArray> : std::true_type {}; +struct _IsTVMArray> : std::true_type {}; template struct _IsSingleObject @@ -409,7 +409,7 @@ TVM_ALWAYS_INLINE Array UnpackedInstTraits::_ConvertOutputs(const } else if (is_single_obj) { return {rv}; } else if (is_array) { - return rv.cast>(); + return rv.cast>(); } } @@ -425,7 +425,7 @@ inline void PythonAPICall::AsPythonString(const Any& obj, std::ostream& os) { } else if (const auto opt_float_imm = obj.as()) { os.precision(17); os << (*opt_float_imm)->value; - } else if (const auto* array = obj.as()) { + } else if (const auto* array = obj.as()) { os << '['; bool is_first = true; for (Any e : *array) { @@ -437,7 +437,7 @@ inline void PythonAPICall::AsPythonString(const Any& obj, std::ostream& os) { AsPythonString(e, os); } os << ']'; - } else if (const auto* dict = obj.as()) { + } else if (const auto* dict = obj.as()) { os << '{'; bool is_first = true; std::vector> dict_items; diff --git a/src/tir/schedule/primitive/block_annotate.cc b/src/tir/schedule/primitive/block_annotate.cc index 97154d189cb1..40725871cf2a 100644 --- a/src/tir/schedule/primitive/block_annotate.cc +++ b/src/tir/schedule/primitive/block_annotate.cc @@ -347,7 +347,7 @@ void UnsafeSetDType(ScheduleState self, const StmtSRef& block_sref, int buffer_i const BlockNode* block = TVM_SREF_TO_BLOCK(block_sref); Buffer buffer = GetNthAccessBuffer(self, GetRef(block), buffer_index, BufferIndexType::kWrite); - DataType target_dtype(runtime::StringToDLDataType(dtype)); + DataType target_dtype(StringToDLDataType(dtype)); // Step 1. If `dtype` equals the original data type, just return. if (buffer->dtype == target_dtype) { diff --git a/src/tir/schedule/primitive/blockize_tensorize.cc b/src/tir/schedule/primitive/blockize_tensorize.cc index 60ac7bf422e7..a5ec9d436b17 100644 --- a/src/tir/schedule/primitive/blockize_tensorize.cc +++ b/src/tir/schedule/primitive/blockize_tensorize.cc @@ -288,7 +288,7 @@ BlockRealize GenerateInner(bool is_write_reduction, Block block) { BlockNode* n = block.CopyOnWrite(); n->iter_vars = iter_vars; - n->init = NullOpt; + n->init = std::nullopt; if (is_write_reduction) { Array reads; reads.reserve(block->writes.size() + block->reads.size()); @@ -343,7 +343,7 @@ Stmt GenerateOuterInit(const Stmt& block_init, const BlockRealize& inner_realize /*writes=*/inner_block->writes, /*name_hint=*/block_name, /*body=*/block_init, - /*init=*/NullOpt)); + /*init=*/std::nullopt)); // Step 3. Create the loop nest on top of the block for (const ForNode* loop : loops) { bool is_init_loop = false; @@ -549,7 +549,7 @@ BlockRealize BlockizeImpl(const ScheduleState& self, const StmtSRef& loop_sref, block_subst->init.defined() // ? GenerateOuterInit(block_subst->init.value(), inner_realize, loops, block_subst->name_hint + "_init") - : Optional(NullOpt))); + : Optional(std::nullopt))); } StmtSRef Blockize(ScheduleState self, const StmtSRef& loop_sref, bool preserve_unit_iters) { @@ -654,7 +654,7 @@ BlockRealize BlockizeBlocks(const ScheduleState& self, const Array& bl /*writes=*/UnionRegions(write_regions), /*name_hint=*/outer_block_name, /*body=*/SeqStmt(seq_body), - /*init=*/Optional(NullOpt))); + /*init=*/Optional(std::nullopt))); } class BlockizeRewriter : public StmtMutator { @@ -743,7 +743,7 @@ void Tensorize(ScheduleState self, const StmtSRef& sref, const TensorIntrin& int bool preserve_unit_iters) { // Step 1: Blockize the subtree rooted at the given loop if needed BlockRealize block_realize{nullptr}; - Optional old_block = NullOpt; + Optional old_block = std::nullopt; if (sref->stmt->IsInstance()) { block_realize = GetBlockRealize(self, sref); old_block = block_realize->block; diff --git a/src/tir/schedule/primitive/cache_index.cc b/src/tir/schedule/primitive/cache_index.cc index 58bcd368c880..2e94b2050496 100644 --- a/src/tir/schedule/primitive/cache_index.cc +++ b/src/tir/schedule/primitive/cache_index.cc @@ -315,7 +315,7 @@ Array MakeIndexCacheStage(IndexInfo* info, const String& storage_scope) { /*name_hint=*/"index_" + std::to_string(expr_index), /*body=*/ BufferStore(info->cache_buffer[expr_index], new_expr, access_indices), - /*init=*/NullOpt, + /*init=*/std::nullopt, /*alloc_buffers=*/{}, /*match_buffers=*/{}, /*annotations=*/{}); diff --git a/src/tir/schedule/primitive/cache_read_write.cc b/src/tir/schedule/primitive/cache_read_write.cc index a0536741c4f7..1b2a3a1cb478 100644 --- a/src/tir/schedule/primitive/cache_read_write.cc +++ b/src/tir/schedule/primitive/cache_read_write.cc @@ -88,7 +88,7 @@ struct CacheStageInfo { /*! \brief Return the buffer region related with the buffer */ Optional GetBufferRegionFromBuffer(const Array& buffer_regions, const Buffer& buffer) { - Optional res = NullOpt; + Optional res = std::nullopt; for (const auto& region : buffer_regions) { if (region->buffer.same_as(buffer)) { ICHECK(!res.defined()); @@ -204,7 +204,7 @@ Block MakeReindexCacheStage(const BufferRegion& cache_region, ReindexCacheStageI /*body=*/ BufferStore(info->write_buffer, BufferLoad(info->read_buffer, read_access_indices), write_access_indices), - /*init=*/NullOpt, + /*init=*/std::nullopt, /*alloc_buffers=*/{}, /*match_buffers=*/{}, /*buf_doms=*/{}); @@ -304,7 +304,7 @@ Block MakeCacheStage(const BufferRegion& cache_region, CacheStageInfo* info, /*body=*/ BufferStore(info->write_buffer, BufferLoad(info->read_buffer, read_access_indices), write_access_indices), - /*init=*/NullOpt, + /*init=*/std::nullopt, /*alloc_buffers=*/{}, /*match_buffers=*/{}, /*annotations=*/{}); @@ -503,7 +503,7 @@ Stmt InsertCacheStage(const Stmt& stmt, int pos, const Stmt& stage) { * \param scope_sref The scope block where the write is considered * \param buffer The queried buffer * \return The sref of the only writer of the input buffer in the given scope, - * or `NullOpt` if no block writes it in the scope. + * or `std::nullopt` if no block writes it in the scope. * \throw NotSingleWriteBlock if there are more than one interested block. */ Optional GetOnlyWriteBlock(ScheduleState self, const StmtSRef& scope_sref, @@ -511,7 +511,7 @@ Optional GetOnlyWriteBlock(ScheduleState self, const StmtSRef& scope_s BlockScope scope = self->GetBlockScope(scope_sref); auto it = scope->buffer_writers.find(buffer); if (it == scope->buffer_writers.end()) { - return NullOpt; + return std::nullopt; } else { const Array& block_srefs = it->second; ICHECK(!block_srefs.empty()); diff --git a/src/tir/schedule/primitive/compute_at.cc b/src/tir/schedule/primitive/compute_at.cc index 56d85318d7bc..0075fee18f4c 100644 --- a/src/tir/schedule/primitive/compute_at.cc +++ b/src/tir/schedule/primitive/compute_at.cc @@ -366,7 +366,7 @@ void RelaxBufferRegions(const Map& binding, runtime::StorageScope global_scope{runtime::StorageRank::kGlobal, ""}; // We cache the variable domains runtime::StorageRank previous_rank = runtime::StorageRank::kGlobal; - Optional> var_dom = NullOpt; + Optional> var_dom = std::nullopt; // Enumerate every buffer region for (const BufferRegion& buffer_region : buffer_regions) { const Buffer& buffer = buffer_region->buffer; diff --git a/src/tir/schedule/primitive/for_kind.cc b/src/tir/schedule/primitive/for_kind.cc index 214390dafe2d..f1e035d92ef7 100644 --- a/src/tir/schedule/primitive/for_kind.cc +++ b/src/tir/schedule/primitive/for_kind.cc @@ -176,17 +176,17 @@ void ParallelizeComputation(const ScheduleState& self, const StmtSRef& loop_sref /*iter_type=*/kThreadIndex, // /*thread_tag=*/thread_axis.value()); } else { - new_loop->thread_binding = NullOpt; + new_loop->thread_binding = std::nullopt; } self->Replace(loop_sref, For(new_loop), {}); } void Parallel(ScheduleState self, const StmtSRef& loop_sref) { - ParallelizeComputation(self, loop_sref, ForKind::kParallel, NullOpt); + ParallelizeComputation(self, loop_sref, ForKind::kParallel, std::nullopt); } void Vectorize(ScheduleState self, const StmtSRef& loop_sref) { - ParallelizeComputation(self, loop_sref, ForKind::kVectorized, NullOpt); + ParallelizeComputation(self, loop_sref, ForKind::kVectorized, std::nullopt); } void Bind(ScheduleState self, const StmtSRef& loop_sref, const String& thread_axis) { @@ -197,7 +197,7 @@ void Unroll(ScheduleState self, const StmtSRef& loop_sref) { const ForNode* loop = TVM_SREF_TO_FOR(loop_sref); ObjectPtr new_loop = make_object(*loop); new_loop->kind = ForKind::kUnrolled; - new_loop->thread_binding = NullOpt; + new_loop->thread_binding = std::nullopt; self->Replace(loop_sref, For(new_loop), {}); } diff --git a/src/tir/schedule/primitive/layout_transformation.cc b/src/tir/schedule/primitive/layout_transformation.cc index 6a0bba5c811a..a455afe6b067 100644 --- a/src/tir/schedule/primitive/layout_transformation.cc +++ b/src/tir/schedule/primitive/layout_transformation.cc @@ -513,14 +513,14 @@ class TransformLayoutPlanner : private StmtExprVisitor { auto generate_if_then_else_block = [&](const WriteInfo& info) -> Optional { if (!info.contains_row_major_traversal || !pad_value.defined() || is_zero(padding_predicate)) { - return NullOpt; + return std::nullopt; } BufferStoreReplacer replacer(info, new_buffer, padding_predicate, inverse, pad_value, &new_block_to_old, analyzer); Stmt stmt = replacer(info.dependent_loopnest.back()->body); if (!replacer.is_all_stores_replaced()) { - return NullOpt; + return std::nullopt; } ICHECK_EQ(inverse->initial_indices.size(), new_buffer->shape.size()); @@ -707,7 +707,7 @@ class TransformLayoutPlanner : private StmtExprVisitor { * * Used to fill the `WriteInfo::innermost_block_realize` field.. */ - Optional innermost_block_realize_{NullOpt}; + Optional innermost_block_realize_{std::nullopt}; /*! \brief The buffer to be replaced */ Buffer old_buffer_; @@ -1176,7 +1176,7 @@ void TransformLayout(ScheduleState self, const StmtSRef& block_sref, int buffer_ : GetScopeRoot(self, block_sref, /*require_stage_pipeline=*/false); const BlockNode* scope_block = TVM_SREF_TO_BLOCK(scope_sref); - Optional opt_inverse = NullOpt; + Optional opt_inverse = std::nullopt; PrimExpr padding_predicate = Bool(false); if (!assume_injective_transform) { std::tie(opt_inverse, padding_predicate) = [&]() { @@ -1209,7 +1209,7 @@ void TransformLayout(ScheduleState self, const StmtSRef& block_sref, int buffer_ GlobalVar g_var; const auto* old_func = GetRootPrimFunc(self->mod, scope_block, &g_var); IRModuleNode* new_mod = self->mod.CopyOnWrite(); - MapObj* new_map = new_mod->functions.CopyOnWrite(); + ffi::MapObj* new_map = new_mod->functions.CopyOnWrite(); Map new_buffer_map; for (auto [var, buffer] : old_func->buffer_map) { @@ -1533,10 +1533,10 @@ void SetAxisSeparator(ScheduleState self, const StmtSRef& block_sref, int buffer GlobalVar g_var; GetRootPrimFunc(self->mod, scope_block, &g_var); IRModuleNode* new_mod = self->mod.CopyOnWrite(); - MapObj* new_map = new_mod->functions.CopyOnWrite(); + ffi::MapObj* new_map = new_mod->functions.CopyOnWrite(); PrimFunc ref_new_func = Downcast(std::move(new_map->at(g_var))); PrimFuncNode* new_func = ref_new_func.CopyOnWrite(); - MapObj* new_buffer_map = new_func->buffer_map.CopyOnWrite(); + ffi::MapObj* new_buffer_map = new_func->buffer_map.CopyOnWrite(); for (auto it = new_buffer_map->begin(); it != new_buffer_map->end(); ++it) { if ((*it).second.same_as(old_buffer)) { (*it).second = new_buffer; diff --git a/src/tir/schedule/primitive/loop_transformation.cc b/src/tir/schedule/primitive/loop_transformation.cc index b8f4dfd58c2b..d112560a1fee 100644 --- a/src/tir/schedule/primitive/loop_transformation.cc +++ b/src/tir/schedule/primitive/loop_transformation.cc @@ -77,14 +77,14 @@ class SubstituteVarAndCollectOpaqueBlock : public StmtExprMutator { /*! \brief Simplify the binding of block realize and update the opaque block reuse mapping */ class IterMapSimplifyBlockBinding : public StmtExprMutator { public: - explicit IterMapSimplifyBlockBinding(MapObj* opaque_blocks, Map loop_var2extent, + explicit IterMapSimplifyBlockBinding(ffi::MapObj* opaque_blocks, Map loop_var2extent, bool preserve_unit_iters) : opaque_blocks_(opaque_blocks), loop_var2extent_(loop_var2extent), preserve_unit_iters_(preserve_unit_iters) {} - static For SimplifyBindings(Stmt stmt, const Array& loop_srefs, MapObj* opaque_blocks, - bool preserve_unit_iters) { + static For SimplifyBindings(Stmt stmt, const Array& loop_srefs, + ffi::MapObj* opaque_blocks, bool preserve_unit_iters) { Map loop_var2extent; for (const StmtSRef& sref : loop_srefs) { const ForNode* loop = TVM_SREF_TO_FOR(sref); @@ -132,7 +132,7 @@ class IterMapSimplifyBlockBinding : public StmtExprMutator { } /*! \brief The reuse mapping */ - MapObj* opaque_blocks_; + ffi::MapObj* opaque_blocks_; /*! \brief The range of loops */ Map loop_var2extent_; /*! \brief Internal analyzer */ @@ -164,7 +164,7 @@ class BlockPropertyError : public ScheduleError { throw BlockPropertyError(state_->mod, GetRef(op)); } Optional high_exclusive = - top_->parent ? GetRef(top_->parent) : Optional(NullOpt); + top_->parent ? GetRef(top_->parent) : Optional(std::nullopt); CheckPartialAffineBinding(state_, GetRef(op), high_exclusive); } } @@ -427,7 +427,7 @@ Array Split(ScheduleState self, const StmtSRef& loop_sref, const Array if (v.same_as(loop->loop_var)) { return substitute_value; } else { - return NullOpt; + return std::nullopt; } }, &opaque_block_reuse)(std::move(new_stmt)); @@ -933,7 +933,7 @@ StmtSRef Fuse(ScheduleState self, const Array& loop_srefs, bool preser return substitute_value[i]; } } - return NullOpt; + return std::nullopt; }; new_stmt = SubstituteVarAndCollectOpaqueBlock(f_substitute, &opaque_block_reuse)(std::move(new_stmt)); @@ -994,7 +994,7 @@ std::pair GetBoundaryOfReorderRange( // Case 1. If `v` corresponds to a block, stop traversal. if (v->stmt->IsInstance()) { if (scope_block_visited) { - throw LoopsNotAChainError(self->mod, NullOpt, + throw LoopsNotAChainError(self->mod, std::nullopt, LoopsNotAChainError::ProblemKind::kNotUnderAScope); } scope_block_visited = true; diff --git a/src/tir/schedule/primitive/pad_einsum.cc b/src/tir/schedule/primitive/pad_einsum.cc index 5bf59005bbe7..5b724b6bd295 100644 --- a/src/tir/schedule/primitive/pad_einsum.cc +++ b/src/tir/schedule/primitive/pad_einsum.cc @@ -27,7 +27,7 @@ namespace tir { /*! * \brief Check if buffer indices are all Vars and expr * \param buffer_access The BufferLoad or BufferStore - * \return The indices if the indices are all Vars, otherwise NullOpt + * \return The indices if the indices are all Vars, otherwise std::nullopt */ Optional> CheckTrivialBufferIndices(const Array& buffer_access) { Array indices; @@ -37,7 +37,7 @@ Optional> CheckTrivialBufferIndices(const Array& buffer_acc } const VarNode* var = index.as(); if (var == nullptr) { - return NullOpt; + return std::nullopt; } indices.push_back(GetRef(var)); } @@ -49,7 +49,7 @@ Optional> CheckTrivialBufferAccess(const BufferRegion& buffer_region) indices.reserve(buffer_region->region.size()); for (const Range& range : buffer_region->region) { if (!tir::is_one(range->extent)) { - return NullOpt; + return std::nullopt; } if (range->min->IsInstance()) { continue; @@ -57,7 +57,7 @@ Optional> CheckTrivialBufferAccess(const BufferRegion& buffer_region) if (const auto* var = range->min.as()) { indices.push_back(GetRef(var)); } else { - return NullOpt; + return std::nullopt; } } return indices; diff --git a/src/tir/schedule/primitive/read_write_at.cc b/src/tir/schedule/primitive/read_write_at.cc index d482263bbcc8..9fdb322a4996 100644 --- a/src/tir/schedule/primitive/read_write_at.cc +++ b/src/tir/schedule/primitive/read_write_at.cc @@ -311,7 +311,7 @@ struct ReadWriteAtImpl { /*writes=*/{BufferRegion(copy_to, domain)}, /*name_hint=*/name_hint, // /*body=*/std::move(stmt), - /*init=*/NullOpt, + /*init=*/std::nullopt, /*alloc_buffers=*/{}, /*match_buffers=*/{}, /*annotations=*/annotations_)); diff --git a/src/tir/schedule/primitive/reduction.cc b/src/tir/schedule/primitive/reduction.cc index 126832cc85fb..e457bda5a86a 100644 --- a/src/tir/schedule/primitive/reduction.cc +++ b/src/tir/schedule/primitive/reduction.cc @@ -63,7 +63,7 @@ class DecomposeReductionBlockReplacer : public StmtMutator { if (block == old_reduction_block_.get()) { ObjectPtr p_new_block = CopyOnWrite(block); p_new_block->name_hint = p_new_block->name_hint + "_update"; - p_new_block->init = NullOpt; + p_new_block->init = std::nullopt; // Add write regions back to read regions in update block. Array new_reads; std::unordered_set read_bufs; @@ -412,7 +412,7 @@ struct ReducerRegistry { identity_getter = std::move(identity_getter) // ](Array values) -> Optional { if (static_cast(values.size()) != n_buffers) { - return NullOpt; + return std::nullopt; } Array lhs; Array rhs; @@ -747,7 +747,7 @@ class BaseBlockCreator { Optional CreateBlockInit(bool has_reduce_iter) { if (!has_reduce_iter) { - return NullOpt; + return std::nullopt; } Array inits; diff --git a/src/tir/schedule/primitive/rolling_buffer.cc b/src/tir/schedule/primitive/rolling_buffer.cc index c01d6c568fcd..19375f7235fc 100644 --- a/src/tir/schedule/primitive/rolling_buffer.cc +++ b/src/tir/schedule/primitive/rolling_buffer.cc @@ -191,7 +191,7 @@ class RollingBufferInfoCollector { stride = 1; } else if (is_const_int(bound->min)) { // If the bound is an int, we can't roll over it - iter_var = NullOpt; + iter_var = std::nullopt; } else { // If all of the above matches fail, we're in unknown behaviour return false; @@ -202,9 +202,9 @@ class RollingBufferInfoCollector { bound_overlap = extent - stride; // Since Pass CompactBufferAllocation will be responsible for compacting the buffer // allocation region, there is no need to roll over the axis where the overlap is not - // positive, so reset iter_var to NullOpt. + // positive, so reset iter_var to std::nullopt. if (bound_overlap <= 0) { - iter_var = NullOpt; + iter_var = std::nullopt; } } bound_iter_vars.push_back(iter_var); diff --git a/src/tir/schedule/state.cc b/src/tir/schedule/state.cc index 43a3c9008f0d..8057492dbb04 100644 --- a/src/tir/schedule/state.cc +++ b/src/tir/schedule/state.cc @@ -750,7 +750,7 @@ class ChildReplacer : private StmtMutator { int n = static_cast(op->seq.size()); if (0 <= i && i < n) { const Stmt& stmt = op->seq[i]; - Optional new_stmt = NullOpt; + Optional new_stmt = std::nullopt; const StmtNode* src_stmt = this->src_stmt_; // `stmt` can be For or BlockRealize // `src_stmt` can be For or Block @@ -945,7 +945,7 @@ void ScheduleStateNode::Replace(const tir::StmtSRef& _src_sref, const Stmt& tgt_ } // Ensure the uniqueness of `this->mod` and `this->mod->functions` IRModuleNode* new_mod = this->mod.CopyOnWrite(); - MapObj* new_map = new_mod->functions.CopyOnWrite(); + ffi::MapObj* new_map = new_mod->functions.CopyOnWrite(); // Move out the PrimFunc where the sref belong while ensuring uniqueness PrimFunc ref_new_func = Downcast(std::move(new_map->at(g_var))); ICHECK(ref_new_func.get() == g_func); @@ -1023,7 +1023,7 @@ TVM_REGISTER_GLOBAL("tir.schedule.ScheduleStateReplace") TVM_REGISTER_GLOBAL("tir.schedule.ScheduleStateGetSRef") .set_body_typed([](ScheduleState self, Stmt stmt) -> Optional { auto it = self->stmt2ref.find(stmt.get()); - return it != self->stmt2ref.end() ? it->second : Optional(NullOpt); + return it != self->stmt2ref.end() ? it->second : Optional(std::nullopt); }); TVM_REGISTER_GLOBAL("tir.schedule.ScheduleStateGetCachedFlags").set_body_typed(GetCachedFlags); diff --git a/src/tir/schedule/trace.cc b/src/tir/schedule/trace.cc index a666a1d5902e..f6fa76da7871 100644 --- a/src/tir/schedule/trace.cc +++ b/src/tir/schedule/trace.cc @@ -58,7 +58,7 @@ Array TranslateInputRVs(const Array& inputs, auto f_subst_with_rv_map = [&rv_map](const Var& var) -> Optional { auto it = rv_map.find(var.get()); if (it == rv_map.end()) { - return NullOpt; + return std::nullopt; } const Object* dst = it->second; ICHECK(dst->IsInstance()) @@ -120,16 +120,16 @@ Array TranslateInputRVs( LOG(FATAL) << "IndexError: Random variable is not defined " << input; throw; } - } else if (const auto* str_obj = input.as()) { + } else if (const auto* str_obj = input.as()) { // Case 2. string => "content" results.push_back(String('"' + std::string(str_obj->data) + '"')); } else if (input.as() || input.as()) { // Case 3. integer or floating-point number results.push_back(input); - } else if (input.as()) { + } else if (input.as()) { // Case 4: array results.push_back(TranslateInputRVs(Downcast>(Any(input)), rv_names)); - } else if (input.as()) { + } else if (input.as()) { // Case 5: dict results.push_back(input); } else if (input.as()) { @@ -139,7 +139,7 @@ Array TranslateInputRVs( if (auto it = rv_names.find(var); it != rv_names.end()) { return it->second; } - return NullOpt; + return std::nullopt; }); results.push_back(index_map); } else { @@ -166,12 +166,12 @@ Array TranslateInputRVs(const Array& inputs, continue; } // Case 4. array - if (input.as()) { + if (input.as()) { results.push_back(TranslateInputRVs(Downcast>(input), named_rvs)); continue; } // Case 5. dict - if (input.as()) { + if (input.as()) { results.push_back(input); continue; } @@ -190,7 +190,7 @@ Array TranslateInputRVs(const Array& inputs, if (it != named_rvs.end()) { return Downcast(it->second); } - return NullOpt; + return std::nullopt; }); results.push_back(index_map); continue; @@ -236,7 +236,7 @@ Array TranslateAddOutputRVs( ICHECK(!rv_names->count(output.cast())) << "ValueError: The random variable has been produced once: " << rv_names->at(output.cast()); - String result{ObjectPtr{nullptr}}; + String result{ffi::ObjectPtr{nullptr}}; if (output == nullptr) { result = "_"; } else if (output.as()) { @@ -280,7 +280,7 @@ void TraceNode::Append(Instruction inst, Any decision) { Optional TraceNode::Pop() { if (insts.empty()) { - return NullOpt; + return std::nullopt; } Instruction inst = insts.back(); insts.pop_back(); @@ -359,7 +359,7 @@ Array TraceNode::AsPython(bool remove_postproc) const { Array attrs; attrs.reserve(inst->attrs.size()); for (const Any& obj : inst->attrs) { - if (const auto* str = obj.as()) { + if (const auto* str = obj.as()) { attrs.push_back(String('"' + std::string(str->data) + '"')); } else { attrs.push_back(obj); @@ -379,10 +379,10 @@ void Trace::ApplyJSONToSchedule(ObjectRef json, Schedule sch) { Array json_decisions{nullptr}; // Parse `json` into `json_insts` and `json_decisions` try { - const ArrayObj* arr = json.as(); + const ffi::ArrayObj* arr = json.as(); ICHECK(arr && arr->size() == 2); - const auto* arr0 = arr->at(0).as(); - const auto* arr1 = arr->at(1).as(); + const auto* arr0 = arr->at(0).as(); + const auto* arr1 = arr->at(1).as(); ICHECK(arr0 && arr1); json_insts = GetRef>(arr0); json_decisions = GetRef>(arr1); @@ -398,7 +398,7 @@ void Trace::ApplyJSONToSchedule(ObjectRef json, Schedule sch) { int index = -1; Any decision{nullptr}; try { - const ArrayObj* arr = decision_entry.as(); + const ffi::ArrayObj* arr = decision_entry.as(); ICHECK(arr && arr->size() == 2); auto arr0 = arr->at(0).as(); ICHECK(arr0); @@ -422,9 +422,9 @@ void Trace::ApplyJSONToSchedule(ObjectRef json, Schedule sch) { Array outputs{ObjectPtr{nullptr}}; // Parse the entry try { - const auto* arr = inst_entry.as(); + const auto* arr = inst_entry.as(); ICHECK(arr && arr->size() == 4); - const auto* arr0 = arr->at(0).as(); + const auto* arr0 = arr->at(0).as(); kind = InstructionKind::Get(arr0->data); inputs = arr->at(1).cast>(); attrs = arr->at(2).cast>(); diff --git a/src/tir/schedule/traced_schedule.cc b/src/tir/schedule/traced_schedule.cc index 52a012b2a321..d3e77e0e3b84 100644 --- a/src/tir/schedule/traced_schedule.cc +++ b/src/tir/schedule/traced_schedule.cc @@ -35,7 +35,7 @@ Schedule Schedule::Traced(IRModule mod, support::LinearCongruentialEngine::TRand if (FindEntryFunc(mod, &gv) != nullptr) { n->func_working_on_ = gv; } else { - n->func_working_on_ = NullOpt; + n->func_working_on_ = std::nullopt; } return Schedule(std::move(n)); } diff --git a/src/tir/schedule/traced_schedule.h b/src/tir/schedule/traced_schedule.h index 30eeccfd85c7..777f31a57bea 100644 --- a/src/tir/schedule/traced_schedule.h +++ b/src/tir/schedule/traced_schedule.h @@ -48,13 +48,14 @@ class TracedScheduleNode : public ConcreteScheduleNode { public: /******** Schedule: Sampling ********/ ExprRV SampleCategorical(const Array& candidates, const Array& probs, - Optional decision = NullOpt) final; + Optional decision = std::nullopt) final; Array SamplePerfectTile(const LoopRV& loop_rv, int n, int max_innermost_factor, - Optional> decision = NullOpt) final; + Optional> decision = std::nullopt) final; Array SamplePartitionedTile(const LoopRV& loop_rv, int n, int partition_pos, int innerpart_factor, - Optional> decision = NullOpt) final; - LoopRV SampleComputeLocation(const BlockRV& block_rv, Optional decision = NullOpt) final; + Optional> decision = std::nullopt) final; + LoopRV SampleComputeLocation(const BlockRV& block_rv, + Optional decision = std::nullopt) final; /******** Schedule: Get blocks & loops ********/ BlockRV GetBlock(const String& name, const Optional& func_name) final; Array GetLoops(const BlockRV& block_rv) final; diff --git a/src/tir/schedule/transform.cc b/src/tir/schedule/transform.cc index 69686bac55fb..fa6a71fce64c 100644 --- a/src/tir/schedule/transform.cc +++ b/src/tir/schedule/transform.cc @@ -323,7 +323,7 @@ Optional TileWithTensorIntrin(const tir::Schedule& sch, const tir::Block Optional opt_tensorize_info = GetTensorizeLoopMapping(sch->state(), sch->GetSRef(block_rv), tir::TensorIntrin::Get(intrin_name).value()->desc, allow_padding); - if (!opt_tensorize_info) return NullOpt; + if (!opt_tensorize_info) return std::nullopt; const tir::TensorizeInfoNode* info = opt_tensorize_info.value().get(); if (info->block_iter_paddings.defined()) { // We have to track whether each producer or consumer is padded. @@ -413,9 +413,9 @@ Optional TileWithTensorIntrin(const tir::Schedule& sch, const tir::Block int64_t total = int_block_extent->value; int64_t inner = int_desc_extent->value; ICHECK_EQ(total % inner, 0); - // Do the split. Leave the outer extent as NullOpt (unspecified) so that the split factors + // Do the split. Leave the outer extent as std::nullopt (unspecified) so that the split factors // can be used for different extents (needed during tuning). - Array split = sch->Split(loop2rv.at(block_loop_sref), {NullOpt, Integer(inner)}); + Array split = sch->Split(loop2rv.at(block_loop_sref), {std::nullopt, Integer(inner)}); ICHECK_EQ(split.size(), 2); inner_loops.insert(sch->GetSRef(split[1]).operator->()); // The inner split will be reordered to the loop domain that is tensorized @@ -508,15 +508,15 @@ Optional NormalizePrimFunc(Schedule sch) { Array binds = GetBlockRealize(sch->state(), block_sref)->iter_values; if (loops.size() == 0) continue; if (loops.size() != binds.size()) { - return NullOpt; + return std::nullopt; } for (int i = 0, n = loops.size(); i < n; ++i) { const ForNode* loop = TVM_SREF_TO_FOR(loops[i]); if (binds[i].get() != loop->loop_var.get()) { - return NullOpt; + return std::nullopt; } if (!is_zero(loop->min)) { - return NullOpt; + return std::nullopt; } } } diff --git a/src/tir/schedule/transform.h b/src/tir/schedule/transform.h index c597997414a0..73d6a0d85371 100644 --- a/src/tir/schedule/transform.h +++ b/src/tir/schedule/transform.h @@ -212,7 +212,7 @@ void LeafBlockRemovalPlan(const ScheduleState& self, const StmtSRef& leaf_block_ * TensorIntrin.register(...) beforehand * \param allow_padding Whether to allow padding when tiling * \return LoopRV corresponding to the outermost loop of a - * block tiled according to the given intrin, NullOpt if a valid loop mapping is not found + * block tiled according to the given intrin, std::nullopt if a valid loop mapping is not found */ Optional TileWithTensorIntrin(const tir::Schedule& sch, const tir::BlockRV& block_rv, const String& intrin_name, bool allow_padding = false); diff --git a/src/tir/schedule/utils.h b/src/tir/schedule/utils.h index 1910bed28796..deedfd6f68dc 100644 --- a/src/tir/schedule/utils.h +++ b/src/tir/schedule/utils.h @@ -218,12 +218,12 @@ inline const int64_t* GetLoopIntExtent(const StmtSRef& loop_sref) { * \brief Check if an expression consists of a single variable, * or a variable plus/minus an constant integer shift * \param expr The expression to be checked - * \return The single variable in the expression, or NullOpt if the expression is neither a variable - * or a constant shift from a variable + * \return The single variable in the expression, or std::nullopt if the expression is neither a + * variable or a constant shift from a variable */ inline Optional AnalyzeVarWithShift(const PrimExpr& expr, Optional* constant) { if (const auto* var = expr.as()) { - *constant = NullOpt; + *constant = std::nullopt; return GetRef(var); } arith::PVar var; @@ -239,7 +239,7 @@ inline Optional AnalyzeVarWithShift(const PrimExpr& expr, Optional* *constant = IntImm(result->dtype, -result->value); return var.Eval(); } - return NullOpt; + return std::nullopt; } /******** Annotation ********/ @@ -249,7 +249,7 @@ inline Optional AnalyzeVarWithShift(const PrimExpr& expr, Optional* * \tparam TObjectRef The type of the annotation value * \param sref The sref to the block or the for loop * \param ann_key The annotation key to be looked up - * \return NullOpt if not found; otherwise the annotation value + * \return std::nullopt if not found; otherwise the annotation value */ template inline Optional GetAnn(const TStmtNode* stmt, const String& ann_key) { @@ -259,7 +259,7 @@ inline Optional GetAnn(const TStmtNode* stmt, const String& ann_key) return Downcast(ann.second); } } - return NullOpt; + return std::nullopt; } /*! @@ -267,7 +267,7 @@ inline Optional GetAnn(const TStmtNode* stmt, const String& ann_key) * \tparam TObjectRef The type of the annotation value * \param sref The sref to the block or the for loop * \param ann_key The annotation key to be looked up - * \return NullOpt if not found; otherwise the annotation value + * \return std::nullopt if not found; otherwise the annotation value */ template inline Optional GetAnn(const StmtSRef& sref, const String& ann_key) { diff --git a/src/tir/transforms/common_subexpr_elim.cc b/src/tir/transforms/common_subexpr_elim.cc index b6c52ec1a3be..fb24ebf099eb 100644 --- a/src/tir/transforms/common_subexpr_elim.cc +++ b/src/tir/transforms/common_subexpr_elim.cc @@ -29,9 +29,9 @@ #include "common_subexpr_elim.h" +#include +#include #include // For the class Pass and the class PassContext -#include -#include #include // For the analysis which gives the size of an expr #include #include diff --git a/src/tir/transforms/common_subexpr_elim_tools.cc b/src/tir/transforms/common_subexpr_elim_tools.cc index ba101ce4e70f..ce8aef4587dd 100644 --- a/src/tir/transforms/common_subexpr_elim_tools.cc +++ b/src/tir/transforms/common_subexpr_elim_tools.cc @@ -26,8 +26,8 @@ #include "common_subexpr_elim_tools.h" #include // For the arith::Analyzer::Simplify() method simplifying terms -#include // For the class Pass and the class PassContext -#include +#include +#include // For the class Pass and the class PassContext #include // For the ExprDeepEqual analysis #include #include diff --git a/src/tir/transforms/common_subexpr_elim_tools.h b/src/tir/transforms/common_subexpr_elim_tools.h index 841f1d65a6f6..58014e6a406d 100644 --- a/src/tir/transforms/common_subexpr_elim_tools.h +++ b/src/tir/transforms/common_subexpr_elim_tools.h @@ -26,7 +26,7 @@ #ifndef TVM_TIR_TRANSFORMS_COMMON_SUBEXPR_ELIM_TOOLS_H_ #define TVM_TIR_TRANSFORMS_COMMON_SUBEXPR_ELIM_TOOLS_H_ -#include +#include #include // For the ExprDeepEqual analysis #include #include diff --git a/src/tir/transforms/compact_buffer_region.cc b/src/tir/transforms/compact_buffer_region.cc index b18c07651000..543b687df0e8 100644 --- a/src/tir/transforms/compact_buffer_region.cc +++ b/src/tir/transforms/compact_buffer_region.cc @@ -537,7 +537,7 @@ struct BufferAllocInfo { std::vector dim_aligns; /*! * \brief The reallocated buffer with minimal size. - * \note The value if NullOpt if the buffer do not need reallocate (e.g parameter buffer). + * \note The value if std::nullopt if the buffer do not need reallocate (e.g parameter buffer). */ Buffer new_buffer; }; diff --git a/src/tir/transforms/default_gpu_schedule.cc b/src/tir/transforms/default_gpu_schedule.cc index 249003d2ad6c..2bf28abd2fcc 100644 --- a/src/tir/transforms/default_gpu_schedule.cc +++ b/src/tir/transforms/default_gpu_schedule.cc @@ -66,15 +66,15 @@ void ThreadBind(tir::Schedule sch, const tir::BlockRV& block, int64_t max_thread } // schedule the fused loop if (product > max_thread_per_block * max_threadblocks) { - Array splits = - sch->Split(fused, - /*factors=*/{NullOpt, Integer(max_threadblocks), Integer(max_thread_per_block)}); + Array splits = sch->Split( + fused, + /*factors=*/{std::nullopt, Integer(max_threadblocks), Integer(max_thread_per_block)}); sch->Reorder(/*ordered_loop_rvs=*/{splits[1], splits[2], splits[0]}); sch->Bind(splits[1], "blockIdx.x"); sch->Bind(splits[2], "threadIdx.x"); } else { - Array splits = - sch->Split(fused, /*factors=*/{NullOpt, Integer(std::min(product, max_thread_per_block))}); + Array splits = sch->Split( + fused, /*factors=*/{std::nullopt, Integer(std::min(product, max_thread_per_block))}); sch->Bind(splits[0], "blockIdx.x"); sch->Bind(splits[1], "threadIdx.x"); } diff --git a/src/tir/transforms/inject_permuted_layout.cc b/src/tir/transforms/inject_permuted_layout.cc index fd1e4a54e473..a5f29f624c41 100644 --- a/src/tir/transforms/inject_permuted_layout.cc +++ b/src/tir/transforms/inject_permuted_layout.cc @@ -103,7 +103,7 @@ class PermutedLayoutInjector : private IRMutatorWithAnalyzer { } static bool CheckAnnotation(const Any& annotation) { - if (auto* node = annotation.as()) { + if (auto* node = annotation.as()) { // Support string annotation for backward compatibility return GetRef(node) != ""; } else if (auto* node = annotation.as()) { diff --git a/src/tir/transforms/inject_software_pipeline.cc b/src/tir/transforms/inject_software_pipeline.cc index 5e003d173d65..d54223c85fd4 100644 --- a/src/tir/transforms/inject_software_pipeline.cc +++ b/src/tir/transforms/inject_software_pipeline.cc @@ -364,7 +364,7 @@ class PipelineRewriter : public StmtExprMutator { // introduce extra lowerbound when the loop length is smaller than num stages // to ensure the epilogue interval do not overlap the prologue interval. PrimExpr epigogue_start = pipeline_loop_->min + pipeline_loop_->extent; - Optional extra_epilogue_lower_bound = NullOpt; + Optional extra_epilogue_lower_bound = std::nullopt; if (max_stage_ > 1 && !analyzer_.CanProveGreaterEqual(pipeline_loop_->extent, max_stage_)) { if (is_const_int(epigogue_start)) { epigogue_start = max(epigogue_start, pipeline_loop_->min + max_stage_); @@ -811,7 +811,7 @@ class PipelineRewriter : public StmtExprMutator { * \return The result loop. */ Stmt EmitImpl(PrimExpr start, PrimExpr end, bool unroll_loop, - Optional extra_loop_lower_bound = NullOpt) { + Optional extra_loop_lower_bound = std::nullopt) { PrimExpr new_loop_var; PrimExpr extent = end - start; @@ -941,7 +941,7 @@ class PipelineRewriter : public StmtExprMutator { if (!is_unit_loop) { new_loop = For(Downcast(new_loop_var), pipeline_loop_->min, extent, unroll_loop ? ForKind::kUnrolled : pipeline_loop_->kind, std::move(new_loop), - NullOpt, preserved_annotations_); + std::nullopt, preserved_annotations_); } // Update producer heads in the global async states. @@ -957,7 +957,7 @@ class PipelineRewriter : public StmtExprMutator { async_states[stage_id].producer_head.value() + extent; } else { // Otherwise, invalidate the global producer head - async_states[stage_id].producer_head = NullOpt; + async_states[stage_id].producer_head = std::nullopt; } } diff --git a/src/tir/transforms/inject_virtual_thread.cc b/src/tir/transforms/inject_virtual_thread.cc index d9fc74f8ad18..d8df0b0e0509 100644 --- a/src/tir/transforms/inject_virtual_thread.cc +++ b/src/tir/transforms/inject_virtual_thread.cc @@ -343,7 +343,7 @@ class VTInjector : public arith::IRMutatorWithAnalyzer { visit_touched_var_ = false; ICHECK_EQ(max_loop_depth_, 0); Stmt then_case = this->VisitStmt(op->then_case); - Optional else_case = NullOpt; + Optional else_case = std::nullopt; if (op->else_case) { int temp = max_loop_depth_; max_loop_depth_ = 0; diff --git a/src/tir/transforms/inline_private_functions.cc b/src/tir/transforms/inline_private_functions.cc index 14672f568549..d14bb05406e7 100644 --- a/src/tir/transforms/inline_private_functions.cc +++ b/src/tir/transforms/inline_private_functions.cc @@ -155,7 +155,7 @@ class PrimFuncInliner : StmtExprMutator { PrimFunc VisitFunc(PrimFunc func) { current_target_ = func->GetAttr(tvm::attr::kTarget); auto new_body = VisitStmt(func->body); - current_target_ = NullOpt; + current_target_ = std::nullopt; if (!new_body.same_as(func->body)) { func.CopyOnWrite()->body = new_body; @@ -177,13 +177,13 @@ class PrimFuncInliner : StmtExprMutator { Optional GetInlinedFunction(const EvaluateNode* eval) { auto call = eval->value.as(); - if (!call) return NullOpt; + if (!call) return std::nullopt; auto gvar = call->op.as(); - if (!gvar) return NullOpt; + if (!gvar) return std::nullopt; auto opt_callee = inlinable_funcs_.Get(gvar.value()); - if (!opt_callee) return NullOpt; + if (!opt_callee) return std::nullopt; auto callee = opt_callee.value(); bool is_same_target = [&]() -> bool { @@ -194,7 +194,7 @@ class PrimFuncInliner : StmtExprMutator { return true; } }(); - if (!is_same_target) return NullOpt; + if (!is_same_target) return std::nullopt; Stmt inlined = InlineArguments(gvar.value(), callee, call->args); return VisitStmt(inlined); @@ -252,7 +252,7 @@ class PrimFuncInliner : StmtExprMutator { */ PSet removable_funcs_; - Optional current_target_ = NullOpt; + Optional current_target_ = std::nullopt; }; } // namespace diff --git a/src/tir/transforms/ir_utils.cc b/src/tir/transforms/ir_utils.cc index 3664abcf5612..f62a12bac2ed 100644 --- a/src/tir/transforms/ir_utils.cc +++ b/src/tir/transforms/ir_utils.cc @@ -600,7 +600,7 @@ Optional ConditionalBoundsContext::TrySolveCondition() { arith::Analyzer analyzer; PrimExpr condition = analyzer.Simplify(condition_); if (is_const_int(condition)) { - return NullOpt; + return std::nullopt; } Array equations; Array vars; @@ -644,7 +644,7 @@ Optional ConditionalBoundsContext::TrySolveCondition() { }; fvisit(condition); if (equations.empty() || vars.empty()) { - return NullOpt; + return std::nullopt; } // build dom ranges for related vars Map ranges; @@ -667,7 +667,7 @@ Optional ConditionalBoundsContext::TrySolveCondition() { arith::IntConstraints constraint(vars, ranges, equations); arith::IntConstraints result = arith::SolveInequalitiesToRange(constraint); if (!result->relations.empty()) { - return NullOpt; + return std::nullopt; } return std::move(result); } diff --git a/src/tir/transforms/lower_cross_thread_reduction.cc b/src/tir/transforms/lower_cross_thread_reduction.cc index 325d8e5bb578..37a31d204427 100644 --- a/src/tir/transforms/lower_cross_thread_reduction.cc +++ b/src/tir/transforms/lower_cross_thread_reduction.cc @@ -312,7 +312,7 @@ Stmt TransformReductionBlock(const BlockRealizeNode* realize, // }; Array ct_buffer_regions = f_create_buffer_regions(ct_buffers); - Optional> it_buffer_regions = NullOpt; + Optional> it_buffer_regions = std::nullopt; if (it_buffers.defined()) { it_buffer_regions = f_create_buffer_regions(it_buffers.value()); } @@ -342,7 +342,7 @@ Stmt TransformReductionBlock(const BlockRealizeNode* realize, // } // Stmt 2: do in-thread reduction { - Optional new_realize = NullOpt; + Optional new_realize = std::nullopt; // If need to generate in-thread reduction, // then replace `wb_buffers` with `it_buffers` accordingly in given BlockRealize // otherwise, directly remove given BlockRealize @@ -353,7 +353,7 @@ Stmt TransformReductionBlock(const BlockRealizeNode* realize, // new_block->name_hint = new_block->name_hint + "_in_thread"; new_block->body = BufferReplacer::Run(wb_buffers, it_buffers.value(), std::move(new_block->body)); - new_block->init = NullOpt; + new_block->init = std::nullopt; ObjectPtr n = make_object(*realize); n->block = Block(new_block); new_realize = BlockRealize(n); @@ -673,9 +673,9 @@ class CrossThreadReductionTransformer : public StmtMutator { Array combiner_lhs{nullptr}; Array combiner_rhs{nullptr}; std::tie(init_values, updates) = - GetInitValuesAndUpdatesFromReductionBlock(NullOpt, GetRef(block)); + GetInitValuesAndUpdatesFromReductionBlock(std::nullopt, GetRef(block)); std::tie(reducer, combiner_lhs, combiner_rhs) = - GetReducerAndCombinerLhsRhs(NullOpt, init_values, updates); + GetReducerAndCombinerLhsRhs(std::nullopt, init_values, updates); // Condition 4. All reduction buffers should be all local or all non-local. int is_local_buf = -1; @@ -815,7 +815,7 @@ class CrossThreadReductionTransformer : public StmtMutator { Array& new_buffers = block2new_buffers_[block_stack_.back()]; Array ct_buffers = MakeScratchpads(reduction_buffers, /*is_cross_thread_buffer=*/true); new_buffers.insert(new_buffers.end(), ct_buffers.begin(), ct_buffers.end()); - Optional> it_buffers = NullOpt; + Optional> it_buffers = std::nullopt; if (need_in_thread_reduction) { it_buffers = MakeScratchpads(reduction_buffers, /*is_cross_thread_buffer=*/false); new_buffers.insert(new_buffers.end(), it_buffers.value().begin(), it_buffers.value().end()); diff --git a/src/tir/transforms/lower_device_kernel_launch.cc b/src/tir/transforms/lower_device_kernel_launch.cc index 6eb196d2520e..bb63aeb0a337 100644 --- a/src/tir/transforms/lower_device_kernel_launch.cc +++ b/src/tir/transforms/lower_device_kernel_launch.cc @@ -143,7 +143,7 @@ class DeviceInfoCollector : public StmtVisitor { // The extent of each thread Map thread_extent; // The amount of dynamic shared memory used - Optional dyn_shmem_size{NullOpt}; + Optional dyn_shmem_size{std::nullopt}; }; class ReturnRemover : public StmtExprMutator { @@ -195,7 +195,7 @@ class DeviceKernelMutator : public StmtExprMutator { func.CopyOnWrite()->body = body; } - current_target_ = NullOpt; + current_target_ = std::nullopt; return func; } diff --git a/src/tir/transforms/lower_init_block.cc b/src/tir/transforms/lower_init_block.cc index 3e8fc204314d..8b450784a020 100644 --- a/src/tir/transforms/lower_init_block.cc +++ b/src/tir/transforms/lower_init_block.cc @@ -39,7 +39,7 @@ class InitBlockLower : public StmtMutator { Stmt init = DoLowering(block->init.value(), block->iter_vars); Stmt body = VisitStmt(block->body); auto n = CopyOnWrite(block); - n->init = NullOpt; + n->init = std::nullopt; n->body = SeqStmt::Flatten(init, body); return Block(n); } diff --git a/src/tir/transforms/lower_intrin.cc b/src/tir/transforms/lower_intrin.cc index c1b8a2e83a45..8e141128f67d 100644 --- a/src/tir/transforms/lower_intrin.cc +++ b/src/tir/transforms/lower_intrin.cc @@ -386,7 +386,7 @@ Pass LowerIntrin() { auto target = f->GetAttr(tvm::attr::kTarget); ICHECK(target.defined()) << "LowerIntrin: Require the target attribute"; arith::Analyzer analyzer; - auto mtriple = target.value()->GetAttr("mtriple", ""); + auto mtriple = target.value()->GetAttr("mtriple", ""); n->body = IntrinInjecter(&analyzer, target.value()->kind->name, mtriple.value())(std::move(n->body)); return f; diff --git a/src/tir/transforms/lower_opaque_block.cc b/src/tir/transforms/lower_opaque_block.cc index 215e4461d672..067e7d1b05d9 100644 --- a/src/tir/transforms/lower_opaque_block.cc +++ b/src/tir/transforms/lower_opaque_block.cc @@ -107,7 +107,7 @@ class OpaqueBlockLower : public StmtExprMutator { } else { // Case 3. An ordinary loop body = For(op->loop_var, std::move(min), std::move(extent), op->kind, std::move(body), - NullOpt, new_annotations); + std::nullopt, new_annotations); } // Step 5. Insert nested attrs for (auto it = pragma_attrs.rbegin(); it != pragma_attrs.rend(); ++it) { diff --git a/src/tir/transforms/lower_thread_allreduce.cc b/src/tir/transforms/lower_thread_allreduce.cc index dde33fa2678d..34b99fea0782 100644 --- a/src/tir/transforms/lower_thread_allreduce.cc +++ b/src/tir/transforms/lower_thread_allreduce.cc @@ -103,7 +103,7 @@ class ThreadAllreduceBuilder final : public StmtExprMutator { return new_buf; } - return NullOpt; + return std::nullopt; } Stmt VisitStmt_(const DeclBufferNode* op) final { @@ -294,8 +294,9 @@ class ThreadAllreduceBuilder final : public StmtExprMutator { PrimExpr mask = Call(mask_dtype, builtin::tvm_warp_activemask(), {}); if (reduce_extent <= warp_size_) { - std::tie(reduce_results, new_alloc_bufs) = MakeWarpAllreduce( - values, types, combiner, reduce_index, reduce_extent, group_index, mask, NullOpt, &seq); + std::tie(reduce_results, new_alloc_bufs) = + MakeWarpAllreduce(values, types, combiner, reduce_index, reduce_extent, group_index, + mask, std::nullopt, &seq); // Broadcast the reduction result from lane 0 to all other lanes. // This avoids to emit predicated stores, as all threads are @@ -324,8 +325,9 @@ class ThreadAllreduceBuilder final : public StmtExprMutator { } // 2. First round of allreduce. - std::tie(reduce_results, local_bufs) = MakeWarpAllreduce( - values, types, combiner, reduce_index, warp_size_, group_index, mask, NullOpt, &seq); + std::tie(reduce_results, local_bufs) = + MakeWarpAllreduce(values, types, combiner, reduce_index, warp_size_, group_index, mask, + std::nullopt, &seq); new_alloc_bufs.insert(new_alloc_bufs.end(), local_bufs.begin(), local_bufs.end()); // 3. Write allreduce results to staging buffer. diff --git a/src/tir/transforms/lower_tvm_builtin.cc b/src/tir/transforms/lower_tvm_builtin.cc index 0931edcc2ec1..a0478325e18a 100644 --- a/src/tir/transforms/lower_tvm_builtin.cc +++ b/src/tir/transforms/lower_tvm_builtin.cc @@ -39,7 +39,7 @@ namespace tir { class BuiltinLower : public StmtExprMutator { public: static PrimFunc Build(PrimFunc func) { - Optional device_type = NullOpt; + Optional device_type = std::nullopt; if (auto target = func->GetAttr(tvm::attr::kTarget)) { device_type = Integer(target.value()->kind->default_device_type); } @@ -49,7 +49,8 @@ class BuiltinLower : public StmtExprMutator { return func; } - explicit BuiltinLower(Optional device_type = NullOpt) : device_type_(device_type) {} + explicit BuiltinLower(Optional device_type = std::nullopt) + : device_type_(device_type) {} // NOTE: Right now, we make the following scoping requirement // for memory allocated by the following primitives @@ -650,8 +651,8 @@ class BuiltinLower : public StmtExprMutator { // The prepration sequence to be emitted before the current statement. std::vector> prep_seq_stack_; - Optional device_type_{NullOpt}; - Optional device_id_{NullOpt}; + Optional device_type_{std::nullopt}; + Optional device_id_{std::nullopt}; bool is_precheck_{false}; diff --git a/src/tir/transforms/make_packed_api.cc b/src/tir/transforms/make_packed_api.cc index 7f8dc60460b4..8ab5ff7a3fa8 100644 --- a/src/tir/transforms/make_packed_api.cc +++ b/src/tir/transforms/make_packed_api.cc @@ -123,7 +123,7 @@ class SubroutineCallRewriter : public StmtExprMutator { if (rewriter.made_change_) { return stmt; } else { - return NullOpt; + return std::nullopt; } } @@ -172,21 +172,21 @@ inline Stmt MakeAssertNotNull(PrimExpr ptr, std::string msg) { * \param func The function to be inspected * * \returns The global_symbol to be used for the function at call - * sites, or NullOpt if the function is to remain unchanged. + * sites, or std::nullopt if the function is to remain unchanged. */ Optional RequiresPackedAPI(const PrimFunc& func) { // A function with an explicit calling convention has already been // lowered, and should not be modified. if (auto opt = func->GetAttr(tvm::attr::kCallingConv)) { if (CallingConv(opt.value()->value) != CallingConv::kDefault) { - return NullOpt; + return std::nullopt; } } // Internal function calls do not need the ffi::Function API auto global_symbol = func->GetAttr(tvm::attr::kGlobalSymbol); if (!global_symbol.defined()) { - return NullOpt; + return std::nullopt; } return global_symbol; diff --git a/src/tir/transforms/make_unpacked_api.cc b/src/tir/transforms/make_unpacked_api.cc index 0cb072701cb5..26a40187fb86 100644 --- a/src/tir/transforms/make_unpacked_api.cc +++ b/src/tir/transforms/make_unpacked_api.cc @@ -51,7 +51,7 @@ class SubroutineCallRewriter : public StmtExprMutator { if (rewriter.made_change_) { return stmt; } else { - return NullOpt; + return std::nullopt; } } diff --git a/src/tir/transforms/memhammer_coalesce.cc b/src/tir/transforms/memhammer_coalesce.cc index 5ca20f57aa78..2be5e148fbfe 100644 --- a/src/tir/transforms/memhammer_coalesce.cc +++ b/src/tir/transforms/memhammer_coalesce.cc @@ -118,7 +118,7 @@ Stmt SplitBindVectorize(const Stmt& stmt, const ConstraintSet& constraints) { if (v.same_as(loop->loop_var)) { return substitute_value; } else { - return NullOpt; + return std::nullopt; } }); PrimExpr predicate = substitute_value < loop->extent; diff --git a/src/tir/transforms/memhammer_intermediate_stage.cc b/src/tir/transforms/memhammer_intermediate_stage.cc index 8d576b0258f4..2ecb740ba327 100644 --- a/src/tir/transforms/memhammer_intermediate_stage.cc +++ b/src/tir/transforms/memhammer_intermediate_stage.cc @@ -395,7 +395,7 @@ std::pair InsertCacheStage(Stmt stmt, bool is_write_cache, String new_loop->loop_var = new_loop_vars[i]; new_loop->body = generate_body; new_loop->kind = ForKind::kSerial; - new_loop->thread_binding = NullOpt; + new_loop->thread_binding = std::nullopt; new_loop->annotations = {}; generate_body = For(new_loop); } diff --git a/src/tir/transforms/memhammer_tensorcore_rewrite.cc b/src/tir/transforms/memhammer_tensorcore_rewrite.cc index 71f91af92fea..5a0d0fa2105c 100644 --- a/src/tir/transforms/memhammer_tensorcore_rewrite.cc +++ b/src/tir/transforms/memhammer_tensorcore_rewrite.cc @@ -42,7 +42,7 @@ std::pair> TileWmmaBlock(Stmt stmt) { arith::Analyzer analyzer; if (!analyzer.CanProveEqual(floormod(extent_last1, 16), 0) || !analyzer.CanProveEqual(floormod(extent_last2, 16), 0)) { - return std::make_pair(stmt, NullOpt); + return std::make_pair(stmt, std::nullopt); } } Var new_loop_vars[4] = { @@ -177,7 +177,7 @@ Stmt RewriteWmmaLoad(Stmt stmt) { /*6:*/ new_src_buffer->strides[new_src_buffer->strides.size() - 2], /*7:*/ StringImm(layout), })), - /*init=*/NullOpt, + /*init=*/std::nullopt, /*alloc_buffers=*/{}, /*match_buffers=*/ { @@ -280,7 +280,7 @@ Stmt RewriteWmmaStore(Stmt stmt) { }), /*6:*/ new_tgt_buffer->strides[0], /*7:*/ StringImm("row_major")})), - /*init=*/NullOpt, + /*init=*/std::nullopt, /*alloc_buffers=*/{}, /*match_buffers=*/ { @@ -366,7 +366,7 @@ std::pair> TileMmaToGlobalBlock(Stmt stmt) { // Only tile when both extent % 8 == 0 if (!analyzer.CanProveEqual(floormod(extent_last1, 8), 0) || !analyzer.CanProveEqual(floormod(extent_last2, 8), 0)) { - return std::make_pair(stmt, NullOpt); + return std::make_pair(stmt, std::nullopt); } } Var new_loop_vars[4] = { @@ -498,7 +498,7 @@ Stmt RewriteMmaStore(Stmt stmt) { {floordiv(tx, 4), floormod(tx, 4) * 2 + vec}), {floordiv(tx, 4), floormod(tx, 4) * 2 + vec}), /*annotations=*/{})), - /*init=*/NullOpt, + /*init=*/std::nullopt, /*alloc_buffers=*/{}, /*match_buffers=*/ { diff --git a/src/tir/transforms/plan_update_buffer_allocation_location.cc b/src/tir/transforms/plan_update_buffer_allocation_location.cc index 5ce8ade2085c..0845f4e3c5f5 100644 --- a/src/tir/transforms/plan_update_buffer_allocation_location.cc +++ b/src/tir/transforms/plan_update_buffer_allocation_location.cc @@ -212,7 +212,7 @@ class BufferAllocationLocator : public StmtExprMutator { /*writes=*/{}, /*name_hint=*/"", /*body=*/std::move(body), - /*init=*/NullOpt, + /*init=*/std::nullopt, /*alloc_buffers=*/alloc_buffers); ObjectPtr n = CopyOnWrite(opaque_block.get()); Array> access = diff --git a/src/tir/transforms/remap_thread_axis.cc b/src/tir/transforms/remap_thread_axis.cc index 519a3e1f80d8..3e0e8a112169 100644 --- a/src/tir/transforms/remap_thread_axis.cc +++ b/src/tir/transforms/remap_thread_axis.cc @@ -69,7 +69,7 @@ class ThreadAxisRewriter : private StmtExprMutator { std::unordered_map vmap_; }; -PrimFunc RemapThreadAxis(PrimFunc func, Map thread_map) { +PrimFunc RemapThreadAxis(PrimFunc func, Map thread_map) { std::unordered_map tmap; for (const auto& kv : thread_map) { tmap[kv.first] = kv.second; @@ -96,7 +96,7 @@ PrimFunc RemapThreadAxis(PrimFunc func, Map thread_map namespace transform { -Pass RemapThreadAxis(Map thread_map) { +Pass RemapThreadAxis(Map thread_map) { auto pass_func = [thread_map](PrimFunc f, IRModule m, PassContext ctx) { return RemapThreadAxis(std::move(f), thread_map); }; diff --git a/src/tir/transforms/renew_defs.cc b/src/tir/transforms/renew_defs.cc index 6098535fb5e8..db5bae8dfad5 100644 --- a/src/tir/transforms/renew_defs.cc +++ b/src/tir/transforms/renew_defs.cc @@ -116,7 +116,7 @@ class RenewDefMutator : public StmtExprMutator { std::bind(&RenewDefMutator::VisitMatchBuffer, this, std::placeholders::_1)); // Step 3. Visit body - Optional init = NullOpt; + Optional init = std::nullopt; if (op->init.defined()) { init = this->VisitStmt(op->init.value()); } diff --git a/src/tir/transforms/simplify.cc b/src/tir/transforms/simplify.cc index f518c61bc676..71843f1cf401 100644 --- a/src/tir/transforms/simplify.cc +++ b/src/tir/transforms/simplify.cc @@ -146,7 +146,7 @@ TVM_REGISTER_PASS_CONFIG_OPTION("tir.Simplify", SimplifyConfig); class StmtSimplifier : public IRMutatorWithAnalyzer { public: static PrimFunc Apply(PrimFunc func, Analyzer* analyzer, - Optional config_opt = NullOpt) { + Optional config_opt = std::nullopt) { auto config = config_opt.value_or(AttrsWithDefaultValues()); analyzer->rewrite_simplify.SetEnabledExtensions(config->GetEnabledExtensions()); @@ -327,7 +327,7 @@ class StmtSimplifier : public IRMutatorWithAnalyzer { if (const int64_t* as_int = as_const_int(condition)) { return Bool(*as_int); } else { - return NullOpt; + return std::nullopt; } } @@ -335,7 +335,7 @@ class StmtSimplifier : public IRMutatorWithAnalyzer { std::optional touch_pattern_; Map non_inlined_bindings_; - Optional current_stmt_{NullOpt}; + Optional current_stmt_{std::nullopt}; std::unordered_set used_in_buffer_def_; }; diff --git a/src/tir/transforms/unify_thread_binding.cc b/src/tir/transforms/unify_thread_binding.cc index 33d77c23353a..664bb9a1633c 100644 --- a/src/tir/transforms/unify_thread_binding.cc +++ b/src/tir/transforms/unify_thread_binding.cc @@ -76,7 +76,7 @@ class ThreadBindingUnifier : public StmtExprMutator { /*min=*/IntImm(dtype, 0), // /*extent=*/IntImm(dtype, 1), // /*kind=*/ForKind::kSerial, stmt, // - /*thread_binding=*/NullOpt, // + /*thread_binding=*/std::nullopt, // /*annotation=*/std::move(annotations)); } } diff --git a/src/tir/transforms/unsupported_dtype_legalize.cc b/src/tir/transforms/unsupported_dtype_legalize.cc index 047e80ea0e7b..da9d74abbe6a 100644 --- a/src/tir/transforms/unsupported_dtype_legalize.cc +++ b/src/tir/transforms/unsupported_dtype_legalize.cc @@ -779,8 +779,7 @@ Pass FP8ComputeLegalize(String promote_dtype_str) { if (CheckDataTypeSupport(target, "tvm.contrib.nvcc.supports_fp8")) { return f; } - return FP8ComputeLegalizer(DataType(runtime::StringToDLDataType(promote_dtype_str))) - .Legalize(f); + return FP8ComputeLegalizer(DataType(StringToDLDataType(promote_dtype_str))).Legalize(f); }; return CreatePrimFuncPass(pass_func, 0, "tir.FP8ComputeLegalize", {}); } diff --git a/src/tir/transforms/using_assume_to_reduce_branches.cc b/src/tir/transforms/using_assume_to_reduce_branches.cc index 3cd33b85905b..81b906786290 100644 --- a/src/tir/transforms/using_assume_to_reduce_branches.cc +++ b/src/tir/transforms/using_assume_to_reduce_branches.cc @@ -161,7 +161,7 @@ class ParseAssumeAndOvercompute : public IRMutatorWithAnalyzer { With analyzer_context; size_t old_num_constraints{0}; size_t new_num_constraints{0}; - Optional assume{NullOpt}; + Optional assume{std::nullopt}; // Disable default-generated copy/move assignment and constructors InternalConstraintContext(const InternalConstraintContext&) = delete; diff --git a/src/tir/transforms/vectorize_loop.cc b/src/tir/transforms/vectorize_loop.cc index 58ce6d61742a..3df73f0edb8d 100644 --- a/src/tir/transforms/vectorize_loop.cc +++ b/src/tir/transforms/vectorize_loop.cc @@ -769,7 +769,7 @@ class Vectorizer : public StmtMutator, public ExprFunctorVisitStmt(op->then_case); - Optional else_case = NullOpt; + Optional else_case = std::nullopt; if (op->else_case) { else_case = this->VisitStmt(op->else_case.value()); } diff --git a/tests/cpp-runtime/hexagon/hexagon_buffer_tests.cc b/tests/cpp-runtime/hexagon/hexagon_buffer_tests.cc index c23391d16846..6f9c9f0f6f7b 100644 --- a/tests/cpp-runtime/hexagon/hexagon_buffer_tests.cc +++ b/tests/cpp-runtime/hexagon/hexagon_buffer_tests.cc @@ -18,12 +18,13 @@ */ #include -#include +#include #include "../src/runtime/hexagon/hexagon_buffer.h" using namespace tvm::runtime; using namespace tvm::runtime::hexagon; +using namespace tvm::ffi; TEST(HexagonBuffer, default_scope) { Optional scope; diff --git a/tests/cpp-runtime/hexagon/hexagon_device_api_tests.cc b/tests/cpp-runtime/hexagon/hexagon_device_api_tests.cc index c6ce0c72f5e4..6211bd63dfbc 100644 --- a/tests/cpp-runtime/hexagon/hexagon_device_api_tests.cc +++ b/tests/cpp-runtime/hexagon/hexagon_device_api_tests.cc @@ -23,6 +23,7 @@ using namespace tvm::runtime; using namespace tvm::runtime::hexagon; +using namespace tvm::ffi; class HexagonDeviceAPITest : public ::testing::Test { protected: diff --git a/tests/cpp-runtime/hexagon/hexagon_user_dma_tests.cc b/tests/cpp-runtime/hexagon/hexagon_user_dma_tests.cc index e9c81fa91125..2e47473f8a17 100644 --- a/tests/cpp-runtime/hexagon/hexagon_user_dma_tests.cc +++ b/tests/cpp-runtime/hexagon/hexagon_user_dma_tests.cc @@ -23,6 +23,7 @@ using namespace tvm::runtime; using namespace tvm::runtime::hexagon; +using namespace tvm::ffi; class HexagonUserDMATest : public ::testing::Test { void SetUp() override { diff --git a/tests/cpp-runtime/hexagon/hexagon_vtcm_pool_tests.cc b/tests/cpp-runtime/hexagon/hexagon_vtcm_pool_tests.cc index 8240241eee26..3cf008c874ab 100644 --- a/tests/cpp-runtime/hexagon/hexagon_vtcm_pool_tests.cc +++ b/tests/cpp-runtime/hexagon/hexagon_vtcm_pool_tests.cc @@ -23,6 +23,7 @@ using namespace tvm::runtime; using namespace tvm::runtime::hexagon; +using namespace tvm::ffi; class HexagonVtcmPoolTest : public ::testing::Test { void SetUp() override { diff --git a/tests/cpp-runtime/opencl/aa_opencl_qcom_extn.cc b/tests/cpp-runtime/opencl/aa_opencl_qcom_extn.cc index 1f3dc2057aee..5073e49e3af0 100644 --- a/tests/cpp-runtime/opencl/aa_opencl_qcom_extn.cc +++ b/tests/cpp-runtime/opencl/aa_opencl_qcom_extn.cc @@ -21,7 +21,7 @@ // hence, crafted the filename accordingly #include -#include +#include #include "../src/runtime/opencl/opencl_common.h" diff --git a/tests/cpp-runtime/opencl/clml_memory_planner.cc b/tests/cpp-runtime/opencl/clml_memory_planner.cc index 3d4d9c41f40e..364eb5591e9c 100644 --- a/tests/cpp-runtime/opencl/clml_memory_planner.cc +++ b/tests/cpp-runtime/opencl/clml_memory_planner.cc @@ -18,7 +18,7 @@ */ #include -#include +#include #include diff --git a/tests/cpp-runtime/opencl/opencl_compile_to_bin.cc b/tests/cpp-runtime/opencl/opencl_compile_to_bin.cc index 4aa09d63fd48..b8e5b90ece7c 100644 --- a/tests/cpp-runtime/opencl/opencl_compile_to_bin.cc +++ b/tests/cpp-runtime/opencl/opencl_compile_to_bin.cc @@ -18,6 +18,9 @@ */ #include +#include +#include +#include #include #include @@ -27,6 +30,7 @@ using namespace tvm::runtime; using namespace tvm::runtime::cl; +using namespace tvm::ffi; namespace { // This kernel was generated by TVM for conv2d operation @@ -180,9 +184,9 @@ TEST_F(OpenCLCompileBin, SourceVsBinaryCompilationPerf) { module.InstallKernel(m_workspace, m_workspace->GetThreadEntry(), m_kernelNames[i], e); } Timestamp comp_end = std::chrono::high_resolution_clock::now(); - auto get_pre_compiled_f = - module.GetFunction("opencl.GetPreCompiledPrograms", GetObjectPtr(&module)); - bytes = get_pre_compiled_f().cast(); + auto get_pre_compiled_f = module.GetFunction("opencl.GetPreCompiledPrograms", + tvm::ffi::GetObjectPtr(&module)); + bytes = get_pre_compiled_f().cast(); std::chrono::duration duration = std::chrono::duration_cast(comp_end - comp_start); compileFromSourceTimeMS = duration.count() * 1e-6; @@ -192,7 +196,7 @@ TEST_F(OpenCLCompileBin, SourceVsBinaryCompilationPerf) { OpenCLModuleNode module(m_dataSrc, "cl", m_fmap, std::string()); module.Init(); module.GetFunction("opencl.SetPreCompiledPrograms", - GetObjectPtr(&module))(String(bytes)); + GetObjectPtr(&module))(tvm::String(bytes)); Timestamp comp_start = std::chrono::high_resolution_clock::now(); for (size_t i = 0; i < m_kernelNames.size(); ++i) { OpenCLModuleNode::KTRefEntry e = {i, 1}; diff --git a/tests/cpp-runtime/opencl/opencl_nativeptr.cc b/tests/cpp-runtime/opencl/opencl_nativeptr.cc index 8f894c4bffca..260effadea0b 100644 --- a/tests/cpp-runtime/opencl/opencl_nativeptr.cc +++ b/tests/cpp-runtime/opencl/opencl_nativeptr.cc @@ -18,7 +18,7 @@ */ #include -#include +#include #include #include diff --git a/tests/cpp-runtime/opencl/texture_copy_test.cc b/tests/cpp-runtime/opencl/texture_copy_test.cc index 701fec4d8baf..75147bb5571d 100644 --- a/tests/cpp-runtime/opencl/texture_copy_test.cc +++ b/tests/cpp-runtime/opencl/texture_copy_test.cc @@ -101,12 +101,12 @@ TEST_F(TextureCopyTest, ViewBufferAsBuffer) { DLDevice cl_dev = {kDLOpenCL, 0}; auto allocator = MemoryManager::GetOrCreateAllocator(cl_dev, AllocatorType::kPooled); - auto buffer = allocator->Alloc(cl_dev, ShapeTuple(shape), {kDLFloat, 32, 1}); + auto buffer = allocator->Alloc(cl_dev, ffi::Shape(shape), {kDLFloat, 32, 1}); auto stor = Storage(buffer, allocator); - auto opencl_memobj = stor->AllocNDArrayScoped(0, ShapeTuple(shape), {kDLFloat, 32, 1}, mem_scope); + auto opencl_memobj = stor->AllocNDArrayScoped(0, ffi::Shape(shape), {kDLFloat, 32, 1}, mem_scope); auto opencl_memview = - stor->AllocNDArrayScoped(0, ShapeTuple(same_shape), {kDLFloat, 32, 1}, mem_scope); + stor->AllocNDArrayScoped(0, ffi::Shape(same_shape), {kDLFloat, 32, 1}, mem_scope); std::random_device dev; std::mt19937 mt(dev()); @@ -158,12 +158,12 @@ TEST_F(TextureCopyTest, ViewBufferAsImage) { DLDevice cl_dev = {kDLOpenCL, 0}; auto allocator = MemoryManager::GetOrCreateAllocator(cl_dev, AllocatorType::kPooled); - auto buffer = allocator->Alloc(cl_dev, ShapeTuple(shape), {kDLFloat, 32, 1}); + auto buffer = allocator->Alloc(cl_dev, ffi::Shape(shape), {kDLFloat, 32, 1}); auto stor = Storage(buffer, allocator); - auto opencl_buf_obj = stor->AllocNDArrayScoped(0, ShapeTuple(shape), {kDLFloat, 32, 1}, "global"); + auto opencl_buf_obj = stor->AllocNDArrayScoped(0, ffi::Shape(shape), {kDLFloat, 32, 1}, "global"); auto opencl_img_obj = - stor->AllocNDArrayScoped(0, ShapeTuple(same_shape), {kDLFloat, 32, 1}, "global.texture"); + stor->AllocNDArrayScoped(0, ffi::Shape(same_shape), {kDLFloat, 32, 1}, "global.texture"); std::random_device dev; std::mt19937 mt(dev()); @@ -215,13 +215,13 @@ TEST_F(TextureCopyTest, ViewImageAsBuffer) { DLDevice cl_dev = {kDLOpenCL, 0}; auto allocator = MemoryManager::GetOrCreateAllocator(cl_dev, AllocatorType::kPooled); - auto buffer = allocator->Alloc(cl_dev, ShapeTuple(shape), {kDLFloat, 32, 1}); + auto buffer = allocator->Alloc(cl_dev, ffi::Shape(shape), {kDLFloat, 32, 1}); auto stor = Storage(buffer, allocator); auto opencl_img_obj = - stor->AllocNDArrayScoped(0, ShapeTuple(shape), {kDLFloat, 32, 1}, "global.texture"); + stor->AllocNDArrayScoped(0, ffi::Shape(shape), {kDLFloat, 32, 1}, "global.texture"); auto opencl_buf_obj = - stor->AllocNDArrayScoped(0, ShapeTuple(same_shape), {kDLFloat, 32, 1}, "global"); + stor->AllocNDArrayScoped(0, ffi::Shape(same_shape), {kDLFloat, 32, 1}, "global"); std::random_device dev; std::mt19937 mt(dev()); @@ -273,13 +273,13 @@ TEST_F(TextureCopyTest, ViewImageAsImage) { DLDevice cl_dev = {kDLOpenCL, 0}; auto allocator = MemoryManager::GetOrCreateAllocator(cl_dev, AllocatorType::kPooled); - auto buffer = allocator->Alloc(cl_dev, ShapeTuple(shape), {kDLFloat, 32, 1}); + auto buffer = allocator->Alloc(cl_dev, ffi::Shape(shape), {kDLFloat, 32, 1}); auto stor = Storage(buffer, allocator); auto opencl_img_obj_1 = - stor->AllocNDArrayScoped(0, ShapeTuple(shape), {kDLFloat, 32, 1}, "global.texture"); + stor->AllocNDArrayScoped(0, ffi::Shape(shape), {kDLFloat, 32, 1}, "global.texture"); auto opencl_img_obj_2 = - stor->AllocNDArrayScoped(0, ShapeTuple(same_shape), {kDLFloat, 32, 1}, "global.texture"); + stor->AllocNDArrayScoped(0, ffi::Shape(same_shape), {kDLFloat, 32, 1}, "global.texture"); std::random_device dev; std::mt19937 mt(dev()); diff --git a/tests/cpp/ir_functor_test.cc b/tests/cpp/ir_functor_test.cc index 9449787218cc..348792d6ff88 100644 --- a/tests/cpp/ir_functor_test.cc +++ b/tests/cpp/ir_functor_test.cc @@ -336,7 +336,7 @@ TEST(IRF, Substitute) { if (var.same_as(x)) { return y; } - return NullOpt; + return std::nullopt; }; BufferLoad new_buffer_load = Downcast(Substitute(buffer_load, f_subst)); ICHECK(new_buffer_load->buffer->data.same_as(y)); diff --git a/tests/cpp/nested_msg_test.cc b/tests/cpp/nested_msg_test.cc index 52bfa2cdd399..d552dae8f754 100644 --- a/tests/cpp/nested_msg_test.cc +++ b/tests/cpp/nested_msg_test.cc @@ -41,10 +41,10 @@ using namespace tvm::relax; TEST(NestedMsg, Basic) { // start with no annotation - relax::Var x("x", NullOpt), y("y", NullOpt); + relax::Var x("x", std::nullopt), y("y", std::nullopt); // constructor from array, T and nullopt. - NestedMsg msg({x, NullOpt, x}); + NestedMsg msg({x, std::nullopt, x}); EXPECT_TRUE(msg.IsNested()); EXPECT_FALSE(msg.IsLeaf()); @@ -64,11 +64,11 @@ TEST(NestedMsg, Basic) { // assignment // assign null - a0 = NullOpt; + a0 = std::nullopt; EXPECT_TRUE(a0 == nullptr); // assign array - a0 = {x, {x, NullOpt, y}}; + a0 = {x, {x, std::nullopt, y}}; EXPECT_TRUE(a0.IsNested()); auto t0 = a0.NestedArray()[1]; EXPECT_TRUE(t0.IsNested()); @@ -82,8 +82,8 @@ TEST(NestedMsg, Basic) { } TEST(NestedMsg, ForEachLeaf) { - relax::Var x("x", NullOpt), y("y", NullOpt); - NestedMsg msg = {x, {x, y}, NullOpt, {x, {x, y}}}; + relax::Var x("x", std::nullopt), y("y", std::nullopt); + NestedMsg msg = {x, {x, y}, std::nullopt, {x, {x, y}}}; int x_count = 0, y_count = 0; @@ -96,35 +96,36 @@ TEST(NestedMsg, ForEachLeaf) { } TEST(NestedMsg, Equal) { - relax::Var x("x", NullOpt), y("y", NullOpt); - relax::Var z("z", NullOpt); + relax::Var x("x", std::nullopt), y("y", std::nullopt); + relax::Var z("z", std::nullopt); auto fequal = [](Expr lhs, Expr rhs) { return lhs.same_as(rhs); }; using M = NestedMsg; - EXPECT_TRUE(Equal(M(NullOpt), M(NullOpt), fequal)); + EXPECT_TRUE(Equal(M(std::nullopt), M(std::nullopt), fequal)); EXPECT_TRUE(Equal(M(x), M(x), fequal)); EXPECT_TRUE(Equal(M({x, y}), M({x, y}), fequal)); - EXPECT_TRUE(Equal(M({x, NullOpt}), M({x, NullOpt}), fequal)); + EXPECT_TRUE(Equal(M({x, std::nullopt}), M({x, std::nullopt}), fequal)); - EXPECT_TRUE(Equal(M({x, {NullOpt, y}}), M({x, {NullOpt, y}}), fequal)); + EXPECT_TRUE(Equal(M({x, {std::nullopt, y}}), M({x, {std::nullopt, y}}), fequal)); - EXPECT_TRUE(Equal(M({x, {NullOpt, y}, {x, z}}), M({x, {NullOpt, y}, {x, z}}), fequal)); + EXPECT_TRUE(Equal(M({x, {std::nullopt, y}, {x, z}}), M({x, {std::nullopt, y}, {x, z}}), fequal)); // type mismatch - EXPECT_FALSE(Equal(M({x, {NullOpt, y}, x}), M({x, {NullOpt, y}, {x, z}}), fequal)); + EXPECT_FALSE(Equal(M({x, {std::nullopt, y}, x}), M({x, {std::nullopt, y}, {x, z}}), fequal)); - EXPECT_FALSE(Equal(M({x, {NullOpt, y}, {x, NullOpt}}), M({x, {NullOpt, y}, {x, z}}), fequal)); + EXPECT_FALSE(Equal(M({x, {std::nullopt, y}, {x, std::nullopt}}), + M({x, {std::nullopt, y}, {x, z}}), fequal)); - EXPECT_FALSE(Equal(M({x, {NullOpt, y}}), M({x, {NullOpt, y}, {x, z}}), fequal)); + EXPECT_FALSE(Equal(M({x, {std::nullopt, y}}), M({x, {std::nullopt, y}, {x, z}}), fequal)); - EXPECT_FALSE(Equal(M(x), M(NullOpt), fequal)); + EXPECT_FALSE(Equal(M(x), M(std::nullopt), fequal)); - EXPECT_FALSE(Equal(M(NullOpt), M(x), fequal)); + EXPECT_FALSE(Equal(M(std::nullopt), M(x), fequal)); EXPECT_FALSE(Equal(M(x), M(Array({x})), fequal)); @@ -136,7 +137,7 @@ TEST(NestedMsg, MapAndDecompose) { relax::Var y("y", PrimStructInfo(runtime::DataType::Int(32))); relax::Var z("z", PrimStructInfo(runtime::DataType::Int(64))); - BlockBuilder bb = BlockBuilder::Create(NullOpt); + BlockBuilder bb = BlockBuilder::Create(std::nullopt); relax::Expr t0 = bb->Normalize(Tuple({x, y})); relax::Expr t1 = bb->Normalize(Tuple({t0, x, z, t0})); @@ -158,12 +159,12 @@ TEST(NestedMsg, MapAndDecompose) { auto output2 = MapToNestedMsg(GetStructInfo(t1), [&](StructInfo sinfo) -> NestedMsg { const auto* prim_sinfo = sinfo.as(); - if (prim_sinfo == nullptr) return NullOpt; + if (prim_sinfo == nullptr) return std::nullopt; int bits = prim_sinfo->dtype.bits(); if (bits == 16) return c0; if (bits == 32) return c1; if (bits == 64) return c2; - return NullOpt; + return std::nullopt; }); EXPECT_TRUE(Equal(output2, expected, @@ -248,9 +249,9 @@ TEST(NestedMsg, CombineNestedMsg) { auto c1 = Integer(1); auto c2 = Integer(2); - NestedMsg lhs = {c0, {c0, c1}, NullOpt, {c0, {c1, c2}}}; - NestedMsg rhs = {c1, {c2, NullOpt}, NullOpt, {c1, {c2, c2}}}; - NestedMsg expected = {c1, {c2, c1}, NullOpt, {c1, {c2, c2}}}; + NestedMsg lhs = {c0, {c0, c1}, std::nullopt, {c0, {c1, c2}}}; + NestedMsg rhs = {c1, {c2, std::nullopt}, std::nullopt, {c1, {c2, c2}}}; + NestedMsg expected = {c1, {c2, c1}, std::nullopt, {c1, {c2, c2}}}; auto output = CombineNestedMsg(lhs, rhs, [](Integer x, Integer y) { if (x->value > y->value) return x; @@ -267,8 +268,8 @@ TEST(NestedMsg, MapNestedMsg) { auto c2 = Integer(2); auto c3 = Integer(3); - NestedMsg msg = {c0, {c0, c1}, NullOpt, {c0, {c2, c1}}}; - NestedMsg expected = {c3, {c3, NullOpt}, NullOpt, {c3, {c2, NullOpt}}}; + NestedMsg msg = {c0, {c0, c1}, std::nullopt, {c0, {c2, c1}}}; + NestedMsg expected = {c3, {c3, std::nullopt}, std::nullopt, {c3, {c2, std::nullopt}}}; auto output = MapNestedMsg(msg, [](Integer x) { if (x->value == 0) { diff --git a/tests/cpp/object_protocol_test.cc b/tests/cpp/object_protocol_test.cc index 3f76b1d2f108..18dff9eaece9 100644 --- a/tests/cpp/object_protocol_test.cc +++ b/tests/cpp/object_protocol_test.cc @@ -18,8 +18,8 @@ */ #include +#include #include -#include #include namespace tvm { @@ -66,6 +66,7 @@ TVM_REGISTER_OBJECT_TYPE(ObjAA); TEST(ObjectHierachy, Basic) { using namespace tvm::runtime; using namespace tvm::test; + using namespace tvm::ffi; ObjectRef refA(make_object()); ICHECK_EQ(refA->type_index(), ObjA::RuntimeTypeIndex()); diff --git a/tests/cpp/runtime/memory/memory_manager_tests.cc b/tests/cpp/runtime/memory/memory_manager_tests.cc index 47146d2000fc..bfe6f9644dde 100644 --- a/tests/cpp/runtime/memory/memory_manager_tests.cc +++ b/tests/cpp/runtime/memory/memory_manager_tests.cc @@ -77,7 +77,7 @@ TEST_F(TvmVMMemoryManagerTest, NaiveEmptyBasic) { EXPECT_EQ(allocator->UsedMemory(), 0); auto dt = DataType::Float(32); size_t nbytes = 1 * 3 * 6 * 6 * dt.bytes(); - ShapeTuple shape = {1, 3, 6, 6}; + ffi::Shape shape = {1, 3, 6, 6}; { auto ndarray = allocator->Empty(shape, dt, dev); EXPECT_EQ(allocator->UsedMemory(), nbytes); @@ -92,7 +92,7 @@ TEST_F(TvmVMMemoryManagerTest, BothAllocatorsCoexists) { EXPECT_EQ(nallocator->UsedMemory(), 0); auto dt = DataType::Float(32); size_t nbytes = 1 * 3 * 6 * 6 * dt.bytes(); - ShapeTuple shape = {1, 3, 6, 6}; + ffi::Shape shape = {1, 3, 6, 6}; { auto ndarray = nallocator->Empty(shape, dt, dev); EXPECT_EQ(nallocator->UsedMemory(), nbytes); @@ -125,7 +125,7 @@ TEST_F(TvmVMMemoryManagerTest, PooledEmptyBasic) { size_t nbytes = 1 * 3 * 6 * 6 * dt.bytes(); size_t page_size = PooledAllocator::kDefaultPageSize; size_t size = ((nbytes + page_size - 1) / page_size) * page_size; - ShapeTuple shape = {1, 3, 6, 6}; + ffi::Shape shape = {1, 3, 6, 6}; { auto ndarray = allocator->Empty(shape, dt, dev); EXPECT_EQ(allocator->UsedMemory(), size); @@ -139,7 +139,7 @@ TEST_F(TvmVMMemoryManagerTest, NaiveAllocWithShape) { EXPECT_EQ(allocator->UsedMemory(), 0); auto dt = DataType::Float(32); size_t nbytes = 1 * 3 * 6 * 6 * dt.bytes(); - ShapeTuple shape = {1, 3, 6, 6}; + ffi::Shape shape = {1, 3, 6, 6}; auto buff = allocator->Alloc(dev, shape, dt); EXPECT_EQ(allocator->UsedMemory(), nbytes); allocator->Free(buff); @@ -165,7 +165,7 @@ TEST_F(TvmVMMemoryManagerTest, PooledAllocWithShape) { size_t nbytes = 1 * 3 * 6 * 6 * dt.bytes(); size_t page_size = PooledAllocator::kDefaultPageSize; size_t size = ((nbytes + page_size - 1) / page_size) * page_size; - ShapeTuple shape = {1, 3, 6, 6}; + ffi::Shape shape = {1, 3, 6, 6}; auto buff = allocator->Alloc(dev, shape, dt); EXPECT_EQ(allocator->UsedMemory(), size); allocator->Free(buff); diff --git a/tests/cpp/tir_scalable_datatype.cc b/tests/cpp/tir_scalable_datatype.cc index a5eeab034f82..ccb43a81d8f1 100644 --- a/tests/cpp/tir_scalable_datatype.cc +++ b/tests/cpp/tir_scalable_datatype.cc @@ -88,7 +88,7 @@ TEST(ScalableDataType, TestScalableDataTypeToString) { TEST(ScalableDataType, TestStringToScalableDataType) { std::string scalable_type_str = "int32xvscalex4"; - EXPECT_EQ(tvm::DataType(tvm::runtime::StringToDLDataType(scalable_type_str)), + EXPECT_EQ(tvm::DataType(tvm::ffi::StringToDLDataType(scalable_type_str)), tvm::DataType(kDLInt, 32, 4, true)); } @@ -97,7 +97,7 @@ TEST(ScalableDataType, TestInvalidStringToScalableDataType) { EXPECT_THROW( { try { - tvm::runtime::StringToDLDataType(scalable_type_str); + tvm::ffi::StringToDLDataType(scalable_type_str); } catch (const tvm::ffi::Error& e) { EXPECT_THAT(e.what(), HasSubstr("unknown dtype `int32x4xvscale`")); throw; diff --git a/tests/python/runtime/test_runtime_rpc.py b/tests/python/runtime/test_runtime_rpc.py index 88e9481c4c07..604d8eb42c3c 100644 --- a/tests/python/runtime/test_runtime_rpc.py +++ b/tests/python/runtime/test_runtime_rpc.py @@ -428,9 +428,9 @@ def run_arr_test(): @tvm.testing.requires_rpc def test_rpc_return_remote_object(): def check(client, is_local): - make_shape = client.get_function("runtime.ShapeTuple") - get_elem = client.get_function("runtime.GetShapeTupleElem") - get_size = client.get_function("runtime.GetShapeTupleSize") + make_shape = client.get_function("ffi.Shape") + get_elem = client.get_function("runtime.GetShapeElem") + get_size = client.get_function("runtime.GetShapeSize") shape = make_shape(2, 3) assert shape.type_key == "runtime.RPCObjectRef" assert get_elem(shape, 0) == 2 diff --git a/tests/python/testing/test_type_annotation_checker.py b/tests/python/testing/test_type_annotation_checker.py index 9af356b97198..42ce1e103903 100644 --- a/tests/python/testing/test_type_annotation_checker.py +++ b/tests/python/testing/test_type_annotation_checker.py @@ -46,7 +46,7 @@ def str_func(x: str) -> str: [5], [], # Tuples are allowed to be used as lists, because both are - # represented in FFI as tvm::runtime::Array. + # represented in FFI as tvm::Array. (1, 2, 3), ], "negative_cases": [ diff --git a/web/emcc/wasm_runtime.cc b/web/emcc/wasm_runtime.cc index b8ebadff4f5c..b208daed51d3 100644 --- a/web/emcc/wasm_runtime.cc +++ b/web/emcc/wasm_runtime.cc @@ -175,7 +175,7 @@ TVM_REGISTER_GLOBAL("tvmjs.runtime.ArrayConcat") std::vector data; for (int i = 0; i < args.size(); ++i) { // Get i-th TVMArray - auto* arr_i = args[i].as(); + auto* arr_i = args[i].as(); ICHECK(arr_i != nullptr); for (size_t j = 0; j < arr_i->size(); ++j) { // Push back each j-th element of the i-th array