From d3d8b6f905fe1e524022b7ac2d7fa18caa2f7083 Mon Sep 17 00:00:00 2001 From: Kamil Diedrich Date: Mon, 13 Aug 2018 09:27:49 +0200 Subject: [PATCH] change ARRAY_COUNT macro to constexpr Change-Id: I027c4e70e3b901f3ffb3c0971935ae67e971db07 --- offline_compiler/options.cpp | 4 ++-- runtime/command_stream/command_stream_receiver.cpp | 4 ++-- runtime/dll/options.cpp | 2 +- runtime/helpers/array_count.h | 4 +--- runtime/helpers/options.cpp | 4 ++-- runtime/helpers/surface_formats.cpp | 14 +++++++------- unit_tests/context/context_multi_device_tests.cpp | 4 ++-- unit_tests/mem_obj/image_snorm_tests.cpp | 14 +++++++------- unit_tests/mem_obj/image_validate_tests.cpp | 2 +- .../offline_compiler/offline_compiler_tests.cpp | 2 -- unit_tests/options.cpp | 4 ++-- 11 files changed, 27 insertions(+), 31 deletions(-) diff --git a/offline_compiler/options.cpp b/offline_compiler/options.cpp index 4150876952..dc5413e942 100644 --- a/offline_compiler/options.cpp +++ b/offline_compiler/options.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, Intel Corporation + * Copyright (c) 2017 - 2018, Intel Corporation * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), @@ -38,6 +38,6 @@ static const HardwareInfo *DefaultPlatformDevices[] = &DEFAULT_PLATFORM::hwInfo, }; -size_t numPlatformDevices = ARRAY_COUNT(DefaultPlatformDevices); +size_t numPlatformDevices = arrayCount(DefaultPlatformDevices); const HardwareInfo **platformDevices = DefaultPlatformDevices; } // namespace OCLRT diff --git a/runtime/command_stream/command_stream_receiver.cpp b/runtime/command_stream/command_stream_receiver.cpp index 4c0169ae0f..8123951aea 100644 --- a/runtime/command_stream/command_stream_receiver.cpp +++ b/runtime/command_stream/command_stream_receiver.cpp @@ -270,7 +270,7 @@ GraphicsAllocation *CommandStreamReceiver::allocateDebugSurface(size_t size) { IndirectHeap &CommandStreamReceiver::getIndirectHeap(IndirectHeap::Type heapType, size_t minRequiredSize) { - DEBUG_BREAK_IF(static_cast(heapType) >= ARRAY_COUNT(indirectHeap)); + DEBUG_BREAK_IF(static_cast(heapType) >= arrayCount(indirectHeap)); auto &heap = indirectHeap[heapType]; GraphicsAllocation *heapMemory = nullptr; @@ -332,7 +332,7 @@ void CommandStreamReceiver::allocateHeapMemory(IndirectHeap::Type heapType, } void CommandStreamReceiver::releaseIndirectHeap(IndirectHeap::Type heapType) { - DEBUG_BREAK_IF(static_cast(heapType) >= ARRAY_COUNT(indirectHeap)); + DEBUG_BREAK_IF(static_cast(heapType) >= arrayCount(indirectHeap)); auto &heap = indirectHeap[heapType]; if (heap) { diff --git a/runtime/dll/options.cpp b/runtime/dll/options.cpp index b4bd1d1b12..a7a5376e66 100644 --- a/runtime/dll/options.cpp +++ b/runtime/dll/options.cpp @@ -36,6 +36,6 @@ static const HardwareInfo *DefaultPlatformDevices[] = { &DEFAULT_PLATFORM::hwInfo, }; -size_t numPlatformDevices = ARRAY_COUNT(DefaultPlatformDevices); +size_t numPlatformDevices = arrayCount(DefaultPlatformDevices); const HardwareInfo **platformDevices = DefaultPlatformDevices; } // namespace OCLRT diff --git a/runtime/helpers/array_count.h b/runtime/helpers/array_count.h index c3b8c39888..eafcf73d84 100644 --- a/runtime/helpers/array_count.h +++ b/runtime/helpers/array_count.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, Intel Corporation + * Copyright (c) 2017 - 2018, Intel Corporation * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), @@ -24,8 +24,6 @@ #include -#define ARRAY_COUNT(x) static_cast(sizeof(x) / sizeof(x[0])) - template constexpr size_t arrayCount(const T (&)[N]) { return N; diff --git a/runtime/helpers/options.cpp b/runtime/helpers/options.cpp index d6ec5aa9e1..73568d2485 100644 --- a/runtime/helpers/options.cpp +++ b/runtime/helpers/options.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, Intel Corporation + * Copyright (c) 2017 - 2018, Intel Corporation * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), @@ -36,6 +36,6 @@ uint32_t initialHardwareTag = (uint32_t)-1; static const HardwareInfo *DefaultPlatformDevices[] = { &DEFAULT_PLATFORM::hwInfo}; -size_t numPlatformDevices = ARRAY_COUNT(DefaultPlatformDevices); +size_t numPlatformDevices = arrayCount(DefaultPlatformDevices); const HardwareInfo **platformDevices = DefaultPlatformDevices; } // namespace OCLRT diff --git a/runtime/helpers/surface_formats.cpp b/runtime/helpers/surface_formats.cpp index 4e7388ec55..b6a12d5f5b 100644 --- a/runtime/helpers/surface_formats.cpp +++ b/runtime/helpers/surface_formats.cpp @@ -193,8 +193,8 @@ const SurfaceFormatInfo planarYuvSurfaceFormats[] = { {{CL_NV12_INTEL, CL_UNORM_INT8}, GMM_FORMAT_NV12, GFX3DSTATE_SURFACEFORMAT_NV12 , 0, 1, 1, 1} }; -const size_t numPackedYuvSurfaceFormats = ARRAY_COUNT(packedYuvSurfaceFormats); -const size_t numPlanarYuvSurfaceFormats = ARRAY_COUNT(planarYuvSurfaceFormats); +const size_t numPackedYuvSurfaceFormats = arrayCount(packedYuvSurfaceFormats); +const size_t numPlanarYuvSurfaceFormats = arrayCount(planarYuvSurfaceFormats); #endif const SurfaceFormatInfo readOnlyDepthSurfaceFormats[] = { @@ -209,13 +209,13 @@ const SurfaceFormatInfo readWriteDepthSurfaceFormats[] = { {{ CL_DEPTH, CL_UNORM_INT16}, GMM_FORMAT_R16_UNORM_TYPE, GFX3DSTATE_SURFACEFORMAT_R16_UNORM , 0, 1, 2, 2} }; -const size_t numReadOnlyDepthSurfaceFormats = ARRAY_COUNT(readOnlyDepthSurfaceFormats); -const size_t numReadWriteDepthSurfaceFormats = ARRAY_COUNT(readWriteDepthSurfaceFormats); +const size_t numReadOnlyDepthSurfaceFormats = arrayCount(readOnlyDepthSurfaceFormats); +const size_t numReadWriteDepthSurfaceFormats = arrayCount(readWriteDepthSurfaceFormats); -const size_t numReadOnlySurfaceFormats = ARRAY_COUNT(readOnlySurfaceFormats); -const size_t numWriteOnlySurfaceFormats = ARRAY_COUNT(writeOnlySurfaceFormats); -const size_t numReadWriteSurfaceFormats = ARRAY_COUNT(readWriteSurfaceFormats); +const size_t numReadOnlySurfaceFormats = arrayCount(readOnlySurfaceFormats); +const size_t numWriteOnlySurfaceFormats = arrayCount(writeOnlySurfaceFormats); +const size_t numReadWriteSurfaceFormats = arrayCount(readWriteSurfaceFormats); // clang-format on } // namespace OCLRT diff --git a/unit_tests/context/context_multi_device_tests.cpp b/unit_tests/context/context_multi_device_tests.cpp index 85dbff1bfa..c49a32cd23 100644 --- a/unit_tests/context/context_multi_device_tests.cpp +++ b/unit_tests/context/context_multi_device_tests.cpp @@ -32,7 +32,7 @@ using namespace OCLRT; TEST(ContextMultiDevice, singleDevice) { cl_device_id devices[] = { MockDevice::createWithNewExecutionEnvironment(nullptr)}; - auto numDevices = ARRAY_COUNT(devices); + auto numDevices = static_cast(arrayCount(devices)); auto retVal = CL_SUCCESS; auto pContext = Context::create(nullptr, DeviceVector(devices, numDevices), @@ -68,7 +68,7 @@ TEST(ContextMultiDevice, eightDevices) { MockDevice::createWithNewExecutionEnvironment(nullptr), MockDevice::createWithNewExecutionEnvironment(nullptr), MockDevice::createWithNewExecutionEnvironment(nullptr)}; - auto numDevices = ARRAY_COUNT(devices); + auto numDevices = static_cast(arrayCount(devices)); ASSERT_EQ(8u, numDevices); auto retVal = CL_SUCCESS; diff --git a/unit_tests/mem_obj/image_snorm_tests.cpp b/unit_tests/mem_obj/image_snorm_tests.cpp index 16ce46a125..9f7c6a0d8e 100644 --- a/unit_tests/mem_obj/image_snorm_tests.cpp +++ b/unit_tests/mem_obj/image_snorm_tests.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, Intel Corporation + * Copyright (c) 2017 - 2018, Intel Corporation * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), @@ -29,10 +29,10 @@ using namespace OCLRT; const cl_mem_flags flagsForTests[] = {CL_MEM_READ_ONLY, CL_MEM_WRITE_ONLY, CL_MEM_READ_WRITE}; -const std::tuple paramsForSnormTests[] = { - std::make_tuple(readOnlySurfaceFormats, numReadOnlySurfaceFormats), - std::make_tuple(writeOnlySurfaceFormats, numWriteOnlySurfaceFormats), - std::make_tuple(readWriteSurfaceFormats, numReadWriteSurfaceFormats), +const std::tuple paramsForSnormTests[] = { + std::make_tuple(readOnlySurfaceFormats, &numReadOnlySurfaceFormats), + std::make_tuple(writeOnlySurfaceFormats, &numWriteOnlySurfaceFormats), + std::make_tuple(readWriteSurfaceFormats, &numReadWriteSurfaceFormats), }; const std::array referenceSnormSurfaceFormats = {{ @@ -60,11 +60,11 @@ TEST_P(SnormSurfaceFormatAccessFlagsTests, givenSnormFormatWhenGetSurfaceFormatF } } -using SnormSurfaceFormatTests = ::testing::TestWithParam>; +using SnormSurfaceFormatTests = ::testing::TestWithParam>; TEST_P(SnormSurfaceFormatTests, givenSnormOclFormatWhenCheckingrReadOnlySurfaceFormatsThenFindExactCount) { const SurfaceFormatInfo *formatsTable = std::get<0>(GetParam()); - size_t formatsTableCount = std::get<1>(GetParam()); + size_t formatsTableCount = *std::get<1>(GetParam()); size_t snormFormatsFound = 0; for (size_t i = 0; i < formatsTableCount; i++) { diff --git a/unit_tests/mem_obj/image_validate_tests.cpp b/unit_tests/mem_obj/image_validate_tests.cpp index b3dc15e0b8..acef82d717 100644 --- a/unit_tests/mem_obj/image_validate_tests.cpp +++ b/unit_tests/mem_obj/image_validate_tests.cpp @@ -809,7 +809,7 @@ TEST_P(ValidParentImageFormatTest, givenParentChannelOrderWhenTestWithAllChannel image.imageFormat = parentImageFormat; bool retVal; - for (unsigned int i = 0; i < ARRAY_COUNT(allChannelOrders); i++) { + for (unsigned int i = 0; i < arrayCount(allChannelOrders); i++) { imageFormat.image_channel_order = allChannelOrders[i]; retVal = image.hasValidParentImageFormat(imageFormat); EXPECT_EQ(imageFormat.image_channel_order == validChannelOrder, retVal); diff --git a/unit_tests/offline_compiler/offline_compiler_tests.cpp b/unit_tests/offline_compiler/offline_compiler_tests.cpp index a8a51eeed4..6b4968a022 100644 --- a/unit_tests/offline_compiler/offline_compiler_tests.cpp +++ b/unit_tests/offline_compiler/offline_compiler_tests.cpp @@ -33,8 +33,6 @@ #include -#define ARRAY_COUNT(x) (sizeof(x) / sizeof(x[0])) - extern Environment *gEnvironment; namespace OCLRT { diff --git a/unit_tests/options.cpp b/unit_tests/options.cpp index b38ef3e1f9..14befcaef2 100644 --- a/unit_tests/options.cpp +++ b/unit_tests/options.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, Intel Corporation + * Copyright (c) 2017 - 2018, Intel Corporation * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), @@ -34,6 +34,6 @@ static const HardwareInfo *DefaultPlatformDevices[] = { &DEFAULT_TEST_PLATFORM::hwInfo, }; -size_t numPlatformDevices = ARRAY_COUNT(DefaultPlatformDevices); +size_t numPlatformDevices = arrayCount(DefaultPlatformDevices); const HardwareInfo **platformDevices = DefaultPlatformDevices; } // namespace OCLRT