Registered Member
|
Hi,
I currently have a program that uses Eigen. It runs without error, and I have no alignment assertions from Eigen. However, when I do profiling using AMD CodeAnalyst, it has a misalign access rate of over 80%. I can trace it to
in \eigen\src\core\assign.h . It occurs at line 316, which is
Now, this may be my fault, so I'll give a short breakdown of my program.
Edit: If I use std::vectors in my struct instead of Eigen objects and I check alignment of the structs in the vector, they are all aligned. But using Eigen objects, every other struct in the vector is aligned, while the others are not. This also occurs if I look at the members in my_struct. With Eigen objects, every other member is aligned in my_struct, but changing them to std::vector, all are aligned. To check alignment, I just do
Any help is appreciated. I am using MSVC++ 2010. I've also tried changing the 'struct member alignment' but I'm still having a high misalign access rate. Thank You. |
Moderator
|
on WIN64 we directly call malloc which already returns aligned buffers. However, it might likely be the case that CodeAnalyst replaces the standard malloc by its own and that this later does not return aligned buffers. You can check by editing the file Eigen/src/Core/util/Memory.h to remove the line 62:
|| defined(_WIN64) \ |
Registered Member
|
Actually, I believe that CodeAnalyst does not modify/replace anything. I just compile and run the program using VC++ under Win7 32 bit, and this profiler monitors it.
I still tried removing the line you mention, but it doesn't help. |
Registered Member
|
Ok, I've compiled the same code in Linux 64 bit using both the GCC and Intel C++ compilers, and my pointers are aligned in the sense of
But as said above, on Windows, when I compile my code in Visual Studio 2010 32 bit, I find that some pointers are not aligned. I've also tried Code::Blocks with the GCC compiler on Windows 32 bit and some pointers are still not aligned. In summary, on Linux 64 bit, I get aligned pointers, but on Windows 32 bit, I get some pointers not being aligned. |
Moderator
|
I don't get it, in your first email you said "It runs without error", so I concluded you see unaligned errors only when running it inside code analyst...
In order to get assertions from Eigen, you must not define NDEBUG at the compilation stage. On WIN32, we use _mm_malloc(size, 16); to allocated aligned buffers is SSE is enabled, and _aligned_malloc(size, 16); otherwise. I don't see why they would failed in your case. To be sure, you could edit the aligned_malloc function in Memory.h line 197 to enforce the use of handmade_aligned_malloc, this one is guaranteed to success. If not then the problem is somewhere else.... |
Registered Member
|
Ok, so overall, the code runs without error, whether I was using codeanalyst or not. I don't get any assertions from Eigen. I was just saying that when I used code analyst to monitor the program during runtime, code analyst reported a high misalign access rate afterwards(note that the program itself ran without error).
And also, when I check the pointers to the structs (and their members) to see if they are aligned, I only get that some are aligned. (This part is separate from code analyst, and I just insert the abovementioned code to check various pointers). For example, if in my main method given in the first post, I insert the code
it outputs "Not Aligned". Overall, there are no assertion errors. I was just wondering why there was a high misalign access rate from the Eigen method quoted in my first post. But if you think that it's something that I should not worry about, then I'll leave it as is. By the way, thank you very much for your help and your suggestions. |
Moderator
|
you are checking the alignment of the vector object itself, and for dynamic sized objects we don't care. What is important is that the data are aligned, e.g.: if (((uintptr_t)(single_struct->v2.data()) % 16u) == 0) |
Registered Member
|
Ok, I didn't realize that. Thank you for your help.
|
Registered users: Bing [Bot], Google [Bot], q.ignora, watchstar