Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions SerialPrograms/Source/Kernels/Kernels_Tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "ImageFilters/Kernels_ImageFilter_Tests.h"
#include "ImageScaleBrightness/Kernels_ImageScaleBrightness_Tests.h"
#include "ImageStats/Kernels_ImageStats_Tests.h"
#include "ScaleInvariantMatrixMatch/Kernels_ScaleInvariantMatrixMatch.h"
#include "SpikeConvolution/Kernels_SpikeConvolution.h"
#include "Waterfill/Kernels_Waterfill_Tests.h"

Expand All @@ -34,6 +35,7 @@ void add_tests(UnitTestDatabase& database){
add_tests_ImageFilters(database);
add_tests_ImageScaleBrightness(database);
add_tests_ImageStats(database);
ScaleInvariantMatrixMatch::add_tests(database);
SpikeConvolution::add_tests(database);
add_tests_Waterfill(database);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
*
*/

#include "Common/Cpp/Exceptions.h"
#include "Common/Cpp/CpuId/CpuId.h"
#include "Common/Cpp/TestRunners/UnitTestDatabase.h"

namespace PokemonAutomation{
namespace Kernels{
Expand Down Expand Up @@ -81,6 +81,10 @@ float compute_error_min4_x86_SSE (size_t width, size_t height, float scale, f
float compute_error_min8_x86_AVX2 (size_t width, size_t height, float scale, float const* const* A, float const* const* TW, float const* const* W);
float compute_error_min16_x86_AVX512(size_t width, size_t height, float scale, float const* const* A, float const* const* TW, float const* const* W);

void add_tests_x86_SSE(UnitTestDatabase& database);
void add_tests_x86_AVX2(UnitTestDatabase& database);
void add_tests_x86_AVX512(UnitTestDatabase& database);

float compute_error(
size_t width, size_t height,
float scale,
Expand Down Expand Up @@ -130,6 +134,30 @@ float compute_error(
}


//
// Register the tests for the ISAs this binary can run. Each ISA checks its
// results against the Default path, which is the source of truth, so the
// Default path itself gets no tests.
//
void add_tests(UnitTestDatabase& database){
#ifdef PA_AutoDispatch_x64_08_Nehalem
if (CPU_CAPABILITY_CURRENT.OK_08_Nehalem){
add_tests_x86_SSE(database);
}
#endif
#ifdef PA_AutoDispatch_x64_13_Haswell
if (CPU_CAPABILITY_CURRENT.OK_13_Haswell){
add_tests_x86_AVX2(database);
}
#endif
#ifdef PA_AutoDispatch_x64_17_Skylake
if (CPU_CAPABILITY_CURRENT.OK_17_Skylake){
add_tests_x86_AVX512(database);
}
#endif
}





Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
#define PokemonAutomation_Kernels_ScaleInvariantMatrixMatch_H

namespace PokemonAutomation{

class UnitTestDatabase;

namespace Kernels{
namespace ScaleInvariantMatrixMatch{

Expand Down Expand Up @@ -54,6 +57,8 @@ float compute_error(



void add_tests(UnitTestDatabase& database);



}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
#include "Kernels/Kernels_x64_AVX2.h"
#include "Kernels/PartialWordAccess/Kernels_PartialWordAccess_x64_AVX2.h"
#include "Kernels_ScaleInvariantMatrixMatch_Routines.h"
#include "Common/Cpp/TestRunners/UnitTestDatabase.h"
#include "Kernels_ScaleInvariantMatrixMatch_TestInfra.h"

namespace PokemonAutomation{
namespace Kernels{
Expand Down Expand Up @@ -126,6 +128,43 @@ float compute_error_min8_x86_AVX2(



float compute_scale_Default(size_t width, size_t height, float const* const* A, float const* const* T);
float compute_scale_Default(size_t width, size_t height, float const* const* A, float const* const* TW, float const* const* W);
float compute_error_Default(size_t width, size_t height, float scale, float const* const* A, float const* const* T);
float compute_error_Default(size_t width, size_t height, float scale, float const* const* A, float const* const* TW, float const* const* W);

class Test_x86_AVX2 : public Test{
public:
Test_x86_AVX2(size_t width, size_t height, bool use_weights)
: Test(
"x86_AVX2",
width, height,
use_weights,
compute_scale_Default,
compute_scale_min8_x86_AVX2,
compute_scale_Default,
compute_scale_min8_x86_AVX2,
compute_error_Default,
compute_error_min8_x86_AVX2,
compute_error_Default,
compute_error_min8_x86_AVX2
)
{}
};
void add_tests_x86_AVX2(UnitTestDatabase& database){
// The kernel requires a minimum row width (the partial-row loads span up to
// a full vector); sizes below that are not registered for this ISA.
for (size_t i = 0; i < sizeof(kTestSizes) / sizeof(kTestSizes[0]); i++){
if (kTestSizes[i][0] < 8){
continue;
}
database.add<Test_x86_AVX2>(kTestSizes[i][0], kTestSizes[i][1], false);
database.add<Test_x86_AVX2>(kTestSizes[i][0], kTestSizes[i][1], true);
}
}



}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

#include <immintrin.h>
#include "Kernels_ScaleInvariantMatrixMatch_Routines.h"
#include "Common/Cpp/TestRunners/UnitTestDatabase.h"
#include "Kernels_ScaleInvariantMatrixMatch_TestInfra.h"

namespace PokemonAutomation{
namespace Kernels{
Expand Down Expand Up @@ -118,6 +120,43 @@ float compute_error_min16_x86_AVX512(



float compute_scale_Default(size_t width, size_t height, float const* const* A, float const* const* T);
float compute_scale_Default(size_t width, size_t height, float const* const* A, float const* const* TW, float const* const* W);
float compute_error_Default(size_t width, size_t height, float scale, float const* const* A, float const* const* T);
float compute_error_Default(size_t width, size_t height, float scale, float const* const* A, float const* const* TW, float const* const* W);

class Test_x86_AVX512 : public Test{
public:
Test_x86_AVX512(size_t width, size_t height, bool use_weights)
: Test(
"x86_AVX512",
width, height,
use_weights,
compute_scale_Default,
compute_scale_min16_x86_AVX512,
compute_scale_Default,
compute_scale_min16_x86_AVX512,
compute_error_Default,
compute_error_min16_x86_AVX512,
compute_error_Default,
compute_error_min16_x86_AVX512
)
{}
};
void add_tests_x86_AVX512(UnitTestDatabase& database){
// The kernel requires a minimum row width (the partial-row loads span up to
// a full vector); sizes below that are not registered for this ISA.
for (size_t i = 0; i < sizeof(kTestSizes) / sizeof(kTestSizes[0]); i++){
if (kTestSizes[i][0] < 16){
continue;
}
database.add<Test_x86_AVX512>(kTestSizes[i][0], kTestSizes[i][1], false);
database.add<Test_x86_AVX512>(kTestSizes[i][0], kTestSizes[i][1], true);
}
}



}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
#include "Kernels/Kernels_x64_SSE41.h"
#include "Kernels/PartialWordAccess/Kernels_PartialWordAccess_x64_SSE41.h"
#include "Kernels_ScaleInvariantMatrixMatch_Routines.h"
#include "Common/Cpp/TestRunners/UnitTestDatabase.h"
#include "Kernels_ScaleInvariantMatrixMatch_TestInfra.h"

namespace PokemonAutomation{
namespace Kernels{
Expand Down Expand Up @@ -120,6 +122,43 @@ float compute_error_min4_x86_SSE(



float compute_scale_Default(size_t width, size_t height, float const* const* A, float const* const* T);
float compute_scale_Default(size_t width, size_t height, float const* const* A, float const* const* TW, float const* const* W);
float compute_error_Default(size_t width, size_t height, float scale, float const* const* A, float const* const* T);
float compute_error_Default(size_t width, size_t height, float scale, float const* const* A, float const* const* TW, float const* const* W);

class Test_x86_SSE : public Test{
public:
Test_x86_SSE(size_t width, size_t height, bool use_weights)
: Test(
"x86_SSE",
width, height,
use_weights,
compute_scale_Default,
compute_scale_min4_x86_SSE,
compute_scale_Default,
compute_scale_min4_x86_SSE,
compute_error_Default,
compute_error_min4_x86_SSE,
compute_error_Default,
compute_error_min4_x86_SSE
)
{}
};
void add_tests_x86_SSE(UnitTestDatabase& database){
// The kernel requires a minimum row width (the partial-row loads span up to
// a full vector); sizes below that are not registered for this ISA.
for (size_t i = 0; i < sizeof(kTestSizes) / sizeof(kTestSizes[0]); i++){
if (kTestSizes[i][0] < 4){
continue;
}
database.add<Test_x86_SSE>(kTestSizes[i][0], kTestSizes[i][1], false);
database.add<Test_x86_SSE>(kTestSizes[i][0], kTestSizes[i][1], true);
}
}



}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,18 @@ struct SumATA2{
using vtype = typename Context::vtype;
static constexpr size_t VECTOR_LENGTH = sizeof(vtype) / sizeof(float);

vtype sum_AT = Context::vzero();
vtype sum_A2 = Context::vzero();
vtype sum_AT;
vtype sum_A2;

// An explicit default constructor is required: with only non-static data
// member initializers, the implicit default constructor does not zero the
// accumulators at -O0 on x86, leaving stale stack contents in the lanes
// (observed with gcc and Apple clang; the user-defined constructor of
// SumError initializes correctly under the same conditions).
PA_FORCE_INLINE SumATA2()
: sum_AT(Context::vzero())
, sum_A2(Context::vzero())
{}

PA_FORCE_INLINE float scale() const{
return Context::vreduce(sum_AT) / Context::vreduce(sum_A2);
Expand Down Expand Up @@ -98,7 +108,7 @@ struct SumATA2{
if constexpr (VECTOR_LENGTH > 1){
if (length){
vtype a0, t0;
Context::load2_partial_front(length, a0, ptrT, t0, ptrA);
Context::load2_partial_front(length, a0, ptrA, t0, ptrT);
sum_at0 = Context::vpma(a0, t0, sum_at0);
sum_as0 = Context::vpma(a0, a0, sum_as0);
}
Expand Down Expand Up @@ -186,7 +196,7 @@ struct SumATA2{
}
if (length){
vtype a0, t0, w0;
Context::load3_partial_front(length, a0, A, t0, TW, w0, W);
Context::load3_partial_front(length, a0, ptrA, t0, ptrT, w0, ptrW);
a0 = Context::vmul(a0, w0);
sum_as0 = Context::vpma(a0, a0, sum_as0);
sum_at0 = Context::vpma(a0, t0, sum_at0);
Expand All @@ -205,10 +215,11 @@ struct SumError{
static constexpr size_t VECTOR_LENGTH = sizeof(vtype) / sizeof(float);

vtype scale;
vtype sum = Context::vzero();
vtype sum;

PA_FORCE_INLINE SumError(float p_scale)
: scale(Context::vset(p_scale))
, sum(Context::vzero())
{}

PA_FORCE_INLINE float sum_sqr() const{
Expand Down Expand Up @@ -271,7 +282,7 @@ struct SumError{
}
if (length){
vtype a0, t0;
Context::load2_partial_front(length, a0, ptrT, t0, ptrA);
Context::load2_partial_front(length, a0, ptrA, t0, ptrT);
a0 = Context::vpms(scale, a0, t0);
sum0 = Context::vpma(a0, a0, sum0);
}
Expand Down Expand Up @@ -345,7 +356,7 @@ struct SumError{
}
if (length){
vtype a0, t0, w0;
Context::load3_partial_front(length, a0, A, t0, TW, w0, W);
Context::load3_partial_front(length, a0, ptrA, t0, ptrT, w0, ptrW);
a0 = Context::vmul(scale, a0);
a0 = Context::vpms(a0, w0, t0);
sum0 = Context::vpma(a0, a0, sum0);
Expand Down
Loading
Loading