- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi, I'm developing an application using Qt framework and I have some difficulties using STL in offload region. As an example:
#pragma offload_attribute(push, target(mic)) #include <algorithm> #pragma offload_attribute(pop) void main() { float a = 0.1f; float b = 0.5f; float c = std::max(a,b); #pragma offload target(mic) { float x = 0.1f; float y = 0.5f; float z = std::max(x,y); } }
This compiled without error. But if I include <QObject> before #pragma offload_attribute I get following error:
undefined reference to 'float const& std::max<float>(float const&, float const&)'
So I guess, that <algorithm> is included in <QObject> library and therefor not linked with mic code. But when I change the order and include <QObject> after <algorithm> I'm experiencing another errors:
function has not been declared with compatible "target" attribute function has not been declared with compatible "target" attribute function has not been declared with compatible "target" attribute function has not been declared with compatible "target" attribute *MIC* function has not been declared with compatible "target" attribute *MIC* function has not been declared with compatible "target" attribute *MIC* function has not been declared with compatible "target" attribute *MIC* function has not been declared with compatible "target" attribute undefined reference to 'std::operator|=(std::_los_Fmtflags&, std::_los_Fmtflags)' undefined reference to 'std::operator~(std::_los_Fmtflags)' undefined reference to 'std::operator&=(std::_los_Fmtflags&, std::_los_Fmtflags)' undefined reference to 'std::operator&(std::_los_Fmtflags, std::_los_Fmtflags)' undefined reference to 'std::operator|=(std::_los_Fmtflags&, std::_los_Fmtflags)' undefined reference to 'std::operator~(std::_los_Fmtflags)' undefined reference to 'std::opreator&=(std::_los_Fmtflags&, std::_los_Fmtflags)' undefined reference to 'QByteArray::swap(QByteArray&)' undefined reference to 'QString::swap(QString&)'
There is no problem using for example <complex> library in offload since it is not included in Qt libraries. I don't need to use Qt classes within offload region, but I'd like to use some STL functions. Any suggestions?
Thanks MK.
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I reproduced part of this scenario by simulating <QObject> with a “QObject.h” containing only the statement:
#include <algorithm>
Then adding the #include for this ahead of the offload_attribute which produces the error:
$ icpc -V Intel(R) C++ Intel(R) 64 Compiler XE for applications running on Intel(R) 64, Version 15.0.1.133 Build 20141023 Copyright (C) 1985-2014 Intel Corporation. All rights reserved. $ icpc u539493.cpp /tmp/icpcvbwuBX.o: In function `__offload_entry_u539493_cpp_10mainicpc2009569027UP9OAG': u539493.cpp:(.text+0x52): undefined reference to `float const& std::max<float>(float const&, float const&)'
I have not been able to reproduce the second set of warnings/errors.
In the placing <QObject> ahead of the offload_attribute, could you conditional its inclusion based on the __MIC__ predefine as follows:
#ifndef __MIC__ #include <QObject> #endif
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The errors look as if there may be a problem in the link command, as icpc ought to link against libstdc++ automatically, while icc or ld would require an explicit reference to the library.
Otherwise, I wonder if this might be connected with the differences in treatment of std::max between icpc and g++. While icpc likes to generate inline code (with the default options, such as Kevin quoted), g++ does not, and prefers fmaxf() with option -ffast-math (implying -ffinite-math-only).
The fmaxf() choice avoids the question of requiring C++ as opposed to C, but icpc doesn't offer an option like -ffinite-math-only to ignore the special requirements of fmaxf() so as to optimize it (which may not be important in the quoted context).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thank you both for reply. I already tried placing <QObject> inclusion in #ifndef statement, but then I get error:
*MIC* identifier "QObject" is undefined
whenever I use QObject class. I thought MIC version of code is created only for parts within #offload statement, so I don´t really understand the previous error.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Yes, target-compilation only creates an outlined function containing the offload code as part of the offload image; however, the compiler sees the complete source file during both the host and target compilations so that’s likely behind that latest error.
I’m not sure what might be a good solution for your case. A couple of ideas might be to:
- move the offload code into a separate function and separate source file
- #ifndef the host-code uses of QObject
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Indeed moving the offload code into separate source file did the trick. I created separate class with offload computations and put whole class within #pragma offload_attribute statements. Now it is possible to call the class in #pragma offfload inside class derived from QObject.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Great! Glad to hear that.

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page