Re: [Libva] [PATCH v2] test: use valarray for raw image comparison
It works well for me, applied. Thanks Haihao >-Original Message- >From: Libva [mailto:libva-boun...@lists.freedesktop.org] On Behalf Of Eoff, >Ullysses A >Sent: Wednesday, October 19, 2016 2:38 AM >To: Phillips, Scott D <scott.d.phill...@intel.com>; libva@lists.freedesktop.org >Subject: Re: [Libva] [PATCH v2] test: use valarray for raw image comparison > >Ah, I overlooked the data types on my first review. Indeed it's important to >take it into account when diff'ing. This is why they were being cast to "int" >previously to calculate the diff. > >On my system /dev/urandom seems to work (i.e. not all zeros). But I agree, >let's drop it since it does not seem to be very uniform. > >This version looks much better to me. > >Thanks, > >U. Artie > >> -Original Message- >> From: Libva [mailto:libva-boun...@lists.freedesktop.org] On Behalf Of >> Scott D Phillips >> Sent: Monday, October 17, 2016 1:01 PM >> To: libva@lists.freedesktop.org >> Subject: [Libva] [PATCH v2] test: use valarray for raw image >> comparison >> >> std::valarray can fuse elementwise operations across arrays for more >> efficient comparison. >> >> Signed-off-by: Scott D Phillips <scott.d.phill...@intel.com> >> --- >> Changes since v1: >> - s/width * height/sizes/ >> - Added another array 'signs' which ensures that 0 and 255 never >> compare as separated by one. >> >> Also, the patch about /dev/urandom actually was accidentally >> generating all zeroes instead of random data. Fixing the bug there >> eliminated the performance gain, so I'm dropping that patch from the >> series. >> >> test/i965_jpeg_encode_test.cpp | 29 + >> 1 file changed, 13 insertions(+), 16 deletions(-) >> >> diff --git a/test/i965_jpeg_encode_test.cpp >> b/test/i965_jpeg_encode_test.cpp index 29c14dc..173cd93 100644 >> --- a/test/i965_jpeg_encode_test.cpp >> +++ b/test/i965_jpeg_encode_test.cpp >> @@ -30,6 +30,7 @@ >> #include >> #include >> #include >> +#include >> >> namespace JPEG { >> namespace Encode { >> @@ -400,23 +401,19 @@ protected: >> ASSERT_EQ(expect->height(), image.height); >> ASSERT_NO_FAILURE(uint8_t *data = >> mapBuffer(image.buf)); >> >> -auto isClose = [](const uint8_t& a, const uint8_t& b) { >> -return std::abs(int(a)-int(b)) <= 2; >> -}; >> - >> for (size_t i(0); i < image.num_planes; ++i) { >> -size_t w = expect->widths[i]; >> -size_t h = expect->heights[i]; >> - >> -const ByteData::value_type *source = expect->plane(i); >> -const uint8_t *result = data + image.offsets[i]; >> -ASSERT_GE(image.pitches[i], w); >> -for (size_t r(0); r < h; ++r) { >> -EXPECT_TRUE(std::equal(result, result + w, source, isClose)) >> -<< "Byte(s) mismatch in plane " << i << " row " << r; >> -source += w; >> -result += image.pitches[i]; >> -} >> +ASSERT_GE(image.pitches[i], expect->widths[i]); >> +std::valarray source(expect->plane(i), >> expect->sizes[i]); >> +std::gslice result_slice(0, {expect->heights[i], >> expect->widths[i]}, >> +{image.pitches[i], 1}); >> +std::valarray result = std::valarray( >> +data + image.offsets[i], >> +image.pitches[i] * expect->heights[i])[result_slice]; >> +std::valarray signs(1, result.size()); >> +signs[result > source] = -1; >> +ASSERT_EQ(source.size(), result.size()); >> +EXPECT_TRUE((source * signs - result * signs).max() <= 2) >> +<< "Byte(s) mismatch in plane " << i; >> } >> >> unmapBuffer(image.buf); >> -- >> 2.7.4 >> >> ___ >> Libva mailing list >> Libva@lists.freedesktop.org >> https://lists.freedesktop.org/mailman/listinfo/libva >___ >Libva mailing list >Libva@lists.freedesktop.org >https://lists.freedesktop.org/mailman/listinfo/libva ___ Libva mailing list Libva@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libva
Re: [Libva] [PATCH v2] test: use valarray for raw image comparison
Ah, I overlooked the data types on my first review. Indeed it's important to take it into account when diff'ing. This is why they were being cast to "int" previously to calculate the diff. On my system /dev/urandom seems to work (i.e. not all zeros). But I agree, let's drop it since it does not seem to be very uniform. This version looks much better to me. Thanks, U. Artie > -Original Message- > From: Libva [mailto:libva-boun...@lists.freedesktop.org] On Behalf Of Scott D > Phillips > Sent: Monday, October 17, 2016 1:01 PM > To: libva@lists.freedesktop.org > Subject: [Libva] [PATCH v2] test: use valarray for raw image comparison > > std::valarray can fuse elementwise operations across arrays for > more efficient comparison. > > Signed-off-by: Scott D Phillips <scott.d.phill...@intel.com> > --- > Changes since v1: > - s/width * height/sizes/ > - Added another array 'signs' which ensures that 0 and 255 never > compare as separated by one. > > Also, the patch about /dev/urandom actually was accidentally > generating all zeroes instead of random data. Fixing the bug > there eliminated the performance gain, so I'm dropping that patch > from the series. > > test/i965_jpeg_encode_test.cpp | 29 + > 1 file changed, 13 insertions(+), 16 deletions(-) > > diff --git a/test/i965_jpeg_encode_test.cpp b/test/i965_jpeg_encode_test.cpp > index 29c14dc..173cd93 100644 > --- a/test/i965_jpeg_encode_test.cpp > +++ b/test/i965_jpeg_encode_test.cpp > @@ -30,6 +30,7 @@ > #include > #include > #include > +#include > > namespace JPEG { > namespace Encode { > @@ -400,23 +401,19 @@ protected: > ASSERT_EQ(expect->height(), image.height); > ASSERT_NO_FAILURE(uint8_t *data = mapBuffer(image.buf)); > > -auto isClose = [](const uint8_t& a, const uint8_t& b) { > -return std::abs(int(a)-int(b)) <= 2; > -}; > - > for (size_t i(0); i < image.num_planes; ++i) { > -size_t w = expect->widths[i]; > -size_t h = expect->heights[i]; > - > -const ByteData::value_type *source = expect->plane(i); > -const uint8_t *result = data + image.offsets[i]; > -ASSERT_GE(image.pitches[i], w); > -for (size_t r(0); r < h; ++r) { > -EXPECT_TRUE(std::equal(result, result + w, source, isClose)) > -<< "Byte(s) mismatch in plane " << i << " row " << r; > -source += w; > -result += image.pitches[i]; > -} > +ASSERT_GE(image.pitches[i], expect->widths[i]); > +std::valarray source(expect->plane(i), > expect->sizes[i]); > +std::gslice result_slice(0, {expect->heights[i], > expect->widths[i]}, > +{image.pitches[i], 1}); > +std::valarray result = std::valarray( > +data + image.offsets[i], > +image.pitches[i] * expect->heights[i])[result_slice]; > +std::valarray signs(1, result.size()); > +signs[result > source] = -1; > +ASSERT_EQ(source.size(), result.size()); > +EXPECT_TRUE((source * signs - result * signs).max() <= 2) > +<< "Byte(s) mismatch in plane " << i; > } > > unmapBuffer(image.buf); > -- > 2.7.4 > > ___ > Libva mailing list > Libva@lists.freedesktop.org > https://lists.freedesktop.org/mailman/listinfo/libva ___ Libva mailing list Libva@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libva
[Libva] [PATCH v2] test: use valarray for raw image comparison
std::valarray can fuse elementwise operations across arrays for more efficient comparison. Signed-off-by: Scott D Phillips--- Changes since v1: - s/width * height/sizes/ - Added another array 'signs' which ensures that 0 and 255 never compare as separated by one. Also, the patch about /dev/urandom actually was accidentally generating all zeroes instead of random data. Fixing the bug there eliminated the performance gain, so I'm dropping that patch from the series. test/i965_jpeg_encode_test.cpp | 29 + 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/test/i965_jpeg_encode_test.cpp b/test/i965_jpeg_encode_test.cpp index 29c14dc..173cd93 100644 --- a/test/i965_jpeg_encode_test.cpp +++ b/test/i965_jpeg_encode_test.cpp @@ -30,6 +30,7 @@ #include #include #include +#include namespace JPEG { namespace Encode { @@ -400,23 +401,19 @@ protected: ASSERT_EQ(expect->height(), image.height); ASSERT_NO_FAILURE(uint8_t *data = mapBuffer(image.buf)); -auto isClose = [](const uint8_t& a, const uint8_t& b) { -return std::abs(int(a)-int(b)) <= 2; -}; - for (size_t i(0); i < image.num_planes; ++i) { -size_t w = expect->widths[i]; -size_t h = expect->heights[i]; - -const ByteData::value_type *source = expect->plane(i); -const uint8_t *result = data + image.offsets[i]; -ASSERT_GE(image.pitches[i], w); -for (size_t r(0); r < h; ++r) { -EXPECT_TRUE(std::equal(result, result + w, source, isClose)) -<< "Byte(s) mismatch in plane " << i << " row " << r; -source += w; -result += image.pitches[i]; -} +ASSERT_GE(image.pitches[i], expect->widths[i]); +std::valarray source(expect->plane(i), expect->sizes[i]); +std::gslice result_slice(0, {expect->heights[i], expect->widths[i]}, +{image.pitches[i], 1}); +std::valarray result = std::valarray( +data + image.offsets[i], +image.pitches[i] * expect->heights[i])[result_slice]; +std::valarray signs(1, result.size()); +signs[result > source] = -1; +ASSERT_EQ(source.size(), result.size()); +EXPECT_TRUE((source * signs - result * signs).max() <= 2) +<< "Byte(s) mismatch in plane " << i; } unmapBuffer(image.buf); -- 2.7.4 ___ Libva mailing list Libva@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libva