Passing vectors from C++

144 views
Skip to first unread message

Edward Catchpole

unread,
May 30, 2019, 10:49:57 AM5/30/19
to Intel SPMD Program Compiler Users
Is there a way to pass our C++ maths vector class to an ISPC export function as a short vector? It feels like there must be a way to do this, but the compiler denies it's possible, and the docs don't mention anything at all.

A simple example:
// test.ispc
export uniform float<3> AddVectors(uniform float<3> a, uniform float<3> b)
{
   
return a + b;
}


// Vector.h
class Vector
{
public:
   
float X;
   
float Y;
   
float Z;


   
/* snip operators and helper functions */
};


// Test.cpp
Vector a = {1.f, 2.f, 3.f};
Vector b = {4.f, 5.f, 6.f};

Vector result = ispc::AddVectors(a, b);



This returns ispc errors complaining about the use of short vectors in the function signature:
<source>:42:25: Error: Illegal to return a "varying" or vector type from
        exported function "AddVectors"

export uniform float<3> AddVectors(uniform float<3> a, uniform float<3> b)
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

<source>:42:53: Error: Vector-typed parameter "a" is illegal in an
        exported function.

export uniform float<3> AddVectors(uniform float<3> a, uniform float<3> b)
                                                    ^

<source>:42:73: Error: Vector-typed parameter "b" is illegal in an
        exported function.

export uniform float<3> AddVectors(uniform float<3> a, uniform float<3> b)

From what I can tell, my alternatives are to do some conversion manually, eg use uniform float[3], or uniform float*, or pass x/y/z parameters separately.

Am I missing another option?

Dmitry Babokin

unread,
May 31, 2019, 2:23:39 AM5/31/19
to ispc-...@googlegroups.com
Short vectors can't be passed by value in extern functions. You can pass them by pointer.

Also note, that short vectors definition as a struct in interface header has alignment attribute, so it's aligned at least to 16 bytes.

--
You received this message because you are subscribed to the Google Groups "Intel SPMD Program Compiler Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ispc-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ispc-users/4a9c9a93-7ac9-4a2f-b97f-fbe2c6f75cd1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages