-
Notifications
You must be signed in to change notification settings - Fork 113
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
Bizarre malloc error in CalculateCurvature
#450
Comments
I've never seen an error like that; how can it know an allocation is too big at compile time? @pca006132 any thoughts, since you did the |
For a bit more context now that I;m poking it again, it is this line as mentioned by the error message. Specifically, it doesn't like that if (meshRelation_.triProperties.size() == 0) {
// int n = NumTri(); // error
int n = 1000000000; // compiles
meshRelation_.triProperties.resize(n);
}
|
Bizarrely, this compiles. Looking at if (meshRelation_.triProperties.size() == 0) {
int n = NumTri();
meshRelation_.triProperties.reserve(n);
meshRelation_.triProperties.resize(n);
} |
That's bizarre - what compiler is this? I feel like I have lines all over the code base that do that; it seems strange it would only complain about that one. |
CalculateCurvature
CalculateCurvature
This was built with the default system compiler (gcc).
It definitely is weird, |
Given that adding a line that should be redundant avoids the error, I got suspicious that it is an optimization issue, and I think that I'm right. set(MANIFOLD_FLAGS -O0) Turning off optimizations in Manifold by setting |
Modifying void shrink_to_fit() {
T *newBuffer = nullptr;
if (size_ > 0) {
// mallocManaged(&newBuffer, size_ * sizeof(T));
int sz = size_ * sizeof(T);
mallocManaged(&newBuffer, sz);
prefetch(newBuffer, size_ * sizeof(T), onHost);
uninitialized_copy(autoPolicy(size_), ptr_, ptr_ + size_, newBuffer);
}
freeManaged(ptr_);
ptr_ = newBuffer;
capacity_ = size_;
} avoids the error for me (without the pre-emptive |
This issue I found in my travels may be related. Maybe breaking out the size calculation to another line defeats the inlining somehow? |
That looks like a perfectly reasonable change, even if it is a GCC bug workaround. The wisdom I always heard was if you think it's a compiler bug, it's really your own bug, but here I'm tempted to disagree. |
Ok, I'll make a PR with this fix then. |
I agree this is very weird... Perhaps gcc somehow thinks that NumTri can return something negative? |
I did experiment with that, but casting to unsigned didn't change anything in this case (though I saw examples online where that fixed peoples malloc problems). |
Just from curiosity, what is the point of reserve(n) followed by resize(n)? |
@pentacular There isn't, but while investigating the bug, I added the This is basically repeating what I described in my comments above though. |
Fixes #450 This breaks the allocation size calculation in ManagedVec::shrink_to_fit onto a separate line in order to work around spooky inlining (I think) by GCC that trips up an excessive allocation compilation error in malloc.
Fixes elalish#450 This breaks the allocation size calculation in ManagedVec::shrink_to_fit onto a separate line in order to work around spooky inlining (I think) by GCC that trips up an excessive allocation compilation error in malloc.
Fixes elalish#450 This breaks the allocation size calculation in ManagedVec::shrink_to_fit onto a separate line in order to work around spooky inlining (I think) by GCC that trips up an excessive allocation compilation error in malloc.
I've finally gotten to pulling down the latest master and started updating the C bindings and have hit a bit of a snag. Everything compiles and tests fine for me with CUDA enabled, leading to
mallocManaged
usingcudaMallocManaged
instead ofmalloc
. So malloc is being tripped up by size parameters that are doing fine in the CUDA branch. Any idea what could be going wrong? Won't have more time to try and figure it out for a bit, so dumping here to see if it makes sense to you guys.Build Error:
Machine:
The text was updated successfully, but these errors were encountered: