// This file is part of Eigen, a lightweight C++ template library // for linear algebra. // // Copyright (C) 2020 Everton Constantino // // This Source Code Form is subject to the terms of the Mozilla // Public License v. 2.0. If a copy of the MPL was not distributed // with this file, You can obtain one at http://mozilla.org/MPL/2.0/ #include "main.h" // Disable "ignoring attributes on template argument" // for packet_traits // => The only workaround would be to wrap _m128 and the likes // within wrappers. #if EIGEN_GNUC_AT_LEAST(6,0) #pragma GCC diagnostic ignored "-Wignored-attributes" #endif #define GET(i,j) (StorageOrder == RowMajor ? (i)*stride + (j) : (i) + (j)*stride) #define SCATTER(i,j,k) (StorageOrder == RowMajor ? ((i)+(k))*stride + (j) : (i) + ((j)+(k))*stride) template void compare(const Packet& a, const Packet& b) { int pktsz = internal::packet_traits::size; Scalar *buffA = new Scalar[pktsz]; Scalar *buffB = new Scalar[pktsz]; internal::pstoreu(buffA, a); internal::pstoreu(buffB, b); for(int i = 0; i < pktsz; i++) { VERIFY_IS_EQUAL(buffA[i], buffB[i]); } delete[] buffA; delete[] buffB; } template struct PacketBlockSet { typedef typename internal::packet_traits::type Packet; void setPacketBlock(internal::PacketBlock& block, Scalar value) { for(int idx = 0; idx < n; idx++) { block.packet[idx] = internal::pset1(value); } } void comparePacketBlock(Scalar *data, int i, int j, int stride, internal::PacketBlock& block) { for(int idx = 0; idx < n; idx++) { Packet line = internal::ploadu(data + SCATTER(i,j,idx)); compare(block.packet[idx], line); } } }; template void run_bdmp_spec_1() { typedef internal::blas_data_mapper BlasDataMapper; int packetSize = internal::packet_traits::size; int minSize = std::max(packetSize, BlockSize); typedef typename internal::packet_traits::type Packet; int szm = internal::random(minSize,500), szn = internal::random(minSize,500); int stride = StorageOrder == RowMajor ? szn : szm; Scalar *d = new Scalar[szn*szm]; // Initializing with random entries for(int i = 0; i < szm*szn; i++) { d[i] = internal::random(static_cast(3), static_cast(10)); } BlasDataMapper bdm(d, stride); // Testing operator() for(int i = 0; i < szm; i++) { for(int j = 0; j < szn; j++) { VERIFY_IS_EQUAL(d[GET(i,j)], bdm(i,j)); } } // Testing getSubMapper and getLinearMapper int i0 = internal::random(0,szm-2); int j0 = internal::random(0,szn-2); for(int i = i0; i < szm; i++) { for(int j = j0; j < szn; j++) { const BlasDataMapper& bdmSM = bdm.getSubMapper(i0,j0); const internal::BlasLinearMapper& bdmLM = bdm.getLinearMapper(i0,j0); Scalar v = bdmSM(i - i0, j - j0); Scalar vd = d[GET(i,j)]; VERIFY_IS_EQUAL(vd, v); VERIFY_IS_EQUAL(vd, bdmLM(GET(i-i0, j-j0))); } } // Testing loadPacket for(int i = 0; i < szm - minSize; i++) { for(int j = 0; j < szn - minSize; j++) { Packet pktBDM = bdm.template loadPacket(i,j); Packet pktD = internal::ploadu(d + GET(i,j)); compare(pktBDM, pktD); } } // Testing gatherPacket Scalar *buff = new Scalar[packetSize]; for(int i = 0; i < szm - minSize; i++) { for(int j = 0; j < szn - minSize; j++) { Packet p = bdm.template gatherPacket(i,j); internal::pstoreu(buff, p); for(int k = 0; k < packetSize; k++) { VERIFY_IS_EQUAL(d[SCATTER(i,j,k)], buff[k]); } } } delete[] buff; // Testing scatterPacket for(int i = 0; i < szm - minSize; i++) { for(int j = 0; j < szn - minSize; j++) { Packet p = internal::pset1(static_cast(1)); bdm.template scatterPacket(i,j,p); for(int k = 0; k < packetSize; k++) { VERIFY_IS_EQUAL(d[SCATTER(i,j,k)], static_cast(1)); } } } //Testing storePacketBlock internal::PacketBlock block; PacketBlockSet pbs; pbs.setPacketBlock(block, static_cast(2)); for(int i = 0; i < szm - minSize; i++) { for(int j = 0; j < szn - minSize; j++) { bdm.template storePacketBlock(i, j, block); pbs.comparePacketBlock(d, i, j, stride, block); } } delete[] d; } template void run_test() { run_bdmp_spec_1(); run_bdmp_spec_1(); run_bdmp_spec_1(); run_bdmp_spec_1(); run_bdmp_spec_1(); run_bdmp_spec_1(); run_bdmp_spec_1(); run_bdmp_spec_1(); run_bdmp_spec_1(); run_bdmp_spec_1(); } EIGEN_DECLARE_TEST(blasutil) { for(int i = 0; i < g_repeat; i++) { CALL_SUBTEST_1(run_test()); CALL_SUBTEST_2(run_test()); CALL_SUBTEST_3(run_test()); // TODO: Replace this by a call to numext::int64_t as soon as we have a way to // detect the typedef for int64_t on all platforms #if EIGEN_HAS_CXX11 CALL_SUBTEST_4(run_test()); #else CALL_SUBTEST_4(run_test()); #endif CALL_SUBTEST_5(run_test()); CALL_SUBTEST_6(run_test()); CALL_SUBTEST_7(run_test >()); CALL_SUBTEST_8(run_test >()); } }