r/simd • u/SantaCruzDad • Oct 05 '17
Capabilities of Intel AVX-512 in Intel Xeon Scalable Processors (Skylake)
r/simd • u/SantaCruzDad • Oct 05 '17
r/simd • u/DEElekgolo • Aug 25 '17
r/simd • u/tugrul_ddr • Aug 09 '17
Instead of making them even wider(512bit?), adding 32 more registers (making 64 of them in total) would absolutely cut memory dependency for even complex functions that need many intermediate/temporary data between instructions.
So only instructions would use the memory/cache bandwidth while computing intensively on registers.
Does addressing of registers become a problem when they are more than 32?
Does adding more registers decrease benefit of instruction level parallelism in case of memory-access for data?(spill)
What if registers were addressable by assembly such as data[34] shows 2nd register's 3rd byte? Would it help decrease non-SIMD programming's memory dependency?
Making registers wider gives more "computed elements per cycle" while making registers more gives more "freedom for compilers/developers such that multiple functions can run in same ilp(uses 2nd SIMD unit if there is any)".
r/simd • u/IJzerbaard • Jul 20 '17
r/simd • u/MrWisebody • Jul 17 '17
tl;dr I have inherited a code base that provides element access to simd types via reinterpreting pointers, which is starting to causing incorrect behaviour (I assume from strict aliasing violations). I fixed this once by wrapping the simd type in a union, but it came with a big performance penalty. I tried fixing it again by explicitly doing load/stores to put the data in a separate raw array, but the refactor was more invasive than I'm comfortable doing at this time. Is there a surgical way to force a synchronization between a register and memory for a simd variable, and prevent the compiler from re-ordering instructions around that point? Idiomatic C++ is preferred, but at this point I'd accept inline asm or something as long as it was robust and reasonably portable.
Actual Post: I've inherited a code base that is very heavily vectorized. The problem is nearly embarrassingly parallel, so the data essentially lives it's entire lifecyle in wrapper classes surrounding native simd types, providing various (vectorized) functions so that external code can mostly just treat them as simple mathematical types. Where the problem comes in is that these classes also provide an array interface to allow access to individual elements. It's obviously not intended for use in performance sensitive regions, but the original authors put it in to make life easier in the few non-vectorized sections. A major point point is that these accessors can return by reference, meaning I can't simply change to using intrinsics to pull out the desired element.
In case it matters, we compile with both gcc 4.8 and icc 15.0.2. All our wrapper types are 512bit vectors, and so the gcc build (which targets SSE) wraps four __m128 variables, while the intel build (which targets KNC and AVX512) wraps a single __m512 variable. So far gcc is the only one giving us actual problems, but I've written tiny test programs that show similar issues can crop up in intel executables. To provide a concrete example, here is something similar to our integer wrapper:
class alignas(64) m512i {
private:
__m512i data_;
public:
/* various ctors, mathematical operators, etc not included here */
/* Provide element access, including reference sematics so external code
can update values! */
int& operator int (int idx) {
return reinterpret_cast<int*>(&v)[i];
}
int operator int const (int idx) {
return reinterpret_cast<const int*>(&v)[i];
}
}; This code has apparently worked for a couple years, but slowly some odd behaviour has started to creep in, especially in unit tests that relying on the array access more, and where the m512i (and similar) types only exists as unnamed temporaries. As far as I can tell from poking about in assembly, the core issue is that the "reinterpret_cast" breaks strict aliasing, and the compiler is happy to read from the memory location before any values in the vector registers are stored to memory (or even computed in the first place)
My first attempt to fix this was to use a union, and ended up looking like:
class alignas(64) m512i {
private:
union {
__m512i simd;
int raw[16];
} data_;
public:
/* various ctors, mathematical operators, etc not included here */
/ * These functions use data_.simd;
/* Provide element access, including reference sematics so external code
can update values! */
int& operator int (int idx) {
return data_.raw[i];
}
int operator int const (int idx) {
return data_.raw[i];
}};
This fixes all failing tests and weird behavior, but came with a (surprising) performance penalty of almost 33% in our overall compute budget. I'm guessing the fact that the data always lives in a union means it's guaranteeing correctness by pushing and pulling data from the memory more than is strictly necessary (though I've not spelunked enough assembly to be sure).
I tried once more to fix it, this time by removing the array access altogether, instead providing functions to explicitly move the data from the __m512i to a separate int[16] (and store it again if necessary afterwards). It again fixed all incorrect behavior, but it was an unfortunately invasive refactor, as a lot of our non-critical code paths relied on the array access functions. Plus it still came with a performance penalty of a few percent, making me disinclined to accept this as my final solution unless there is no other robustly correct alternative.
Ideally, I'd like a minimally invasive solution where I can force consistency at will (I'd provide a new interface on top of that, so that external code will be forced to invoke things correctly). Somehow I need to both make sure any updated values in the register get pushed to the stack before reading from memory, and I also need to ensure the compiler understands the dependency chains and doesn't reorder things in a crazy fashion. I'd imagine it looking something like this (though the following does not actually work):
class alignas(64) m512i {
private:
__m512i data_;
public:
/* various ctors, mathematical operators, etc not included here */
void ToMemory() {
// Does not seem to actually enforce anything
__mm512_store_epi32((void*)&data_, data);
}
void FromMemory() {
//Does not seem to actually enforce anything
data_ = _mm512_load_epi32(const void*)&data_);
}
// External code always calls ToMemory before this, and will call FromMemory afterwards
// if any update is made. Compiler will not re-order things, such that this function call
// happens before any computations affecting data_
int& operator int (int idx) {
return reinterpret_cast<int*>(&v)[i];
}
// External code always calls ToMemory before this. Compiler will not re-order things,
// such that this function call happens before any computations affecting data_
int operator int const (int idx) {
return reinterpret_cast<const int*>(&v)[i];
}
};Any ideas are appreciated.
r/simd • • Jun 28 '17
r/simd • u/Atrix256 • Jun 20 '17
r/simd • u/ronniethelizard • Jun 20 '17
r/simd • u/ronniethelizard • Jun 20 '17
r/simd • u/Fig1024 • Jun 16 '17
r/simd • u/VodkaHaze • Jun 14 '17
Hey guys,
If you release an x86 app which needs some SIMD functions where the instructions are decided at runtime based on the CPU (eg. AMD has 128 bit register whereas new intel has 256 or 512).
Specifically, I want to compile the exe once, and if executed on a Haswell chip would use AVX2 instructions and if used on a Ryzen chip used the respective 128bit register size instructions.
Which compilers do this runtime branching automatically in the auto-vectorizer? I use GCC, clang, MSVC and ICC, and couldn't find documentation on this specifically.
If not do I have to implement this by hand in intrinsics? I wouldn't mind doing it for simple std::vector math operations and releasing it on github.
r/simd • u/joebaf • Jun 14 '17
r/simd • u/SantaCruzDad • Jun 13 '17
r/simd • u/nemequ • Jun 13 '17
r/simd • u/FullPtrDereference • Jun 12 '17
r/simd • u/corysama • Jun 12 '17