Skip to content
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

Merged
merged 4 commits into from
May 24, 2017
Merged

Conversation

vchuravy
Copy link
Member

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] and jl_special_vector_alignment will have to start taking the DataLayout into account.

[1] https://github.com/llvm-mirror/llvm/blob/836dd8e1f01318ac7f1149d399ce36b064404cb4/lib/IR/DataLayout.cpp#L507-L514

@vchuravy vchuravy added backport pending 0.6 bugfix This change fixes an existing bug needs tests Unit tests are required for this change labels May 20, 2017
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);
Copy link
Member Author

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);

@vchuravy
Copy link
Member Author

@yuyichao should I split the last three commits out into a separate PR? This became more invasive then I thought.

@vchuravy vchuravy removed the needs tests Unit tests are required for this change label May 21, 2017
@vchuravy
Copy link
Member Author

vchuravy commented May 21, 2017

@jlbuild

@jlbuild
Copy link

jlbuild commented May 21, 2017

Status of f993102 builds:

Builder Name Build Download
linux32 ERRORED N/A
linux64 ERRORED N/A
linuxaarch64 ERRORED N/A
linuxarmv7l ERRORED N/A
linuxppc64le ERRORED N/A
osx64 ERRORED N/A
win32 CANCELED N/A
win64 ERRORED N/A

@vchuravy
Copy link
Member Author

@nanosoldier runbenchmarks(ALL, vs = ":master")

@vchuravy vchuravy requested a review from yuyichao May 21, 2017 11:18
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)
Copy link
Contributor

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);
Copy link
Contributor

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)

@@ -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;
Copy link
Contributor

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.

Copy link
Member Author

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)
Copy link
Contributor

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.

@yuyichao
Copy link
Contributor

I was reviewing under the assumption that JL_HEAP_ALIGNMENT is meant to be the max alignment that the GC can provide.

@vchuravy
Copy link
Member Author

@jlbuild !nuke

@jlbuild
Copy link

jlbuild commented May 21, 2017

Status of 151bd81 builds:

Builder Name Nuke Build Download
linux32 COMPLETE COMPLETE Download
linux64 COMPLETE COMPLETE Download
linuxaarch64 COMPLETE COMPLETE Download
linuxarmv7l COMPLETE COMPLETE Download
linuxppc64le COMPLETE COMPLETE Download
osx64 COMPLETE COMPLETE Download
win32 COMPLETE ERRORED N/A
win64 COMPLETE ERRORED N/A

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.
Copy link
Contributor

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,
Copy link
Contributor

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
Copy link
Contributor

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...

@nanosoldier
Copy link
Collaborator

Your benchmark job has completed - possible performance regressions were detected. A full report can be found here. cc @jrevels

@vchuravy vchuravy changed the title [RFC] limit maximum vector alignment to heap alignment limit maximum vector alignment to heap alignment May 21, 2017
@jlbuild
Copy link

jlbuild commented May 22, 2017

Status of 3c39b0a builds:

Builder Name Nuke Build Download Code Output
linux32 COMPLETE COMPLETE Download ERRORED
linux64 COMPLETE COMPLETE Download COMPLETE
linuxaarch64 COMPLETE COMPLETE Download COMPLETE
linuxarmv7l COMPLETE COMPLETE Download COMPLETE
linuxppc64le COMPLETE COMPLETE Download COMPLETE
osx64 COMPLETE COMPLETE Download PENDING

@vchuravy vchuravy requested a review from yuyichao May 22, 2017 13:47
@vchuravy
Copy link
Member Author

@eschnett have you seen the SIMD.jl failure on 32bit linux before? https://buildog.julialang.org/#/builders/45/builds/1

Test Failed
  Expression: s === sum(xs)
   Evaluated: -3.927754334663871e235 === 91.0
ERROR: LoadError: There was an error during testing
while loading /home/buildworker/.julia/v0.7/SIMD/test/runtests.jl, in expression starting on line 372

return quote
Base.@_inline_meta
Base.llvmcall($exp,
NTuple{N, VecElement{T}},
Copy link
Contributor

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?

b = f20961([a], [a])
@test b == result
if N == 36
code_llvm(STDOUT, f20961, (Vector{Vec{N, T}}, Vector{Vec{N, T}}))
Copy link
Contributor

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.
@vchuravy
Copy link
Member Author

If there are no further comments I plan to merge this in about 24h

@vchuravy vchuravy merged commit 298fffb into master May 24, 2017
@vchuravy vchuravy deleted the vc/vec_alignment branch May 24, 2017 23:46
tkelman pushed a commit that referenced this pull request Jun 3, 2017
(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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugfix This change fixes an existing bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants