From 32bc8b88d945022b054aa75e700cb5fe044edfc0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E6=98=A5=E4=B9=94?= <83450930+Liyulingyue@users.noreply.github.com> Date: Sat, 8 Jul 2023 04:21:51 +0800 Subject: [PATCH] [CodeStyle][CINN] ruff F401 and F403 in python/cinn (#55182) Co-authored-by: SigureMo --- pyproject.toml | 4 - python/cinn/__init__.py | 173 +++++++++++++++++++++++++++++++- python/cinn/backends.py | 6 +- python/cinn/common.py | 18 +++- python/cinn/framework.py | 10 +- python/cinn/frontend.py | 14 ++- python/cinn/ir/__init__.py | 110 +++++++++++++++++++- python/cinn/lang.py | 20 +++- python/cinn/optim.py | 2 +- python/cinn/pe.py | 68 ++++++++++++- python/cinn/poly.py | 10 +- python/cinn/runtime.py | 55 +++++++++- python/cinn/utils.py | 17 +++- python/cinn/version/__init__.py | 2 +- 14 files changed, 486 insertions(+), 23 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 6ab8c3fd1df..f098e720f7f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -98,10 +98,6 @@ ignore = [ # Ignore unnecessary lambda in dy2st unittest test_lambda "test/dygraph_to_static/test_lambda.py" = ["PLC3002"] # Temporarily ignore CINN files, it will fix later -"python/cinn/**" = [ - "F401", - "F403", -] "test/cinn/**" = [ "F403", ] diff --git a/python/cinn/__init__.py b/python/cinn/__init__.py index a978d9e4616..9411b774e38 100644 --- a/python/cinn/__init__.py +++ b/python/cinn/__init__.py @@ -21,9 +21,172 @@ cuhfile = os.path.join(runtime_include_dir, "cinn_cuda_runtime_source.cuh") if os.path.exists(cuhfile): os.environ.setdefault('runtime_include_dir', runtime_include_dir) -from .core_api.common import * -from .core_api.backends import * -from .core_api.poly import * -from .core_api.ir import * -from .core_api.lang import * +from .common import ( # noqa: F401 + BFloat16, + Bool, + CINNValue, + CINNValuePack, + DefaultHostTarget, + DefaultNVGPUTarget, + DefaultTarget, + Float, + Float16, + Int, + RefCount, + Shared_CINNValuePack_, + String, + Target, + Type, + UInt, + Void, + _CINNValuePack_, + get_target, + is_compiled_with_cuda, + is_compiled_with_cudnn, + make_const, + reset_name_id, + set_target, + type_of, +) +from .backends import ( # noqa: F401 + Compiler, + ExecutionEngine, + ExecutionOptions, +) +from .poly import ( # noqa: F401 + Condition, + Iterator, + SharedStage, + SharedStageMap, + Stage, + StageMap, + create_stages, +) +from .ir import ( # noqa: F401 + Add, + And, + Args, + Argument, + BinaryOpNodeAdd, + BinaryOpNodeAnd, + BinaryOpNodeDiv, + BinaryOpNodeEQ, + BinaryOpNodeFracOp, + BinaryOpNodeGE, + BinaryOpNodeGT, + BinaryOpNodeLE, + BinaryOpNodeLT, + BinaryOpNodeMax, + BinaryOpNodeMin, + BinaryOpNodeMod, + BinaryOpNodeMul, + BinaryOpNodeNE, + BinaryOpNodeOr, + BinaryOpNodeSub, + Block, + Call, + CallOp, + CallType, + Cast, + ComputeOp, + Div, + EQ, + Expr, + ExprNodeAdd, + ExprNodeAnd, + ExprNodeBlock, + ExprNodeCall, + ExprNodeCast, + ExprNodeDiv, + ExprNodeEQ, + ExprNodeFloatImm, + ExprNodeFracOp, + ExprNodeGE, + ExprNodeGT, + ExprNodeIntImm, + ExprNodeLE, + ExprNodeLT, + ExprNodeLet, + ExprNodeLoad, + ExprNodeMax, + ExprNodeMin, + ExprNodeMinus, + ExprNodeMod, + ExprNodeMul, + ExprNodeNE, + ExprNodeNot, + ExprNodeOr, + ExprNodeProduct, + ExprNodeReduce, + ExprNodeSelect, + ExprNodeStore, + ExprNodeStringImm, + ExprNodeSub, + ExprNodeSum, + ExprNodeUIntImm, + ExprNode_Module_, + ExprNode_Tensor_, + ExprNode_Var_, + FloatImm, + FracOp, + GE, + GT, + IRVisitor, + IntImm, + IrNode, + IrNodeRef, + IrNodeTy, + LE, + LT, + Let, + Load, + LoadStoreAddrMnger, + LoweredFunc, + Max, + Min, + Minus, + Mod, + Mul, + NE, + Not, + Operation, + Or, + PackedFunc, + PlaceholderOp, + Product, + Reduce, + Registry, + Select, + SharedIrNode, + Store, + StringImm, + Sub, + Sum, + Tensor, + UIntImm, + UnaryOpNodeMinus, + UnaryOpNodeNot, + Var, + _Module_, + _Tensor_, + _Var_, +) +from .lang import ( # noqa: F401 + Buffer, + Module, + Placeholder, + ReturnType, + call_extern, + call_lowered, + compute, + create_placeholder, + lower, + lower_vec, + reduce_all, + reduce_any, + reduce_max, + reduce_min, + reduce_mul, + reduce_sum, +) from .version import full_version as __version__ diff --git a/python/cinn/backends.py b/python/cinn/backends.py index 481e14c6f85..6395d209586 100644 --- a/python/cinn/backends.py +++ b/python/cinn/backends.py @@ -12,4 +12,8 @@ # See the License for the specific language governing permissions and # limitations under the License. -from .core_api.backends import ExecutionEngine, ExecutionOptions +from .core_api.backends import ( # noqa: F401 + Compiler, + ExecutionEngine, + ExecutionOptions, +) diff --git a/python/cinn/common.py b/python/cinn/common.py index ae089cfce2d..6f0f8e8c593 100644 --- a/python/cinn/common.py +++ b/python/cinn/common.py @@ -12,16 +12,30 @@ # See the License for the specific language governing permissions and # limitations under the License. -from .core_api.common import * -from .core_api.common import ( +from .core_api.common import ( # noqa: F401 + BFloat16, Bool, CINNValue, + CINNValuePack, + DefaultHostTarget, + DefaultNVGPUTarget, + DefaultTarget, Float, + Float16, Int, + RefCount, + Shared_CINNValuePack_, String, Target, Type, UInt, Void, + _CINNValuePack_, + get_target, + is_compiled_with_cuda, + is_compiled_with_cudnn, make_const, + reset_name_id, + set_target, + type_of, ) diff --git a/python/cinn/framework.py b/python/cinn/framework.py index 54ac8f70feb..5ea4ef7c4af 100644 --- a/python/cinn/framework.py +++ b/python/cinn/framework.py @@ -12,4 +12,12 @@ # See the License for the specific language governing permissions and # limitations under the License. -from .core_api.framework import * +from .core_api.framework import ( # noqa: F401 + NodeAttr, + Operator, + OpValueType, + OpValueType1, + Scope, + SharedTensor, + Tensor, +) diff --git a/python/cinn/frontend.py b/python/cinn/frontend.py index bb340aa879e..c1c309f3f5c 100644 --- a/python/cinn/frontend.py +++ b/python/cinn/frontend.py @@ -12,4 +12,16 @@ # See the License for the specific language governing permissions and # limitations under the License. -from .core_api.frontend import * +from .core_api.frontend import ( # noqa: F401 + Computation, + Instruction, + Interpreter, + NetBuilder, + PaddleModelConvertor, + Placeholder, + Program, + Variable, + get_default_graph_pass, + get_default_opfusion_pass, + get_default_program_pass, +) diff --git a/python/cinn/ir/__init__.py b/python/cinn/ir/__init__.py index 7d09bb66e8a..b05b2323007 100644 --- a/python/cinn/ir/__init__.py +++ b/python/cinn/ir/__init__.py @@ -12,7 +12,115 @@ # See the License for the specific language governing permissions and # limitations under the License. -from ..core_api.ir import * +from ..core_api.ir import ( # noqa: F401 + Add, + And, + Args, + Argument, + BinaryOpNodeAdd, + BinaryOpNodeAnd, + BinaryOpNodeDiv, + BinaryOpNodeEQ, + BinaryOpNodeFracOp, + BinaryOpNodeGE, + BinaryOpNodeGT, + BinaryOpNodeLE, + BinaryOpNodeLT, + BinaryOpNodeMax, + BinaryOpNodeMin, + BinaryOpNodeMod, + BinaryOpNodeMul, + BinaryOpNodeNE, + BinaryOpNodeOr, + BinaryOpNodeSub, + Block, + Call, + CallOp, + CallType, + Cast, + ComputeOp, + Div, + EQ, + Expr, + ExprNodeAdd, + ExprNodeAnd, + ExprNodeBlock, + ExprNodeCall, + ExprNodeCast, + ExprNodeDiv, + ExprNodeEQ, + ExprNodeFloatImm, + ExprNodeFracOp, + ExprNodeGE, + ExprNodeGT, + ExprNodeIntImm, + ExprNodeLE, + ExprNodeLT, + ExprNodeLet, + ExprNodeLoad, + ExprNodeMax, + ExprNodeMin, + ExprNodeMinus, + ExprNodeMod, + ExprNodeMul, + ExprNodeNE, + ExprNodeNot, + ExprNodeOr, + ExprNodeProduct, + ExprNodeReduce, + ExprNodeSelect, + ExprNodeStore, + ExprNodeStringImm, + ExprNodeSub, + ExprNodeSum, + ExprNodeUIntImm, + ExprNode_Module_, + ExprNode_Tensor_, + ExprNode_Var_, + FloatImm, + FracOp, + GE, + GT, + IRVisitor, + IntImm, + IrNode, + IrNodeRef, + IrNodeTy, + LE, + LT, + Let, + Load, + LoadStoreAddrMnger, + LoweredFunc, + Max, + Min, + Minus, + Mod, + Mul, + NE, + Not, + Operation, + Or, + PackedFunc, + PlaceholderOp, + Product, + Reduce, + Registry, + Select, + SharedIrNode, + Store, + StringImm, + Sub, + Sum, + Tensor, + UIntImm, + UnaryOpNodeMinus, + UnaryOpNodeNot, + Var, + _Module_, + _Tensor_, + _Var_, +) def get_global_func(name): diff --git a/python/cinn/lang.py b/python/cinn/lang.py index bee58107e05..9cf3c1d1179 100644 --- a/python/cinn/lang.py +++ b/python/cinn/lang.py @@ -12,5 +12,21 @@ # See the License for the specific language governing permissions and # limitations under the License. -from .core_api.lang import * -from .core_api.lang import Buffer, compute, lower +from .core_api.lang import ( # noqa: F401 + Buffer, + Module, + Placeholder, + ReturnType, + call_extern, + call_lowered, + compute, + create_placeholder, + lower, + lower_vec, + reduce_all, + reduce_any, + reduce_max, + reduce_min, + reduce_mul, + reduce_sum, +) diff --git a/python/cinn/optim.py b/python/cinn/optim.py index c1c77a9a6cf..12f9786e9f8 100644 --- a/python/cinn/optim.py +++ b/python/cinn/optim.py @@ -12,4 +12,4 @@ # See the License for the specific language governing permissions and # limitations under the License. -from .core_api.optim import ir_copy, simplify +from .core_api.optim import ir_copy, simplify # noqa: F401 diff --git a/python/cinn/pe.py b/python/cinn/pe.py index 25dd5a77915..34e0bfb84cb 100644 --- a/python/cinn/pe.py +++ b/python/cinn/pe.py @@ -12,4 +12,70 @@ # See the License for the specific language governing permissions and # limitations under the License. -from .core_api.pe import * +from .core_api.pe import ( # noqa: F401 + abs, + acos, + acosh, + add, + asin, + asinh, + atan, + atan2, + atanh, + bitwise_and, + bitwise_not, + bitwise_or, + bitwise_xor, + ceil, + cos, + cosh, + divide, + equal, + erf, + exp, + floor, + floor_divide, + greater, + greater_equal, + identity, + isfinite, + isinf, + isnan, + left_shift, + less, + less_equal, + log, + log2, + log10, + logical_and, + logical_not, + logical_or, + logical_xor, + matmul, + matmul_mkl, + max, + min, + mod, + multiply, + negative, + not_equal, + reduce_all, + reduce_any, + reduce_max, + reduce_min, + reduce_prod, + reduce_sum, + remainder, + right_shift, + round, + rsqrt, + sigmoid, + sign, + sin, + sinh, + sqrt, + subtract, + tan, + tanh, + trunc, +) diff --git a/python/cinn/poly.py b/python/cinn/poly.py index 91c8b479402..7bc2bf32fb3 100644 --- a/python/cinn/poly.py +++ b/python/cinn/poly.py @@ -12,4 +12,12 @@ # See the License for the specific language governing permissions and # limitations under the License. -from .core_api.poly import create_stages +from .core_api.poly import ( # noqa: F401 + Condition, + Iterator, + SharedStage, + SharedStageMap, + Stage, + StageMap, + create_stages, +) diff --git a/python/cinn/runtime.py b/python/cinn/runtime.py index 33eb9acb88b..47bd7247479 100644 --- a/python/cinn/runtime.py +++ b/python/cinn/runtime.py @@ -12,4 +12,57 @@ # See the License for the specific language governing permissions and # limitations under the License. -from .core_api.runtime import * +from .core_api.runtime import ( # noqa: F401 + VoidPointer, + cinn_arm_device, + cinn_bool_t, + cinn_buffer_copy, + cinn_buffer_copy_to_device, + cinn_buffer_copy_to_host, + cinn_buffer_free, + cinn_buffer_get_data_const_handle, + cinn_buffer_get_data_handle, + cinn_buffer_kind_t, + cinn_buffer_load_float32, + cinn_buffer_load_float64, + cinn_buffer_malloc, + cinn_buffer_on_device, + cinn_buffer_on_host, + cinn_buffer_t, + cinn_device_interface_t, + cinn_device_kind_t, + cinn_device_release, + cinn_device_sync, + cinn_float32_t, + cinn_float64_t, + cinn_int8_t, + cinn_int32_t, + cinn_int64_t, + cinn_opencl_device, + cinn_pod_value_t, + cinn_pod_value_to_buffer_p, + cinn_pod_value_to_double, + cinn_pod_value_to_float, + cinn_pod_value_to_int8, + cinn_pod_value_to_int32, + cinn_pod_value_to_int64, + cinn_pod_value_to_void_p, + cinn_type_code_t, + cinn_type_float, + cinn_type_handle, + cinn_type_int, + cinn_type_t, + cinn_type_uint, + cinn_type_unk, + cinn_uint32_t, + cinn_uint64_t, + cinn_unk_device, + cinn_unk_t, + cinn_value_t, + cinn_x86_device, + cinn_x86_device_interface, + clear_seed, + nullptr, + seed, + set_cinn_cudnn_deterministic, +) diff --git a/python/cinn/utils.py b/python/cinn/utils.py index 8c44cc2a546..35cea7e9e0b 100644 --- a/python/cinn/utils.py +++ b/python/cinn/utils.py @@ -12,4 +12,19 @@ # See the License for the specific language governing permissions and # limitations under the License. -from .core_api.utils import * +from .core_api.utils import ( # noqa: F401 + EventType, + HostEvent, + HostEventRecorder, + ProfilerHelper, + kCodeGen, + kCompile, + kCompute, + kFusePass, + kGraph, + kInstruction, + kOptimize, + kOrdinary, + kProgram, + kSchedule, +) diff --git a/python/cinn/version/__init__.py b/python/cinn/version/__init__.py index ad6a9882ea5..766bdeacbad 100644 --- a/python/cinn/version/__init__.py +++ b/python/cinn/version/__init__.py @@ -13,6 +13,6 @@ # limitations under the License. try: - from .info import * + from .info import * # noqa: F403 except: full_version = 'Unknown' -- GitLab