diff --git a/runtime/core/array_ref.h b/runtime/core/array_ref.h index d02aac955ce..a23509e8698 100644 --- a/runtime/core/array_ref.h +++ b/runtime/core/array_ref.h @@ -29,6 +29,7 @@ #include #include +#include #include namespace executorch { @@ -149,7 +150,7 @@ class ArrayRef final { if (Length != RHS.Length) { return false; } - for (size_t i = 0; i < this->Length; i++) { + for (const auto i : c10::irange(this->Length)) { if (Data[i] != RHS.Data[i]) { return false; } diff --git a/runtime/core/hierarchical_allocator.h b/runtime/core/hierarchical_allocator.h index f2f5fd18fb5..b5031fa38e5 100644 --- a/runtime/core/hierarchical_allocator.h +++ b/runtime/core/hierarchical_allocator.h @@ -8,6 +8,7 @@ #pragma once +#include #include #include #include @@ -96,7 +97,7 @@ class HierarchicalAllocator final { "n_allocators %" PRIu32 " > %zu", n_allocators, kSpanArraySize); - for (uint32_t i = 0; i < n_allocators; ++i) { + for (const auto i : c10::irange(n_allocators)) { span_array_[i] = Span(allocators[i].base_address(), allocators[i].size()); } diff --git a/runtime/core/portable_type/c10/c10/targets.bzl b/runtime/core/portable_type/c10/c10/targets.bzl index 64436278e79..2bde5eac5e4 100644 --- a/runtime/core/portable_type/c10/c10/targets.bzl +++ b/runtime/core/portable_type/c10/c10/targets.bzl @@ -45,7 +45,7 @@ def define_common_targets(): "-DC10_USING_CUSTOM_GENERATED_MACROS", ], visibility = [ - "//executorch/runtime/core/portable_type/...", + "//executorch/...", ], deps = select({ "DEFAULT": [], diff --git a/runtime/core/portable_type/test/bfloat16_test.cpp b/runtime/core/portable_type/test/bfloat16_test.cpp index 6b42a6e4a5e..505f80e770f 100644 --- a/runtime/core/portable_type/test/bfloat16_test.cpp +++ b/runtime/core/portable_type/test/bfloat16_test.cpp @@ -6,6 +6,7 @@ * LICENSE file in the root directory of this source tree. */ +#include #include #include @@ -41,7 +42,7 @@ uint16_t bits_from_f32(float src) { TEST(BFloat16Conversion, FloatToBFloat16AndBack) { // NOLINTNEXTLINE(cppcoreguidelines-avoid-c-arrays,cppcoreguidelines-avoid-magic-numbers,modernize-avoid-c-arrays) float in[100]; - for (int i = 0; i < 100; ++i) { + for (const auto i : c10::irange(100)) { // NOLINTNEXTLINE(bugprone-narrowing-conversions,cppcoreguidelines-narrowing-conversions,cppcoreguidelines-avoid-magic-numbers) in[i] = i + 1.25; } @@ -51,7 +52,7 @@ TEST(BFloat16Conversion, FloatToBFloat16AndBack) { // NOLINTNEXTLINE(cppcoreguidelines-avoid-c-arrays,cppcoreguidelines-avoid-magic-numbers,modernize-avoid-c-arrays) float out[100]; - for (int i = 0; i < 100; ++i) { + for (const auto i : c10::irange(100)) { bfloats[i].x = bits_from_f32(in[i]); out[i] = f32_from_bits(bfloats[i].x); @@ -64,7 +65,7 @@ TEST(BFloat16Conversion, FloatToBFloat16AndBack) { TEST(BFloat16Conversion, FloatToBFloat16RNEAndBack) { // NOLINTNEXTLINE(cppcoreguidelines-avoid-c-arrays,cppcoreguidelines-avoid-magic-numbers,modernize-avoid-c-arrays) float in[100]; - for (int i = 0; i < 100; ++i) { + for (const auto i : c10::irange(100)) { // NOLINTNEXTLINE(bugprone-narrowing-conversions,cppcoreguidelines-narrowing-conversions,cppcoreguidelines-avoid-magic-numbers) in[i] = i + 1.25; } @@ -74,7 +75,7 @@ TEST(BFloat16Conversion, FloatToBFloat16RNEAndBack) { // NOLINTNEXTLINE(cppcoreguidelines-avoid-c-arrays,cppcoreguidelines-avoid-magic-numbers,modernize-avoid-c-arrays) float out[100]; - for (int i = 0; i < 100; ++i) { + for (const auto i : c10::irange(100)) { bfloats[i].x = round_to_nearest_even(in[i]); out[i] = f32_from_bits(bfloats[i].x); diff --git a/runtime/core/portable_type/test/targets.bzl b/runtime/core/portable_type/test/targets.bzl index c0b4ef00c78..d8e82a15fba 100644 --- a/runtime/core/portable_type/test/targets.bzl +++ b/runtime/core/portable_type/test/targets.bzl @@ -11,6 +11,7 @@ def define_common_targets(): srcs = ["bfloat16_test.cpp"], deps = [ "//executorch/runtime/core/portable_type:portable_type", + "//executorch/runtime/core/portable_type/c10/c10:c10", ], ) @@ -52,5 +53,6 @@ def define_common_targets(): deps = [ "//executorch/runtime/core/exec_aten/util:tensor_util", "//executorch/runtime/core/portable_type:portable_type", + "//executorch/runtime/core/portable_type/c10/c10:c10", ], ) diff --git a/runtime/core/portable_type/test/tensor_impl_test.cpp b/runtime/core/portable_type/test/tensor_impl_test.cpp index bd5f82c5d1f..0b8ae05f4da 100644 --- a/runtime/core/portable_type/test/tensor_impl_test.cpp +++ b/runtime/core/portable_type/test/tensor_impl_test.cpp @@ -6,6 +6,7 @@ * LICENSE file in the root directory of this source tree. */ +#include #include #include @@ -76,7 +77,7 @@ TEST_F(TensorImplTest, TestSetSizesContigContract) { SizesType new_sizes[RANK] = {0, 0, 0, 0, 0}; // assign random sizes between 1 and 100 - for (int i = 0; i < RANK; i++) { + for (const auto i : c10::irange(RANK)) { new_sizes[i] = distribution(generator); } Error err = resize_tensor_impl(&t, {new_sizes, RANK}); diff --git a/runtime/core/targets.bzl b/runtime/core/targets.bzl index c3535688f63..d67312beda3 100644 --- a/runtime/core/targets.bzl +++ b/runtime/core/targets.bzl @@ -50,6 +50,7 @@ def define_common_targets(): ], exported_preprocessor_flags = get_core_flags(), exported_deps = [ + "//executorch/runtime/core/portable_type/c10/c10:c10", "//executorch/runtime/platform:platform", ], ) @@ -73,6 +74,7 @@ def define_common_targets(): ], exported_deps = [ ":core", + "//executorch/runtime/core/portable_type/c10/c10:c10", ], visibility = [ "//executorch/...", @@ -145,13 +147,16 @@ def define_common_targets(): ":tensor_layout", ], ) - + runtime.cxx_library( name = "tensor_layout", srcs = ["tensor_layout.cpp"], exported_headers = ["tensor_layout.h"], + deps = [ + "//executorch/runtime/core/portable_type/c10/c10:c10", + ], exported_deps = [ - ":core", + ":core", "//executorch/runtime/core/exec_aten:lib", ], visibility = ["//executorch/..."], diff --git a/runtime/core/tensor_layout.cpp b/runtime/core/tensor_layout.cpp index 748a43fc5d6..f0fac442e20 100644 --- a/runtime/core/tensor_layout.cpp +++ b/runtime/core/tensor_layout.cpp @@ -6,6 +6,7 @@ * LICENSE file in the root directory of this source tree. */ +#include #include #include #include @@ -43,7 +44,7 @@ Result TensorLayout::create( return Error::InvalidArgument; } - for (size_t i = 0; i < dim_order.size(); i++) { + for (const auto i : c10::irange(dim_order.size())) { if (dim_order[i] >= sizes.size()) { return Error::InvalidArgument; } diff --git a/runtime/core/test/event_tracer_test.cpp b/runtime/core/test/event_tracer_test.cpp index 622de1ff9fa..9591d9c06ee 100644 --- a/runtime/core/test/event_tracer_test.cpp +++ b/runtime/core/test/event_tracer_test.cpp @@ -8,6 +8,7 @@ #include +#include #include #include #include @@ -207,7 +208,7 @@ TEST(TestEventTracer, SimpleEventTracerTest) { // and also with a null pointer (to test that the null case works). DummyEventTracer dummy; std::vector dummy_event_tracer_arr = {&dummy, nullptr}; - for (size_t i = 0; i < dummy_event_tracer_arr.size(); i++) { + for (const auto i : c10::irange(dummy_event_tracer_arr.size())) { RunSimpleTracerTest(&dummy); RunSimpleTracerTest(nullptr); } @@ -234,7 +235,7 @@ TEST(TestEventTracer, SimpleEventTracerTestDelegate) { // and also with a null pointer (to test that the null case works). DummyEventTracer dummy; std::vector dummy_event_tracer_arr = {&dummy, nullptr}; - for (size_t i = 0; i < dummy_event_tracer_arr.size(); i++) { + for (const auto i : c10::irange(dummy_event_tracer_arr.size())) { RunSimpleTracerTestDelegate(&dummy); RunSimpleTracerTestDelegate(nullptr); } diff --git a/runtime/core/test/memory_allocator_test.cpp b/runtime/core/test/memory_allocator_test.cpp index dfd2f23a488..f0fa44ae6e7 100644 --- a/runtime/core/test/memory_allocator_test.cpp +++ b/runtime/core/test/memory_allocator_test.cpp @@ -9,6 +9,7 @@ #include #include +#include #include #include #include @@ -62,12 +63,12 @@ TEST_F(MemoryAllocatorTest, MemoryAllocatorAlignment) { 128, 2}; - for (int i = 0; i < arr_size; i++) { + for (const auto i : c10::irange(arr_size)) { auto align_size = alignment[i]; constexpr size_t mem_size = 1000; uint8_t mem_pool[mem_size]; MemoryAllocator allocator = MemoryAllocator(mem_size, mem_pool); - for (int j = 0; j < arr_size; j++) { + for (const auto j : c10::irange(arr_size)) { auto size = allocation[j]; void* start = allocator.allocate(size, align_size); EXPECT_ALIGNED(start, align_size); @@ -81,7 +82,7 @@ TEST_F(MemoryAllocatorTest, MemoryAllocatorNonPowerOfTwoAlignment) { MemoryAllocator allocator(mem_size, mem_pool); size_t alignment[5] = {0, 5, 6, 12, 34}; - for (int i = 0; i < 5; i++) { + for (const auto i : c10::irange(5)) { ASSERT_EQ(nullptr, allocator.allocate(8, alignment[i])); } } diff --git a/runtime/core/test/targets.bzl b/runtime/core/test/targets.bzl index 7332aad8a3d..abe52bcadff 100644 --- a/runtime/core/test/targets.bzl +++ b/runtime/core/test/targets.bzl @@ -40,6 +40,7 @@ def define_common_targets(): ], deps = [ "//executorch/runtime/core:event_tracer", + "//executorch/runtime/core/portable_type/c10/c10:c10", ], ) @@ -68,6 +69,7 @@ def define_common_targets(): ], deps = [ "//executorch/runtime/core:memory_allocator", + "//executorch/runtime/core/portable_type/c10/c10:c10", ], )