Skip to content

REF: Remove raw intrinsics from arithmetic operations - #10708

Closed
seiko2plus wants to merge 2 commits into
opencv:3.4from
seiko2plus:coreUnvintrinArithm
Closed

seiko2plus wants to merge 2 commits into
opencv:3.4from
seiko2plus:coreUnvintrinArithm

Conversation

@seiko2plus

@seiko2plus seiko2plus commented Jan 27, 2018 •

Copy link
Copy Markdown
Contributor

WORK IN PROGRESS

Don't Merge

Tasks

force_builders=Custom
docker_image:Custom=powerpc64le

@seiko2plus
seiko2plus force-pushed the coreUnvintrinArithm branch 2 times, most recently from f07ae91 to fbe1819 Compare January 30, 2018 23:41
@seiko2plus
seiko2plus force-pushed the coreUnvintrinArithm branch 2 times, most recently from 1940d42 to db2c0c6 Compare February 8, 2018 20:26

#ifndef CV_SIMD128
//! Set to 1 if current compiler supports vector extensions (NEON or SSE is enabled)
//! Set to 1 if current compiler supports vector extensions (NEON or SSE or VSX is enabled)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AVX?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just update doc for Power VSX. Please consider this branch isn't ready for review yet, I made so many changes and still working on other things. I would expect to finish it in a week or two.

@seiko2plus
seiko2plus force-pushed the coreUnvintrinArithm branch 8 times, most recently from 48b263f to 8a56515 Compare March 8, 2018 19:50
@kinchungwong

Copy link
Copy Markdown
Contributor

Can someone familiar with OpenCV - OpenVX integration comment on whether the prefix vx_, such as vx_uint8, can be used within the Wide Universal Intrinsics proposal namespace (cv, or cv::hal, or cv::hal_baseline), and does not affect OpenVX, which puts these typedefs under global namespace?

They are in different namespaces, but there are source code in OpenCV which will be exposed to both namespaces if HAVE_OPENVX is defined.

