已合并
foreach_addcdiv/mul.scalarlist, foreach_addcdiv/mul.Tensor代码回退 #1868
AtomGit-Bot创建于 2024年9月24日
foreach_addcdiv/mul.scalarlist, foreach_addcdiv/mul.Tensor代码回退 #1868
已合并
从refs/pull/1868/head合入到master
共 4 个文件变更+36-153
| @@ -19,68 +19,13 @@ | |||
| 19 | namespace op_api { | 19 | namespace op_api { |
| 20 | using npu_preparation = at_npu::native::OpPreparation; | 20 | using npu_preparation = at_npu::native::OpPreparation; |
| 21 | 21 | ||
| 22 | -void _split_and_exec_npu_cmd_addcdiv(const at::TensorList input, | ||
| 23 | - const at::TensorList tensors1, | ||
| 24 | - const at::TensorList tensors2, | ||
| 25 | - at::ArrayRef<at::Scalar> scalars, | ||
| 26 | - at::TensorList result, | ||
| 27 | - bool is_inplace) | ||
| 28 | -{ | ||
| 29 | - size_t tensor_count = input.size(); | ||
| 30 | - size_t max_tensor_count = is_inplace ? 16 : 12; | ||
| 31 | - size_t loop_time = tensor_count / max_tensor_count; | ||
| 32 | - size_t remaining_count = tensor_count % max_tensor_count; | ||
| 33 | - size_t data_count = max_tensor_count; | ||
| 34 | - if (remaining_count > 0) { | ||
| 35 | - loop_time++; | ||
| 36 | - } | ||
| 37 | - | ||
| 38 | - if (tensor_count <= max_tensor_count) { | ||
| 39 | - EXEC_NPU_CMD(aclnnForeachAddcdivScalarList, input, tensors1, tensors2, scalars, result); | ||
| 40 | - return; | ||
| 41 | - } | ||
| 42 | - for (size_t i = 0; i < loop_time; i++) { | ||
| 43 | - if (i == loop_time - 1 && remaining_count > 0) | ||
| 44 | - data_count = remaining_count; | ||
| 45 | - at::TensorList temp_input(input.data() + i * max_tensor_count, data_count); | ||
| 46 | - at::TensorList temp_tensors1(tensors1.data() + i * max_tensor_count, data_count); | ||
| 47 | - at::TensorList temp_tensors2(tensors2.data() + i * max_tensor_count, data_count); | ||
| 48 | - at::ArrayRef<at::Scalar> temp_scalars(scalars.data() + i * max_tensor_count, data_count); | ||
| 49 | - at::TensorList temp_result(result.data() + i * max_tensor_count, data_count); | ||
| 50 | - EXEC_NPU_CMD(aclnnForeachAddcdivScalarList, temp_input, temp_tensors1, temp_tensors2, temp_scalars, temp_result); | ||
| 51 | - } | ||
| 52 | -} | ||
| 53 | - | ||
| 54 | std::vector<at::Tensor> _foreach_addcdiv(const at::TensorList input, | 22 | std::vector<at::Tensor> _foreach_addcdiv(const at::TensorList input, |
| 55 | const at::TensorList tensors1, | 23 | const at::TensorList tensors1, |
| 56 | const at::TensorList tensors2, | 24 | const at::TensorList tensors2, |
| 57 | at::ArrayRef<at::Scalar> scalars) | 25 | at::ArrayRef<at::Scalar> scalars) |
| 58 | { | 26 | { |
| 59 | - static const bool is_support_nd_out = (c10_npu::GetSocVersion() >= c10_npu::SocVersion::Ascend910B1 && | ||
| 60 | - c10_npu::GetSocVersion() < c10_npu::SocVersion::Ascend310B1) || | ||
| 61 | - (c10_npu::GetSocVersion() > c10_npu::SocVersion::Ascend310B4); | ||
| 62 | - if (!is_support_nd_out) { | ||
| 63 | - return at::native::foreach_tensor_addcdiv_scalarlist_slow(input, tensors1, tensors2, scalars); | ||
| 64 | - } | ||
| 65 | - | ||
| 66 | at::native::check_foreach_api_restrictions(input, tensors1, tensors2, scalars); | 27 | at::native::check_foreach_api_restrictions(input, tensors1, tensors2, scalars); |
| 67 | - if (!at::native::can_use_fast_route({input, tensors1, tensors2}) || | 28 | + return at::native::foreach_tensor_addcdiv_scalarlist_slow(input, tensors1, tensors2, scalars); |
| 68 | - at::native::has_integral_tensor(input, true)) { | ||
| 69 | - return at::native::foreach_tensor_addcdiv_scalarlist_slow(input, tensors1, tensors2, scalars); | ||
| 70 | - } | ||
| 71 | - | ||
| 72 | - auto scalar_type = input[0].scalar_type(); | ||
| 73 | - | ||
| 74 | - std::vector<at::Tensor> result; | ||
| 75 | - result.reserve(input.size()); | ||
| 76 | - for (const at::Tensor &tensor : input) { | ||
| 77 | - auto output_size = op_infer::input_same_output_size(tensor); | ||
| 78 | - result.push_back(npu_preparation::apply_tensor_without_format(output_size, tensor.options().dtype(scalar_type))); | ||
| 79 | - } | ||
| 80 | - at::TensorList result_ = at::TensorList(result); | ||
| 81 | - _split_and_exec_npu_cmd_addcdiv(input, tensors1, tensors2, scalars, result_, false); | ||
| 82 | - | ||
| 83 | - return result; | ||
| 84 | } | 29 | } |
| 85 | 30 | ||
| 86 | void _foreach_addcdiv_(const at::TensorList input, | 31 | void _foreach_addcdiv_(const at::TensorList input, |
| @@ -88,19 +33,7 @@ void _foreach_addcdiv_(const at::TensorList input, | |||
| 88 | const at::TensorList tensors2, | 33 | const at::TensorList tensors2, |
| 89 | at::ArrayRef<at::Scalar> scalars) | 34 | at::ArrayRef<at::Scalar> scalars) |
| 90 | { | 35 | { |
| 91 | - static const bool is_support_nd_out = (c10_npu::GetSocVersion() >= c10_npu::SocVersion::Ascend910B1 && | ||
| 92 | - c10_npu::GetSocVersion() < c10_npu::SocVersion::Ascend310B1) || | ||
| 93 | - (c10_npu::GetSocVersion() > c10_npu::SocVersion::Ascend310B4); | ||
| 94 | - if (!is_support_nd_out) { | ||
| 95 | - return at::native::foreach_tensor_addcdiv_scalarlist_slow_(input, tensors1, tensors2, scalars); | ||
| 96 | - } | ||
| 97 | - | ||
| 98 | at::native::check_foreach_api_restrictions(input, tensors1, tensors2, scalars); | 36 | at::native::check_foreach_api_restrictions(input, tensors1, tensors2, scalars); |
| 99 | - if (!at::native::can_use_fast_route({input, tensors1, tensors2}) || | 37 | + return at::native::foreach_tensor_addcdiv_scalarlist_slow_(input, tensors1, tensors2, scalars); |
| 100 | - at::native::has_integral_tensor(input, true)) { | ||
| 101 | - return at::native::foreach_tensor_addcdiv_scalarlist_slow_(input, tensors1, tensors2, scalars); | ||
| 102 | - } | ||
| 103 | - | ||
| 104 | - _split_and_exec_npu_cmd_addcdiv(input, tensors1, tensors2, scalars, input, true); | ||
| 105 | } | 38 | } |
| 106 | } | 39 | } |
| @@ -25,7 +25,7 @@ using npu_preparation = at_npu::native::OpPreparation; | |||
| 25 | void _split_and_exec_npu_cmd_addcdiv_tensor(const at::TensorList input, | 25 | void _split_and_exec_npu_cmd_addcdiv_tensor(const at::TensorList input, |
| 26 | const at::TensorList tensors1, | 26 | const at::TensorList tensors1, |
| 27 | const at::TensorList tensors2, | 27 | const at::TensorList tensors2, |
| 28 | - at::ArrayRef<at::Scalar> scalars, | 28 | + const at::Tensor scalars, |
| 29 | at::TensorList result, | 29 | at::TensorList result, |
| 30 | bool is_inplace) | 30 | bool is_inplace) |
| 31 | { | 31 | { |
| @@ -39,7 +39,8 @@ void _split_and_exec_npu_cmd_addcdiv_tensor(const at::TensorList input, | |||
| 39 | } | 39 | } |
| 40 | 40 | ||
| 41 | if (tensor_count <= max_tensor_count) { | 41 | if (tensor_count <= max_tensor_count) { |
| 42 | - EXEC_NPU_CMD(aclnnForeachAddcdivScalarList, input, tensors1, tensors2, scalars, result); | 42 | + auto scalar_tensor = npu_preparation::copy_tensor_host_to_device(scalars); |
| 43 | + EXEC_NPU_CMD(aclnnForeachAddcdivScalarList, input, tensors1, tensors2, scalar_tensor, result); | ||
| 43 | return; | 44 | return; |
| 44 | } | 45 | } |
| 45 | for (size_t i = 0; i < loop_time; i++) { | 46 | for (size_t i = 0; i < loop_time; i++) { |
| @@ -47,9 +48,11 @@ void _split_and_exec_npu_cmd_addcdiv_tensor(const at::TensorList input, | |||
| 47 | at::TensorList temp_input(input.data() + i * max_tensor_count, data_count); | 48 | at::TensorList temp_input(input.data() + i * max_tensor_count, data_count); |
| 48 | at::TensorList temp_tensors1(tensors1.data() + i * max_tensor_count, data_count); | 49 | at::TensorList temp_tensors1(tensors1.data() + i * max_tensor_count, data_count); |
| 49 | at::TensorList temp_tensors2(tensors2.data() + i * max_tensor_count, data_count); | 50 | at::TensorList temp_tensors2(tensors2.data() + i * max_tensor_count, data_count); |
| 50 | - at::ArrayRef<at::Scalar> temp_scalars(scalars.data() + i * max_tensor_count, data_count); | 51 | + at::Tensor temp_scalars = scalars.slice(0, i * max_tensor_count, data_count); |
| 51 | at::TensorList temp_result(result.data() + i * max_tensor_count, data_count); | 52 | at::TensorList temp_result(result.data() + i * max_tensor_count, data_count); |
| 52 | - EXEC_NPU_CMD(aclnnForeachAddcdivScalarList, temp_input, temp_tensors1, temp_tensors2, temp_scalars, temp_result); | 53 | + |
| 54 | + auto scalar_tensor = npu_preparation::copy_tensor_host_to_device(temp_scalars); | ||
| 55 | + EXEC_NPU_CMD(aclnnForeachAddcdivScalarList, temp_input, temp_tensors1, temp_tensors2, scalar_tensor, temp_result); | ||
| 53 | } | 56 | } |
| 54 | } | 57 | } |
| 55 | 58 | ||
| @@ -73,6 +76,7 @@ std::vector<at::Tensor> _foreach_addcdiv(const at::TensorList input, | |||
| 73 | at::native::has_integral_tensor(input, true)) { | 76 | at::native::has_integral_tensor(input, true)) { |
| 74 | return at::native::foreach_tensor_addcdiv_scalarlist_slow(input, tensors1, tensors2, scalars_); | 77 | return at::native::foreach_tensor_addcdiv_scalarlist_slow(input, tensors1, tensors2, scalars_); |
| 75 | } | 78 | } |
| 79 | + | ||
| 76 | auto scalar_type = input[0].scalar_type(); | 80 | auto scalar_type = input[0].scalar_type(); |
| 77 | std::vector<at::Tensor> result(input.size()); | 81 | std::vector<at::Tensor> result(input.size()); |
| 78 | auto iterRes = result.data(); | 82 | auto iterRes = result.data(); |
| @@ -82,7 +86,7 @@ std::vector<at::Tensor> _foreach_addcdiv(const at::TensorList input, | |||
| 82 | iterRes[i++] = at_npu::native::OpPreparation::apply_tensor_without_format(output_size, tensor.options().dtype(scalar_type)); | 86 | iterRes[i++] = at_npu::native::OpPreparation::apply_tensor_without_format(output_size, tensor.options().dtype(scalar_type)); |
| 83 | } | 87 | } |
| 84 | at::TensorList result_ = at::TensorList(result); | 88 | at::TensorList result_ = at::TensorList(result); |
| 85 | - _split_and_exec_npu_cmd_addcdiv_tensor(input, tensors1, tensors2, scalars_, result_, false); | 89 | + _split_and_exec_npu_cmd_addcdiv_tensor(input, tensors1, tensors2, scalars, result_, false); |
| 86 | return result; | 90 | return result; |
| 87 | } | 91 | } |
| 88 | 92 | ||
| @@ -108,7 +112,7 @@ void _foreach_addcdiv_(const at::TensorList input, | |||
| 108 | } | 112 | } |
| 109 | 113 | ||
| 110 | at::native::check_foreach_api_restrictions(input, tensors1, tensors2); | 114 | at::native::check_foreach_api_restrictions(input, tensors1, tensors2); |
| 111 | - _split_and_exec_npu_cmd_addcdiv_tensor(input, tensors1, tensors2, scalars_, input, true); | 115 | + _split_and_exec_npu_cmd_addcdiv_tensor(input, tensors1, tensors2, scalars, input, true); |
| 112 | } | 116 | } |
| 113 | 117 | ||
| 114 | } | 118 | } |
| @@ -19,67 +19,13 @@ | |||
| 19 | namespace op_api { | 19 | namespace op_api { |
| 20 | using npu_preparation = at_npu::native::OpPreparation; | 20 | using npu_preparation = at_npu::native::OpPreparation; |
| 21 | 21 | ||
| 22 | -void _split_and_exec_npu_cmd_addcmul(const at::TensorList input, | ||
| 23 | - const at::TensorList tensors1, | ||
| 24 | - const at::TensorList tensors2, | ||
| 25 | - at::ArrayRef<at::Scalar> scalars, | ||
| 26 | - at::TensorList result, | ||
| 27 | - bool is_inplace) | ||
| 28 | -{ | ||
| 29 | - size_t tensor_count = input.size(); | ||
| 30 | - size_t max_tensor_count = is_inplace ? 16 : 12; | ||
| 31 | - size_t loop_time = tensor_count / max_tensor_count; | ||
| 32 | - size_t remaining_count = tensor_count % max_tensor_count; | ||
| 33 | - size_t data_count = max_tensor_count; | ||
| 34 | - if (remaining_count > 0) | ||
| 35 | - loop_time++; | ||
| 36 | - | ||
| 37 | - if (tensor_count <= max_tensor_count) { | ||
| 38 | - EXEC_NPU_CMD(aclnnForeachAddcmulScalarList, input, tensors1, tensors2, scalars, result); | ||
| 39 | - return; | ||
| 40 | - } | ||
| 41 | - for (size_t i = 0; i < loop_time; i++) { | ||
| 42 | - if (i == loop_time - 1 && remaining_count > 0) | ||
| 43 | - data_count = remaining_count; | ||
| 44 | - at::TensorList temp_input(input.data() + i * max_tensor_count, data_count); | ||
| 45 | - at::TensorList temp_tensors1(tensors1.data() + i * max_tensor_count, data_count); | ||
| 46 | - at::TensorList temp_tensors2(tensors2.data() + i * max_tensor_count, data_count); | ||
| 47 | - at::ArrayRef<at::Scalar> temp_scalars(scalars.data() + i * max_tensor_count, data_count); | ||
| 48 | - at::TensorList temp_result(result.data() + i * max_tensor_count, data_count); | ||
| 49 | - EXEC_NPU_CMD(aclnnForeachAddcmulScalarList, temp_input, temp_tensors1, temp_tensors2, temp_scalars, temp_result); | ||
| 50 | - } | ||
| 51 | -} | ||
| 52 | - | ||
| 53 | std::vector<at::Tensor> _foreach_addcmul(const at::TensorList input, | 22 | std::vector<at::Tensor> _foreach_addcmul(const at::TensorList input, |
| 54 | const at::TensorList tensors1, | 23 | const at::TensorList tensors1, |
| 55 | const at::TensorList tensors2, | 24 | const at::TensorList tensors2, |
| 56 | at::ArrayRef<at::Scalar> scalars) | 25 | at::ArrayRef<at::Scalar> scalars) |
| 57 | { | 26 | { |
| 58 | - static const bool is_support_nd_out = (c10_npu::GetSocVersion() >= c10_npu::SocVersion::Ascend910B1 && | ||
| 59 | - c10_npu::GetSocVersion() < c10_npu::SocVersion::Ascend310B1) || | ||
| 60 | - (c10_npu::GetSocVersion() > c10_npu::SocVersion::Ascend310B4); | ||
| 61 | - if (!is_support_nd_out) { | ||
| 62 | - return at::native::foreach_tensor_addcmul_scalarlist_slow(input, tensors1, tensors2, scalars); | ||
| 63 | - } | ||
| 64 | - | ||
| 65 | at::native::check_foreach_api_restrictions(input, tensors1, tensors2, scalars); | 27 | at::native::check_foreach_api_restrictions(input, tensors1, tensors2, scalars); |
| 66 | - if (!at::native::can_use_fast_route({input, tensors1, tensors2}) || | 28 | + return at::native::foreach_tensor_addcmul_scalarlist_slow(input, tensors1, tensors2, scalars); |
| 67 | - at::native::has_integral_tensor(input, true)) { | ||
| 68 | - return at::native::foreach_tensor_addcmul_scalarlist_slow(input, tensors1, tensors2, scalars); | ||
| 69 | - } | ||
| 70 | - | ||
| 71 | - auto scalar_type = input[0].scalar_type(); | ||
| 72 | - | ||
| 73 | - std::vector<at::Tensor> result; | ||
| 74 | - result.reserve(input.size()); | ||
| 75 | - for (const at::Tensor &tensor : input) { | ||
| 76 | - auto output_size = op_infer::input_same_output_size(tensor); | ||
| 77 | - result.push_back(npu_preparation::apply_tensor_without_format(output_size, tensor.options().dtype(scalar_type))); | ||
| 78 | - } | ||
| 79 | - at::TensorList result_ = at::TensorList(result); | ||
| 80 | - _split_and_exec_npu_cmd_addcmul(input, tensors1, tensors2, scalars, result_, false); | ||
| 81 | - | ||
| 82 | - return result; | ||
| 83 | } | 29 | } |
| 84 | 30 | ||
| 85 | void _foreach_addcmul_(const at::TensorList input, | 31 | void _foreach_addcmul_(const at::TensorList input, |
| @@ -87,18 +33,7 @@ void _foreach_addcmul_(const at::TensorList input, | |||
| 87 | const at::TensorList tensors2, | 33 | const at::TensorList tensors2, |
| 88 | at::ArrayRef<at::Scalar> scalars) | 34 | at::ArrayRef<at::Scalar> scalars) |
| 89 | { | 35 | { |
| 90 | - static const bool is_support_nd_out = (c10_npu::GetSocVersion() >= c10_npu::SocVersion::Ascend910B1 && | ||
| 91 | - c10_npu::GetSocVersion() < c10_npu::SocVersion::Ascend310B1) || | ||
| 92 | - (c10_npu::GetSocVersion() > c10_npu::SocVersion::Ascend310B4); | ||
| 93 | - if (!is_support_nd_out) { | ||
| 94 | - return at::native::foreach_tensor_addcmul_scalarlist_slow_(input, tensors1, tensors2, scalars); | ||
| 95 | - } | ||
| 96 | - | ||
| 97 | at::native::check_foreach_api_restrictions(input, tensors1, tensors2, scalars); | 36 | at::native::check_foreach_api_restrictions(input, tensors1, tensors2, scalars); |
| 98 | - if (!at::native::can_use_fast_route({input, tensors1, tensors2}) || | 37 | + return at::native::foreach_tensor_addcmul_scalarlist_slow_(input, tensors1, tensors2, scalars); |
| 99 | - at::native::has_integral_tensor(input, true)) { | ||
| 100 | - return at::native::foreach_tensor_addcmul_scalarlist_slow_(input, tensors1, tensors2, scalars); | ||
| 101 | - } | ||
| 102 | - _split_and_exec_npu_cmd_addcmul(input, tensors1, tensors2, scalars, input, true); | ||
| 103 | } | 38 | } |
| 104 | } | 39 | } |
| @@ -25,7 +25,7 @@ using npu_preparation = at_npu::native::OpPreparation; | |||
| 25 | void _split_and_exec_npu_cmd_addcmul_tensor(const at::TensorList input, | 25 | void _split_and_exec_npu_cmd_addcmul_tensor(const at::TensorList input, |
| 26 | const at::TensorList tensors1, | 26 | const at::TensorList tensors1, |
| 27 | const at::TensorList tensors2, | 27 | const at::TensorList tensors2, |
| 28 | - at::ArrayRef<at::Scalar> scalars, | 28 | + at::Tensor scalars, |
| 29 | at::TensorList result, | 29 | at::TensorList result, |
| 30 | bool is_inplace) | 30 | bool is_inplace) |
| 31 | { | 31 | { |
| @@ -49,7 +49,7 @@ void _split_and_exec_npu_cmd_addcmul_tensor(const at::TensorList input, | |||
| 49 | at::TensorList temp_input(input.data() + i * max_tensor_count, data_count); | 49 | at::TensorList temp_input(input.data() + i * max_tensor_count, data_count); |
| 50 | at::TensorList temp_tensors1(tensors1.data() + i * max_tensor_count, data_count); | 50 | at::TensorList temp_tensors1(tensors1.data() + i * max_tensor_count, data_count); |
| 51 | at::TensorList temp_tensors2(tensors2.data() + i * max_tensor_count, data_count); | 51 | at::TensorList temp_tensors2(tensors2.data() + i * max_tensor_count, data_count); |
| 52 | - at::ArrayRef<at::Scalar> temp_scalars(scalars.data() + i * max_tensor_count, data_count); | 52 | + at::Tensor temp_scalars = scalars.slice(0, i * max_tensor_count, data_count); |
| 53 | at::TensorList temp_result(result.data() + i * max_tensor_count, data_count); | 53 | at::TensorList temp_result(result.data() + i * max_tensor_count, data_count); |
| 54 | EXEC_NPU_CMD(aclnnForeachAddcmulScalarList, temp_input, temp_tensors1, temp_tensors2, temp_scalars, temp_result); | 54 | EXEC_NPU_CMD(aclnnForeachAddcmulScalarList, temp_input, temp_tensors1, temp_tensors2, temp_scalars, temp_result); |
| 55 | } | 55 | } |
| @@ -70,20 +70,25 @@ std::vector<at::Tensor> _foreach_addcmul(const at::TensorList input, | |||
| 70 | } | 70 | } |
| 71 | 71 | ||
| 72 | at::native::check_foreach_api_restrictions(input, tensors1, tensors2, scalars_); | 72 | at::native::check_foreach_api_restrictions(input, tensors1, tensors2, scalars_); |
| 73 | - if (!at::native::can_use_fast_route({input, tensors1, tensors2}) || | 73 | + if (!at_npu::native::env::CheckJitDisable() || |
| 74 | + !at::native::can_use_fast_route({input, tensors1, tensors2}) || | ||
| 74 | at::native::has_integral_tensor(input, true)) { | 75 | at::native::has_integral_tensor(input, true)) { |
| 75 | return at::native::foreach_tensor_addcmul_scalarlist_slow(input, tensors1, tensors2, scalars_); | 76 | return at::native::foreach_tensor_addcmul_scalarlist_slow(input, tensors1, tensors2, scalars_); |
| 76 | } | 77 | } |
| 78 | + | ||
| 77 | auto scalar_type = input[0].scalar_type(); | 79 | auto scalar_type = input[0].scalar_type(); |
| 78 | - std::vector<at::Tensor> result(input.size()); | 80 | + if (scalar_type != at::ScalarType::Half && scalar_type != at::ScalarType::Float && scalar_type != at::ScalarType::Int) { |
| 79 | - auto iterRes = result.data(); | 81 | + TORCH_CHECK(false, "input must be half, float or int32" + OPS_ERROR(ErrCode::TYPE)); |
| 80 | - int i = 0; | 82 | + } |
| 83 | + std::vector<at::Tensor> result; | ||
| 84 | + result.reserve(input.size()); | ||
| 81 | for (const at::Tensor &tensor : input) { | 85 | for (const at::Tensor &tensor : input) { |
| 82 | auto output_size = op_infer::input_same_output_size(tensor); | 86 | auto output_size = op_infer::input_same_output_size(tensor); |
| 83 | - iterRes[i++] = at_npu::native::OpPreparation::apply_tensor_without_format(output_size, tensor.options().dtype(scalar_type)); | 87 | + result.push_back(npu_preparation::apply_tensor_without_format(output_size, tensor.options().dtype(scalar_type))); |
| 84 | } | 88 | } |
| 85 | at::TensorList result_ = at::TensorList(result); | 89 | at::TensorList result_ = at::TensorList(result); |
| 86 | - _split_and_exec_npu_cmd_addcmul_tensor(input, tensors1, tensors2, scalars_, result_, false); | 90 | + auto scalar_tensor = npu_preparation::copy_tensor_host_to_device(scalars); |
| 91 | + _split_and_exec_npu_cmd_addcmul_tensor(input, tensors1, tensors2, scalar_tensor, result_, false); | ||
| 87 | return result; | 92 | return result; |
| 88 | } | 93 | } |
| 89 | 94 | ||
| @@ -100,16 +105,22 @@ void _foreach_addcmul_(const at::TensorList input, | |||
| 100 | if (!is_support_nd_out) { | 105 | if (!is_support_nd_out) { |
| 101 | return at::native::foreach_tensor_addcmul_scalarlist_slow_(input, tensors1, tensors2, scalars_); | 106 | return at::native::foreach_tensor_addcmul_scalarlist_slow_(input, tensors1, tensors2, scalars_); |
| 102 | } | 107 | } |
| 103 | - | 108 | + |
| 104 | at::native::check_foreach_api_restrictions(input, tensors1, tensors2, scalars_); | 109 | at::native::check_foreach_api_restrictions(input, tensors1, tensors2, scalars_); |
| 105 | - if (!at::native::can_use_fast_route({input, tensors1, tensors2}) || | 110 | + if (!at_npu::native::env::CheckJitDisable() || |
| 111 | + !at::native::can_use_fast_route({input, tensors1, tensors2}) || | ||
| 106 | at::native::has_integral_tensor(input, true)) { | 112 | at::native::has_integral_tensor(input, true)) { |
| 107 | return at::native::foreach_tensor_addcmul_scalarlist_slow_(input, tensors1, tensors2, scalars_); | 113 | return at::native::foreach_tensor_addcmul_scalarlist_slow_(input, tensors1, tensors2, scalars_); |
| 108 | } | 114 | } |
| 109 | 115 | ||
| 110 | at::native::check_foreach_api_restrictions(input, tensors1, tensors2); | 116 | at::native::check_foreach_api_restrictions(input, tensors1, tensors2); |
| 117 | + auto scalar_type = input[0].scalar_type(); | ||
| 118 | + if (scalar_type != at::ScalarType::Half && scalar_type != at::ScalarType::Float && scalar_type != at::ScalarType::Int) { | ||
| 119 | + TORCH_CHECK(false, "input must be half, float or int32" + OPS_ERROR(ErrCode::TYPE)); | ||
| 120 | + } | ||
| 121 | + auto scalar_tensor = npu_preparation::copy_tensor_host_to_device(scalars); | ||
| 111 | 122 | ||
| 112 | - _split_and_exec_npu_cmd_addcmul_tensor(input, tensors1, tensors2, scalars_, input, true); | 123 | + _split_and_exec_npu_cmd_addcmul_tensor(input, tensors1, tensors2, scalar_tensor, input, true); |
| 113 | } | 124 | } |
| 114 | 125 | ||
| 115 | } // namespace op_api | 126 | } // namespace op_api |