Software Archive
Read-only legacy content
17061 Discussions

Aligned Allocators with C++11 on the MIC?

Stephen_M_5
Beginner
295 Views

Short version: is this possible?

Long version: I have tried to use aligned allocators either directly or indirectly for a couple of different projects using the Xeon Phi, and have yet to be successful in compiling it x0 My understanding is that the allocator rules / parameters / syntax changed (again) similar to this issue:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=51626

I distinctly remember finding a different bug talking about 4.7.0 vs 4.7.3 or something, but cannot seem to dig it up again.  Anyway, my understanding of custom allocators is limited to say it nicely.  I understand that I can alternatively use C-style arrays with _mm_malloc, but this is not what I desire.  I desire the ability to use aligned allocators.

For example, trying to use something like this:

https://gist.github.com/gavrus/5986353

where the only difference is I added

#include <cstddef>    // ptrdiff_t
#include <stdexcept>  // std::length_error
#include <xmmintrin.h>// _mm_malloc

to allow it to compile in unix environments.  The allocator works fine if I use things without the Phi's, but as soon as that ends up in an offload region it will fail.  The example of that is rather verbose, so I elect to include a somewhat more standard example here instead using Eigen (which internally uses aligned allocators for their data types):

#include <iostream>
#pragma offload_attribute(push, target(mic))
    #include <Eigen/Core>
#pragma offload_attribute(pop)

int main(int argc, char **argv) {
    Eigen::Vector3f original(1,2,3);

    float *d = original.data();// just gives raw pointer

    std::cout << "Vec Before: " << std::endl << original << std::endl;

    #pragma offload target(mic:0) inout(d : length(3))
    {
        Eigen::Vector3f test(5,6,7);
        d[0] = test.x();
        d[1] = test.y();
        d[2] = test.z();
    }

    std::cout << "Vec After: " << std::endl << original << std::endl;
    return 0;
}

to compile it for just the node, I can comment out the #pragma lines (and scope braces...) using:

icpc -std=c++11 -I eigen/ -o test eigen_test.cpp

(I just cloned eigen locally, but it is also installed via yum and pkg-config with that works too) and it will print

Vec Before: 
1
2
3
Vec After: 
5
6
7

as expected.  Putting the #pragma and scope braces back in, the compiler freaks out (mostly because Eigen uses a bunch of fancy templates), but the root cause here is:

undefined reference to `__gnu_cxx::new_allocator<char>::new_allocator()'

I have tried many different things, from static linking to any compiler flags I can find that sound reasonable...

For reference:

~> g++ -print-file-name=libstdc++.a
/opt/rh/devtoolset-3/root/usr/lib/gcc/x86_64-redhat-linux/4.9.2/libstdc++.a
~> g++ --version
g++ (GCC) 4.9.2 20150212 (Red Hat 4.9.2-6)

and (as I believe is to be expected):

~> icpc -print-file-name=libstdc++.a
/opt/rh/devtoolset-3/root/usr/lib/gcc/x86_64-redhat-linux/4.9.2/libstdc++.a
~>> icpc --version
icpc (ICC) 15.0.3 20150407

The only other thing that seems relevant here is the following from the icpc man page:

-stdlib[=keyword] (M*X only)

        (M*X only)
 
        Lets you select the C++ library to be used for linking.
   
        Architecture Restrictions:  Not available on Intel(R)  64
        architecture targeting Intel(R) MIC Architecture

e.g. forbidding -stdlib=libstdc++.

I apologize for this dump of information!  I've been searching on and off for a while now and would love to know if this can even be done, and if so how to do it ;)  I understand that the Phi's are still actively being developed, but I couldn't find anywhere explicitly forbidding what I want to do.

Thanks for any help!

0 Kudos
0 Replies
Reply