diff --git a/backends/arm/runtime/VGFSetup.cpp b/backends/arm/runtime/VGFSetup.cpp index abb4c50d8be..fa8c7ead220 100644 --- a/backends/arm/runtime/VGFSetup.cpp +++ b/backends/arm/runtime/VGFSetup.cpp @@ -24,6 +24,13 @@ namespace vgf { /* static function to map format to byte count */ static uint32_t get_format_size(VkFormat format); +// SPV_ARM_tensor does not support rank-0 representations according to the spec. +// Use an unsqueezed dimension when the resource table contains an empty +// shape. Tensors are output as rank 0 when copied back from the vgf backend. +namespace { +constexpr int64_t kScalarSentinelDimension = 1; +} + // Debug function to inspect memory properties static string memory_flags_to_string(VkMemoryPropertyFlags flags) { if (flags == 0) @@ -264,7 +271,11 @@ static void debug_print_resources( the_shape.size(), the_stride.size()); for (int j = 0; j < the_shape.size(); j++) { - ET_LOG(Info, " %d: dim %ld", j, the_shape[j]); + ET_LOG( + Info, + " %d: dim %lld", + j, + static_cast(the_shape[j])); } // Allocate a tensor with bound memory break; @@ -387,6 +398,7 @@ bool VgfRepr::process_vgf(const char* vgf_data, ArrayRef specs) { // Get tensor shape and strides auto shape = resource_decoder->getTensorShape(i); auto stride = resource_decoder->getTensorStride(i); + const auto shape_size = shape.size(); switch (resource_decoder->getCategory(i)) { case vgflib::ResourceCategory::INPUT: @@ -409,9 +421,9 @@ bool VgfRepr::process_vgf(const char* vgf_data, ArrayRef specs) { result = allocate_tensor( vk_physical, vk_device, - vgflib::ToVkFormat(resource_decoder->getVkFormat(i)), - static_cast(shape.size()), - shape.begin(), + resource_format, + shape_size == 0 ? 1 : static_cast(shape_size), + shape_size == 0 ? &kScalarSentinelDimension : shape.begin(), static_cast(stride.size()), stride.begin(), &tensor_description, @@ -422,8 +434,7 @@ bool VgfRepr::process_vgf(const char* vgf_data, ArrayRef specs) { ET_LOG(Error, "Failed to allocate tensor for VGF resource %d", i); return false; } - size_t e_size = get_format_size( - vgflib::ToVkFormat(resource_decoder->getVkFormat(i))); + size_t e_size = get_format_size(resource_format); if (0 == e_size) { ET_LOG(Error, "failed to get element size of VkFormat"); return false; @@ -449,9 +460,11 @@ bool VgfRepr::process_vgf(const char* vgf_data, ArrayRef specs) { .sType = VK_STRUCTURE_TYPE_TENSOR_DESCRIPTION_ARM, .pNext = nullptr, .tiling = VK_TENSOR_TILING_LINEAR_ARM, - .format = vgflib::ToVkFormat(resource_decoder->getVkFormat(i)), - .dimensionCount = static_cast(shape.size()), - .pDimensions = shape.begin(), + .format = resource_format, + .dimensionCount = + shape_size == 0 ? 1 : static_cast(shape_size), + .pDimensions = + shape_size == 0 ? &kScalarSentinelDimension : shape.begin(), // Note: stride_data of 0's causes size==0, null means stride==size .pStrides = (0 == stride.size() ? nullptr : stride.begin()), .usage = VK_TENSOR_USAGE_DATA_GRAPH_BIT_ARM, diff --git a/backends/arm/test/ops/test_addmm.py b/backends/arm/test/ops/test_addmm.py index 1170f65dd58..685b69b3541 100644 --- a/backends/arm/test/ops/test_addmm.py +++ b/backends/arm/test/ops/test_addmm.py @@ -167,7 +167,6 @@ def test_addmm_u85_INT(test_data: Tuple): @common.parametrize("test_data", test_data_suite) @common.SkipIfNoModelConverter -@pytest.mark.xfail(reason="MLETORCH-1410: Tensor dimension count not supported: 0") def test_addmm_vgf_FP(test_data: input_t1): pipeline = VgfPipeline[input_t1]( Addmm(), @@ -181,7 +180,6 @@ def test_addmm_vgf_FP(test_data: input_t1): @common.parametrize("test_data", test_data_suite) @common.SkipIfNoModelConverter -@pytest.mark.xfail(reason="MLETORCH-1410: Tensor dimension count not supported: 0") def test_addmm_vgf_INT(test_data: input_t1): pipeline = VgfPipeline[input_t1]( Addmm(), diff --git a/backends/arm/test/ops/test_amax.py b/backends/arm/test/ops/test_amax.py index 99529e07ca2..e69e9163325 100644 --- a/backends/arm/test/ops/test_amax.py +++ b/backends/arm/test/ops/test_amax.py @@ -139,7 +139,6 @@ def test_max_dim_tosa_FP_not_delegated(): @common.parametrize("test_data", Amax.test_data) @common.SkipIfNoModelConverter -@pytest.mark.xfail(reason="MLETORCH-1410: Tensor dimension count not supported: 0") def test_amax_vgf_FP(test_data: Amax.input_t): data, dim, keep_dims = test_data() module = Amax(dim, keep_dims) @@ -154,7 +153,6 @@ def test_amax_vgf_FP(test_data: Amax.input_t): @common.parametrize("test_data", Amax.test_data) @common.SkipIfNoModelConverter -@pytest.mark.xfail(reason="MLETORCH-1410: Tensor dimension count not supported: 0") def test_amax_vgf_INT(test_data: Amax.input_t): data, dim, keep_dims = test_data() module = Amax(dim, keep_dims) @@ -169,7 +167,6 @@ def test_amax_vgf_INT(test_data: Amax.input_t): @common.parametrize("test_data", Max.test_data) @common.SkipIfNoModelConverter -@pytest.mark.xfail(reason="MLETORCH-1410: Tensor dimension count not supported: 0") def test_max_dim_vgf_FP_to_amax(test_data: Max.input_t): data, dim = test_data() pipeline = VgfPipeline[Max.input_t]( @@ -183,7 +180,6 @@ def test_max_dim_vgf_FP_to_amax(test_data: Max.input_t): @common.parametrize("test_data", Max.test_data) @common.SkipIfNoModelConverter -@pytest.mark.xfail(reason="MLETORCH-1410: Tensor dimension count not supported: 0") def test_max_dim_vgf_INT_to_amax(test_data: Max.input_t): data, dim = test_data() pipeline = VgfPipeline[Max.input_t]( diff --git a/backends/arm/test/ops/test_amin.py b/backends/arm/test/ops/test_amin.py index d213cabf5a1..09d9018c73e 100644 --- a/backends/arm/test/ops/test_amin.py +++ b/backends/arm/test/ops/test_amin.py @@ -155,7 +155,6 @@ def test_min_dim_tosa_FP_not_delegated(): @common.parametrize("test_data", Amin.test_data) @common.SkipIfNoModelConverter -@pytest.mark.xfail(reason="MLETORCH-1410: Tensor dimension count not supported: 0") def test_amin_vgf_FP(test_data: Amin.input_t): data, dim, keep_dims = test_data() pipeline = VgfPipeline[Amin.input_t]( @@ -166,7 +165,6 @@ def test_amin_vgf_FP(test_data: Amin.input_t): @common.parametrize("test_data", Amin.test_data) @common.SkipIfNoModelConverter -@pytest.mark.xfail(reason="MLETORCH-1410: Tensor dimension count not supported: 0") def test_amin_vgf_INT(test_data: Amin.input_t): data, dim, keep_dims = test_data() pipeline = VgfPipeline[Amin.input_t]( @@ -180,7 +178,6 @@ def test_amin_vgf_INT(test_data: Amin.input_t): @common.parametrize("test_data", Min.test_data) @common.SkipIfNoModelConverter -@pytest.mark.xfail(reason="MLETORCH-1410: Tensor dimension count not supported: 0") def test_min_dim_vgf_FP_to_amin(test_data: Min.input_t): data, dim = test_data() pipeline = VgfPipeline[Min.input_t]( @@ -194,7 +191,6 @@ def test_min_dim_vgf_FP_to_amin(test_data: Min.input_t): @common.parametrize("test_data", Min.test_data) @common.SkipIfNoModelConverter -@pytest.mark.xfail(reason="MLETORCH-1410: Tensor dimension count not supported: 0") def test_min_dim_vgf_INT_to_amin(test_data: Min.input_t): data, dim = test_data() pipeline = VgfPipeline[Min.input_t]( diff --git a/backends/arm/test/ops/test_any.py b/backends/arm/test/ops/test_any.py index 1676018f0ce..3eccff0a64e 100644 --- a/backends/arm/test/ops/test_any.py +++ b/backends/arm/test/ops/test_any.py @@ -6,7 +6,6 @@ from typing import List, Tuple -import pytest import torch from executorch.backends.arm.test import common from executorch.backends.arm.test.tester.test_pipeline import ( @@ -189,7 +188,6 @@ def test_any_u85_INT(test_data: input_t1): @common.parametrize("test_data", test_data) @common.SkipIfNoModelConverter -@pytest.mark.xfail(reason="MLETORCH-1410: Tensor dimension count not supported: 0") def test_any_vgf_FP(test_data: input_t1): op, data_fn = test_data() pipeline = VgfPipeline[input_t1]( @@ -204,7 +202,6 @@ def test_any_vgf_FP(test_data: input_t1): @common.parametrize("test_data", test_data) @common.SkipIfNoModelConverter -@pytest.mark.xfail(reason="MLETORCH-1410: Tensor dimension count not supported: 0") def test_any_vgf_INT(test_data: input_t1): op, data_fn = test_data() pipeline = VgfPipeline[input_t1]( diff --git a/backends/arm/test/ops/test_mean_dim.py b/backends/arm/test/ops/test_mean_dim.py index 656f35fb17f..970340c352b 100644 --- a/backends/arm/test/ops/test_mean_dim.py +++ b/backends/arm/test/ops/test_mean_dim.py @@ -4,7 +4,6 @@ # # This source code is licensed under the BSD-style license found in the # LICENSE file in the root directory of this source tree. -import pytest import torch from executorch.backends.arm.test import common from executorch.backends.arm.test.tester.test_pipeline import ( @@ -84,7 +83,6 @@ def test_adaptive_avg_pool2d_u85_INT(test_data): @common.parametrize("test_data", AdaptiveAveragePool2d.test_data_suite) @common.SkipIfNoModelConverter -@pytest.mark.xfail(reason="MLETORCH-1410: Tensor dimension count not supported: 0") def test_adaptive_avg_pool2d_vgf_FP(test_data): pipeline = VgfPipeline[input_t]( AdaptiveAveragePool2d(), @@ -98,7 +96,6 @@ def test_adaptive_avg_pool2d_vgf_FP(test_data): @common.parametrize("test_data", AdaptiveAveragePool2d.test_data_suite) @common.SkipIfNoModelConverter -@pytest.mark.xfail(reason="MLETORCH-1410: Tensor dimension count not supported: 0") def test_adaptive_avg_pool2d_vgf_INT(test_data): pipeline = VgfPipeline[input_t]( AdaptiveAveragePool2d(), @@ -331,7 +328,6 @@ def test_mean_dim_u85_INT(test_data): @common.parametrize("test_data", MeanDim.test_data_suite) @common.SkipIfNoModelConverter -@pytest.mark.xfail(reason="MLETORCH-1410: Tensor dimension count not supported: 0") def test_mean_dim_vgf_FP(test_data): test_data_val, dim, keep_dim = test_data() pipeline = VgfPipeline[input_t]( @@ -346,7 +342,6 @@ def test_mean_dim_vgf_FP(test_data): @common.parametrize("test_data", MeanDim.test_data_suite) @common.SkipIfNoModelConverter -@pytest.mark.xfail(reason="MLETORCH-1410: Tensor dimension count not supported: 0") def test_mean_dim_vgf_INT(test_data): test_data_val, dim, keep_dim = test_data() pipeline = VgfPipeline[input_t]( diff --git a/backends/arm/test/ops/test_scalar_tensor.py b/backends/arm/test/ops/test_scalar_tensor.py index ecc2fece223..d5e5b365da1 100644 --- a/backends/arm/test/ops/test_scalar_tensor.py +++ b/backends/arm/test/ops/test_scalar_tensor.py @@ -2,7 +2,6 @@ # # This source code is licensed under the BSD-style license found in the # LICENSE file in the root directory of this source tree. -import pytest import torch from executorch.backends.arm.test import common @@ -102,7 +101,6 @@ def test_scalar_tensor_u85_INT(test_data): @common.parametrize("test_data", float_test_data_suite) @common.SkipIfNoModelConverter -@pytest.mark.xfail(reason="MLETORCH-1410: Tensor dimension count not supported: 0") def test_scalar_tensor_vgf_FP(test_data): scalar, dtype, data = test_data() pipeline = VgfPipeline( @@ -116,7 +114,6 @@ def test_scalar_tensor_vgf_FP(test_data): @common.parametrize("test_data", int_test_data_suite) @common.SkipIfNoModelConverter -@pytest.mark.xfail(reason="MLETORCH-1410: Tensor dimension count not supported: 0") def test_scalar_tensor_vgf_INT(test_data): scalar, dtype, data = test_data() pipeline = VgfPipeline( diff --git a/backends/arm/test/ops/test_select.py b/backends/arm/test/ops/test_select.py index b47295f967b..23046c34fe4 100644 --- a/backends/arm/test/ops/test_select.py +++ b/backends/arm/test/ops/test_select.py @@ -7,7 +7,6 @@ from typing import Tuple -import pytest import torch from executorch.backends.arm.test import common @@ -170,7 +169,6 @@ def test_select_int_u85_INT(test_data: Tuple): @common.parametrize("test_data", test_data_suite) @common.SkipIfNoModelConverter -@pytest.mark.xfail(reason="MLETORCH-1410: Tensor dimension count not supported: 0") def test_select_int_vgf_FP_copy(test_data: Tuple): pipeline = VgfPipeline[input_t1]( SelectCopy(), test_data(), aten_op_copy, [], tosa_version="TOSA-1.0+FP" @@ -180,7 +178,6 @@ def test_select_int_vgf_FP_copy(test_data: Tuple): @common.parametrize("test_data", test_data_suite) @common.SkipIfNoModelConverter -@pytest.mark.xfail(reason="MLETORCH-1410: Tensor dimension count not supported: 0") def test_select_int_vgf_FP(test_data: Tuple): pipeline = VgfPipeline[input_t1]( SelectInt(), test_data(), aten_op_int, [], tosa_version="TOSA-1.0+FP" @@ -190,7 +187,6 @@ def test_select_int_vgf_FP(test_data: Tuple): @common.parametrize("test_data", test_data_suite) @common.SkipIfNoModelConverter -@pytest.mark.xfail(reason="MLETORCH-1410: Tensor dimension count not supported: 0") def test_select_int_vgf_INT_copy(test_data: Tuple): pipeline = VgfPipeline[input_t1]( SelectCopy(), @@ -204,7 +200,6 @@ def test_select_int_vgf_INT_copy(test_data: Tuple): @common.parametrize("test_data", test_data_suite) @common.SkipIfNoModelConverter -@pytest.mark.xfail(reason="MLETORCH-1410: Tensor dimension count not supported: 0") def test_select_int_vgf_INT(test_data: Tuple): pipeline = VgfPipeline[input_t1]( SelectInt(), diff --git a/backends/arm/test/ops/test_var.py b/backends/arm/test/ops/test_var.py index f08e4498cc5..9f1c437fc65 100644 --- a/backends/arm/test/ops/test_var.py +++ b/backends/arm/test/ops/test_var.py @@ -6,7 +6,6 @@ from typing import Tuple -import pytest import torch from executorch.backends.arm.test import common @@ -214,7 +213,6 @@ def test_var_dim_u85_INT_no_dim(test_data: Tuple): @common.parametrize("test_data", Var.test_parameters) @common.SkipIfNoModelConverter -@pytest.mark.xfail(reason="MLETORCH-1410: Tensor dimension count not supported: 0") def test_var_dim_vgf_FP_no_dim(test_data: Tuple): data, keepdim, correction = test_data() pipeline = VgfPipeline[input_t1]( @@ -225,7 +223,6 @@ def test_var_dim_vgf_FP_no_dim(test_data: Tuple): @common.parametrize("test_data", Var.test_parameters) @common.SkipIfNoModelConverter -@pytest.mark.xfail(reason="MLETORCH-1410: Tensor dimension count not supported: 0") def test_var_dim_vgf_INT_no_dim(test_data: Tuple): data, keepdim, correction = test_data() pipeline = VgfPipeline[input_t1]( @@ -296,7 +293,6 @@ def test_var_dim_u85_INT(test_data: Tuple): @common.parametrize("test_data", VarDim.test_parameters) @common.SkipIfNoModelConverter -@pytest.mark.xfail(reason="MLETORCH-1410: Tensor dimension count not supported: 0") def test_var_dim_vgf_FP(test_data: Tuple): data, dim, keepdim, unbiased = test_data() pipeline = VgfPipeline[input_t1]( @@ -307,7 +303,6 @@ def test_var_dim_vgf_FP(test_data: Tuple): @common.parametrize("test_data", VarDim.test_parameters) @common.SkipIfNoModelConverter -@pytest.mark.xfail(reason="MLETORCH-1410: Tensor dimension count not supported: 0") def test_var_dim_vgf_INT(test_data: Tuple): data, dim, keepdim, unbiased = test_data() pipeline = VgfPipeline[input_t1]( @@ -377,7 +372,6 @@ def test_var_dim_u85_INT_correction(test_data: Tuple): @common.parametrize("test_data", VarCorrection.test_parameters) @common.SkipIfNoModelConverter -@pytest.mark.xfail(reason="MLETORCH-1410: Tensor dimension count not supported: 0") def test_var_dim_vgf_FP_correction(test_data: Tuple): data, dim, keepdim, corr = test_data() pipeline = VgfPipeline[input_t1]( @@ -388,7 +382,6 @@ def test_var_dim_vgf_FP_correction(test_data: Tuple): @common.parametrize("test_data", VarCorrection.test_parameters) @common.SkipIfNoModelConverter -@pytest.mark.xfail(reason="MLETORCH-1410: Tensor dimension count not supported: 0") def test_var_dim_vgf_INT_correction(test_data: Tuple): data, dim, keepdim, corr = test_data() pipeline = VgfPipeline[input_t1](