A quick check might be just compile with HAVE_OPENVX defined.
(I might be wrong since I'm a noob here.)

The README on https://github.com/opencv/opencv/tree/master/3rdparty/openvx gives a basic usage of OpenVX, by including "ivx.hpp", which pulls in "VX/vx.h", "VX/vx_types.h" (both of which are in OpenVX proper, https://github.com/GPUOpen-ProfessionalCompute-Libraries/amdovx-core/blob/develop/openvx/include

(Sorry I'm a noob here, please pardon if this question doesn't make sense.)

@seiko2plus

seiko2plus commented Mar 27, 2018 •

Copy link
Copy Markdown
Contributor Author

@kinchungwong, Aww My bad, I think you're right and I may have rushed into it.
Could you propose a different prefix?

They can be replaced to "xv_" or simply to v_uint8 as @vpisarev mentioned in OE-27?

i.e. xv_

xv_uint8 vec1 = xv_load(ptr);
xv_uint8 vec2 = xv_load_halves(ptr1, ptr2);
Data<R> trait = XV_RegTrait<LaneType>::zero();

i.e. v_x

v_xuint8 vec1  = v_xload(ptr);
v_xuint8 vec2  = v_xload_halves(ptr1, ptr2);
Data<R> trait  = V_XRegTrait<LaneType>::zero();

"Simply to v_uint8" looks better to me , but we still needs to add suffix to loaders since, v_load_* taken by simd128.

Thank you !

@kinchungwong

kinchungwong commented Mar 27, 2018 •

Copy link
Copy Markdown
Contributor

@seiko2plus

"Simply to v_uint8 " looks better to me , but we still needs to add suffix to loaders since, v_load_* taken by simd128.

I think @vpisarev already knew; which is why he suggested the simplest "v underscore" prefix in OE-27:

It's suggested to rename all the vector types used in universal intrinsics to something size-agnostic. Currently we use v_uint8x16 etc. types for the vector types. They can be renamed to v_uint8xn (or simply to v_uint8).

I would prefer keeping the xn suffix, to distinguish a vector (of any type) from a scalar, for mental reasons.


I would also look for another suffix (possibly a union or struct), to denote "array of underlying vector type", such as __m128i[4u], which can be used to emulate a 512-bit vector on SSE2.


"Simply to v_uint8" looks better to me , but we still needs to add suffix to loaders since, v_load_* taken by simd128.

As for v_load_*, I can mention a C++ programming trick. The idea is to create a dummy class that wraps the arguments (an untyped pointer), then add lots of overloaded conversion operators on it. By doing this, one can call a general function, and then call a specific overload by specifying the return type. This works around the issue of C++ typically not letting you choose an overload on return type. I don't know if it is good or bad taste according to @vpisarev , so I will wait for his comments first.

Sample code: https://github.com/kinchungwong/simd_style_helper/blob/master/simd_style_helper_loadstore.h#L168

Sample code: (in case my repo is deleted)

click to expand sample code section
class DummyLoader
{
private:
   const void* m_ptr;

public:
  DummyLoader(const void* ptr) : m_ptr(ptr) {}

  /* implicit */  operator v_elephant () const 
  { 
#if HAVE_BOAT
    return load_elephant_with_boat(m_ptr);
#elif HAVE_TRUCK
    return load_elephant_with_truck(m_ptr);
#endif
  }

  /* implicit */  operator v_bigcat () const 
  { 
#if HAVE_CAGE
    return load_bigcat_with_cage(m_ptr);
#else
   static_assert(false, "Bigcat not supported on this platform without CAGE enabled");
#endif
  }
};

template <typename ANIMAL>
ANIMAL load(const void* ptr)
{
   // calls implicit conversion operator
   // important reminder: this is NOT reinterpret-cast.
    return (ANIMAL)DummyLoader(ptr); 
}

Could someone from OpenCV, /cc @alalek @vpisarev @mshabunin , help coordinate the effort? E.g. have a central list of tasks and the name of people (currently) assigned, and some basic (temporary) design docs? A "touch base" time slot will also help.


Can CI catch this issue earlier? Is there at least one platform where HAVE_OPENVX is enabled (e.g. one with an AMD GPU; this is not an advertisement), and some OpenVX tests can be run on that build?


There's also need to coordinate the list of universal intrinsics (in particular the typedefs, macros, etc), see PR #11169 , where /cc @tomoaki0705 has a question about v_load_deinterleave which needs an answer (and more importantly, need coordinate and central design docs).


We also need to make sure any modifications on algorithm implementations (e.g. in imgproc, imgwarp, objdetect hog, etc) do not run into conflicts with the OE-15 bit-exactness initiative, /cc @terfendail . I understand that #10708 does not touch algorithm implementations yet, but it might happen soon.

@seiko2plus
seiko2plus force-pushed the coreUnvintrinArithm branch 2 times, most recently from 1ba50ab to 45ffb82 Compare April 7, 2018 15:52
@seiko2plus
seiko2plus force-pushed the coreUnvintrinArithm branch 2 times, most recently from abe3813 to 14518ee Compare April 15, 2018 01:44
@seiko2plus
seiko2plus force-pushed the coreUnvintrinArithm branch 3 times, most recently from 9aded9f to e230d24 Compare June 16, 2018 09:08
@vpisarev vpisarev mentioned this pull request Jul 12, 2018
4 of 6 tasks
@seiko2plus
seiko2plus force-pushed the coreUnvintrinArithm branch from e230d24 to b66b704 Compare July 12, 2018 15:50
@seiko2plus
seiko2plus force-pushed the coreUnvintrinArithm branch from b66b704 to c0dcd02 Compare July 12, 2018 16:06
@seiko2plus
seiko2plus force-pushed the coreUnvintrinArithm branch from c0dcd02 to 8b2a2b7 Compare July 12, 2018 16:11
@vpisarev

Copy link
Copy Markdown
Contributor

thank you, @seiko2plus! the PR is superseded by #11953, where I merged all the latest changes (hopefully)

@vpisarev vpisarev closed this Jul 16, 2018
@seiko2plus

Copy link
Copy Markdown
Contributor Author

@vpisarev, My pleasure! Yes, #11953 It covers the latest changes.. thank you

@seiko2plus seiko2plus changed the title core: Remove raw intrinsics from arithmetic operations REF: Remove raw intrinsics from arithmetic operations Jul 25, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants