-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
limit maximum vector alignment to heap alignment #21980
Conversation
src/cgutils.cpp
Outdated
@@ -524,7 +524,8 @@ static Type *julia_struct_to_llvm(jl_value_t *jt, jl_unionall_t *ua, bool *isbox | |||
#endif | |||
unsigned llvm_alignment = DL.getABITypeAlignment((Type*)jst->struct_decl); | |||
unsigned julia_alignment = jst->layout->alignment; | |||
assert(llvm_alignment == julia_alignment); | |||
assert(julia_alignment <= JL_SMALL_BYTE_ALIGNMENT && | |||
julia_alignment == llvm_alignment); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This assert is wrong needs to be:
assert(julia_alignment <= JL_SMALL_BYTE_ALIGNMENT);
assert(llvm_alignment <= JL_SMALL_BYTE_ALIGNMENT &
julia_alignment == llvm_alignment);
68609f3
to
87ccf70
Compare
@yuyichao should I split the last three commits out into a separate PR? This became more invasive then I thought. |
@nanosoldier |
src/cgutils.cpp
Outdated
unsigned julia_alignment = jl_datatype_align(jst); | ||
// Check that the alignment adheres to the heap alignment. | ||
assert(julia_alignment <= JL_HEAP_ALIGNMENT); | ||
if (llvm_alignment <= JL_HEAP_ALIGNMENT) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should only be a temporary workaround.
src/gc.c
Outdated
@@ -2832,15 +2833,15 @@ void *jl_gc_perm_alloc_nolock(size_t sz, int zero) | |||
if (__unlikely(sz > GC_PERM_POOL_LIMIT)) | |||
#endif | |||
return zero ? calloc(1, sz) : malloc(sz); | |||
sz = LLT_ALIGN(sz, JL_SMALL_BYTE_ALIGNMENT); | |||
sz = LLT_ALIGN(sz, JL_HEAP_ALIGNMENT); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This shouldn't be changed. (i.e. this should stay at 16 when you change the heap_alignment to 64)
src/intrinsics.cpp
Outdated
@@ -331,8 +331,7 @@ static Value *emit_unbox(Type *to, const jl_cgval_t &x, jl_value_t *jt, Value *d | |||
|
|||
int alignment; | |||
if (x.isboxed) { | |||
// julia's gc gives 16-byte aligned addresses | |||
alignment = 16; | |||
alignment = JL_HEAP_ALIGNMENT; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This shouldn't be changed since this won't increase. It might even be too much and should be sizeof(void*) * 2
now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so it should be MAX_ALIGN
?
src/cgutils.cpp
Outdated
} | ||
if (alignment > JL_HEAP_ALIGNMENT) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be an assertion in the condition above. When used in pointerref
/pointerset
the user should be allowed to specify larger alignment.
I was reviewing under the assumption that |
@jlbuild !nuke |
Status of 151bd81 builds:
|
src/cgutils.cpp
Outdated
assert(llvm_alignment == julia_alignment); | ||
unsigned julia_alignment = jl_datatype_align(jst); | ||
// Check that the alignment adheres to the heap alignment. | ||
// TODO: Fix alignment calculation in LLVM. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also fix the calculation on our side both in GC and in the struct declaration....
src/gc.c
Outdated
@@ -2836,11 +2837,11 @@ void *jl_gc_perm_alloc_nolock(size_t sz, int zero) | |||
if (__unlikely(sz > gc_perm_size)) { | |||
#ifdef _OS_WINDOWS_ | |||
void *pool = VirtualAlloc(NULL, | |||
GC_PERM_POOL_SIZE + JL_SMALL_BYTE_ALIGNMENT, | |||
GC_PERM_POOL_SIZE + JL_HEAP_ALIGNMENT, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
..... The comment above applys to these too....... The permgen allocation shouldn't be changed.
@@ -331,7 +331,6 @@ static Value *emit_unbox(Type *to, const jl_cgval_t &x, jl_value_t *jt, Value *d | |||
|
|||
int alignment; | |||
if (x.isboxed) { | |||
// julia's gc gives 16-byte aligned addresses |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Keep this comment for now I guess...
Your benchmark job has completed - possible performance regressions were detected. A full report can be found here. cc @jrevels |
151bd81
to
3c39b0a
Compare
Status of 3c39b0a builds:
|
@eschnett have you seen the SIMD.jl failure on 32bit linux before? https://buildog.julialang.org/#/builders/45/builds/1
|
test/vecelement.jl
Outdated
return quote | ||
Base.@_inline_meta | ||
Base.llvmcall($exp, | ||
NTuple{N, VecElement{T}}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unusual indent in this block?
test/vecelement.jl
Outdated
b = f20961([a], [a]) | ||
@test b == result | ||
if N == 36 | ||
code_llvm(STDOUT, f20961, (Vector{Vec{N, T}}, Vector{Vec{N, T}})) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this temporary? less noisy to output this to a buffer and test for something instead?
Make julia_alignment actually return the jl_datatype_align if `alignment == 0` and check that the requested alignment is coherent with the heap alignment.
3c39b0a
to
b9671b0
Compare
If there are no further comments I plan to merge this in about 24h |
(cherry picked from commit c2c0997) ref #21980 introduce jl_datatype_align (cherry picked from commit 5115a38) Introduce JL_HEAP_ALIGNMENT (cherry picked from commit ed286e4) fix julia_alignment Make julia_alignment actually return the jl_datatype_align if `alignment == 0` and check that the requested alignment is coherent with the heap alignment. (cherry picked from commit b9671b0)
This imposes an upper limit on the vector alignment of 16. This is the current guaranteed alignment of the heap and after #21959 we can raise the limit to 64. In 0.5 we were a lot more conservative with the alignment given to memory loads.
I consider this a band-aid fix for #20961 and #21918. I don't know how the full fix for #20961 would look like, but I think it will involve fixing the
DataLayout
fallback in LLVM [1] andjl_special_vector_alignment
will have to start taking theDataLayout
into account.[1] https://github.com/llvm-mirror/llvm/blob/836dd8e1f01318ac7f1149d399ce36b064404cb4/lib/IR/DataLayout.cpp#L507-L514