Add neon intrinsics for aarch64

Related-To: NEO-6452

Signed-off-by: Sebastian Luzynski <sebastian.jozef.luzynski@intel.com>
This commit is contained in:
Sebastian Luzynski
2022-03-28 16:30:45 +00:00
committed by Compute-Runtime-Automation
parent c7d8915dd4
commit cf906030ac
16 changed files with 445 additions and 27 deletions

View File

@@ -25,5 +25,11 @@ set(IGDRCL_SRCS_tests_helpers
${CMAKE_CURRENT_SOURCE_DIR}/test_hw_info_config.cpp
)
if(COMPILER_SUPPORTS_NEON)
list(APPEND IGDRCL_SRCS_tests_helpers
${CMAKE_CURRENT_SOURCE_DIR}/uint16_neon_tests.cpp
)
endif()
target_sources(${TARGET_NAME} PRIVATE ${IGDRCL_SRCS_tests_helpers})
add_subdirectories()

View File

@@ -0,0 +1,111 @@
/*
* Copyright (C) 2022 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#include "shared/source/helpers/aarch64/uint16_neon.h"
#include "shared/source/helpers/aligned_memory.h"
#include "gtest/gtest.h"
using namespace NEO;
TEST(Uint16Neon, GivenNeonAndMaskWhenCastingToBoolThenTrueIsReturned) {
EXPECT_TRUE(static_cast<bool>(NEO::uint16x16_t::mask()));
}
TEST(Uint16Neon, GivenNeonAndZeroWhenCastingToBoolThenFalseIsReturned) {
EXPECT_FALSE(static_cast<bool>(NEO::uint16x16_t::zero()));
}
TEST(Uint16Neon, GivenNeonWhenConjoiningMaskAndZeroThenBooleanResultIsCorrect) {
EXPECT_TRUE(NEO::uint16x16_t::mask() && NEO::uint16x16_t::mask());
EXPECT_FALSE(NEO::uint16x16_t::mask() && NEO::uint16x16_t::zero());
EXPECT_FALSE(NEO::uint16x16_t::zero() && NEO::uint16x16_t::mask());
EXPECT_FALSE(NEO::uint16x16_t::zero() && NEO::uint16x16_t::zero());
}
TEST(Uint16Neon, GivenNeonAndOneWhenCreatingThenInstancesAreSame) {
auto one = NEO::uint16x16_t::one();
NEO::uint16x16_t alsoOne(one);
EXPECT_EQ(0, memcmp(&alsoOne, &one, sizeof(NEO::uint16x16_t)));
}
TEST(Uint16Neon, GivenNeonAndValueWhenCreatingThenConstructorIsReplicated) {
NEO::uint16x16_t allSevens(7u);
for (int i = 0; i < NEO::uint16x16_t::numChannels; ++i) {
EXPECT_EQ(7u, allSevens.get(i));
}
}
ALIGNAS(32)
static const uint16_t laneValues[] = {
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31};
TEST(Uint16Neon, GivenNeonAndArrayWhenCreatingThenConstructorIsReplicated) {
NEO::uint16x16_t lanes(laneValues);
for (int i = 0; i < NEO::uint16x16_t::numChannels; ++i) {
EXPECT_EQ(static_cast<uint16_t>(i), lanes.get(i));
}
}
TEST(Uint16Neon, GivenNeonWhenLoadingThenValuesAreSetCorrectly) {
NEO::uint16x16_t lanes;
lanes.load(laneValues);
for (int i = 0; i < NEO::uint16x16_t::numChannels; ++i) {
EXPECT_EQ(static_cast<uint16_t>(i), lanes.get(i));
}
}
TEST(Uint16Neon, GivenNeonWhenStoringThenValuesAreSetCorrectly) {
uint16_t *alignedMemory = reinterpret_cast<uint16_t *>(alignedMalloc(1024, 32));
NEO::uint16x16_t lanes(laneValues);
lanes.store(alignedMemory);
for (int i = 0; i < NEO::uint16x16_t::numChannels; ++i) {
EXPECT_EQ(static_cast<uint16_t>(i), alignedMemory[i]);
}
alignedFree(alignedMemory);
}
TEST(Uint16Neon, GivenNeonWhenDecrementingThenValuesAreSetCorrectly) {
NEO::uint16x16_t result(laneValues);
result -= NEO::uint16x16_t::one();
for (int i = 0; i < NEO::uint16x16_t::numChannels; ++i) {
EXPECT_EQ(static_cast<uint16_t>(i - 1), result.get(i));
}
}
TEST(Uint16Neon, GivenNeonWhenIncrementingThenValuesAreSetCorrectly) {
NEO::uint16x16_t result(laneValues);
result += NEO::uint16x16_t::one();
for (int i = 0; i < NEO::uint16x16_t::numChannels; ++i) {
EXPECT_EQ(static_cast<uint16_t>(i + 1), result.get(i));
}
}
TEST(Uint16Sse4, GivenNeonWhenBlendingThenValuesAreSetCorrectly) {
NEO::uint16x16_t a(NEO::uint16x16_t::one());
NEO::uint16x16_t b(NEO::uint16x16_t::zero());
NEO::uint16x16_t c;
// c = mask ? a : b
c = blend(a, b, NEO::uint16x16_t::mask());
for (int i = 0; i < NEO::uint16x16_t::numChannels; ++i) {
EXPECT_EQ(a.get(i), c.get(i));
}
// c = mask ? a : b
c = blend(a, b, NEO::uint16x16_t::zero());
for (int i = 0; i < NEO::uint16x16_t::numChannels; ++i) {
EXPECT_EQ(b.get(i), c.get(i));
}
}

View File

@@ -0,0 +1,12 @@
#
# Copyright (C) 2022 Intel Corporation
#
# SPDX-License-Identifier: MIT
#
if(${NEO_TARGET_PROCESSOR} STREQUAL "aarch64")
target_sources(${TARGET_NAME} PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt
${CMAKE_CURRENT_SOURCE_DIR}/cpuinfo_tests_aarch64.cpp
)
endif()

View File

@@ -0,0 +1,38 @@
/*
* Copyright (C) 2022 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#include "shared/source/helpers/file_io.h"
#include "shared/source/os_interface/linux/os_inc.h"
#include "shared/source/utilities/cpu_info.h"
#include "shared/test/common/helpers/variable_backup.h"
#include "gtest/gtest.h"
#include <cstdio>
#include <fstream>
using namespace NEO;
TEST(CpuInfoAarch64, givenProcCpuinfoFileExistsWhenIsCpuFlagPresentIsCalledThenValidValueIsReturned) {
VariableBackup<const char *> pathPrefixBackup(&Os::sysFsProcPathPrefix, "./test_files");
std::string cpuinfoFile = "./test_files/cpuinfo";
EXPECT_FALSE(fileExists(cpuinfoFile));
{
std::ofstream cpuinfo(cpuinfoFile);
cpuinfo << "processor\t\t: 0\nFeatures\t\t: flag1 flag2 flag3\n";
}
EXPECT_TRUE(fileExists(cpuinfoFile));
CpuInfo testCpuInfo;
EXPECT_TRUE(testCpuInfo.isCpuFlagPresent("flag1"));
EXPECT_TRUE(testCpuInfo.isCpuFlagPresent("flag2"));
EXPECT_FALSE(testCpuInfo.isCpuFlagPresent("nonExistingCpuFlag"));
std::remove(cpuinfoFile.c_str());
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2021 Intel Corporation
* Copyright (C) 2021-2022 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@@ -17,26 +17,6 @@
using namespace NEO;
TEST(CpuInfo, givenProcCpuinfoFileExistsWhenIsCpuFlagPresentIsCalledThenValidValueIsReturned) {
VariableBackup<const char *> pathPrefixBackup(&Os::sysFsProcPathPrefix, "./test_files");
std::string cpuinfoFile = "./test_files/cpuinfo";
EXPECT_FALSE(fileExists(cpuinfoFile));
{
std::ofstream cpuinfo(cpuinfoFile);
cpuinfo << "processor\t\t: 0\nflags\t\t: flag1 flag2 flag3\n";
}
EXPECT_TRUE(fileExists(cpuinfoFile));
CpuInfo testCpuInfo;
EXPECT_TRUE(testCpuInfo.isCpuFlagPresent("flag1"));
EXPECT_TRUE(testCpuInfo.isCpuFlagPresent("flag2"));
EXPECT_FALSE(testCpuInfo.isCpuFlagPresent("nonExistingCpuFlag"));
std::remove(cpuinfoFile.c_str());
}
TEST(CpuInfo, givenProcCpuinfoFileIsNotExistsWhenIsCpuFlagPresentIsCalledThenValidValueIsReturned) {
std::string cpuinfoFile = "test_files/linux/proc/cpuinfo";
EXPECT_FALSE(fileExists(cpuinfoFile));

View File

@@ -1,5 +1,5 @@
#
# Copyright (C) 2021 Intel Corporation
# Copyright (C) 2021-2022 Intel Corporation
#
# SPDX-License-Identifier: MIT
#
@@ -9,4 +9,6 @@ if(${NEO_TARGET_PROCESSOR} STREQUAL "x86_64")
${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt
${CMAKE_CURRENT_SOURCE_DIR}/cpuinfo_tests_x86_64.cpp
)
add_subdirectories()
endif()

View File

@@ -0,0 +1,11 @@
#
# Copyright (C) 2022 Intel Corporation
#
# SPDX-License-Identifier: MIT
#
if(UNIX)
target_sources(${TARGET_NAME} PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/cpuinfo_tests_x86_64_linux.cpp
)
endif()

View File

@@ -0,0 +1,38 @@
/*
* Copyright (C) 2022 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#include "shared/source/helpers/file_io.h"
#include "shared/source/os_interface/linux/os_inc.h"
#include "shared/source/utilities/cpu_info.h"
#include "shared/test/common/helpers/variable_backup.h"
#include "gtest/gtest.h"
#include <cstdio>
#include <fstream>
using namespace NEO;
TEST(CpuInfo, givenProcCpuinfoFileExistsWhenIsCpuFlagPresentIsCalledThenValidValueIsReturned) {
VariableBackup<const char *> pathPrefixBackup(&Os::sysFsProcPathPrefix, "./test_files");
std::string cpuinfoFile = "./test_files/cpuinfo";
EXPECT_FALSE(fileExists(cpuinfoFile));
{
std::ofstream cpuinfo(cpuinfoFile);
cpuinfo << "processor\t\t: 0\nflags\t\t: flag1 flag2 flag3\n";
}
EXPECT_TRUE(fileExists(cpuinfoFile));
CpuInfo testCpuInfo;
EXPECT_TRUE(testCpuInfo.isCpuFlagPresent("flag1"));
EXPECT_TRUE(testCpuInfo.isCpuFlagPresent("flag2"));
EXPECT_FALSE(testCpuInfo.isCpuFlagPresent("nonExistingCpuFlag"));
std::remove(cpuinfoFile.c_str());
}