Comments (4)
(Finally getting back to this question after a major deadline on my end, and before my next major deadline in a week.)
I agree with your mental model of what should happen in this case. I'm working through a fix, but it might take a while to implement and test.
from tapir-llvm.
Thanks for pointing out this issue.
I was in the midst of crafting a long response about why Cilk evaluates all function arguments before the spawn and why your example contains a subtlety — compiler optimizations at -O1
— that makes the behavior appear inconsistent. But thinking about it further, I think your example gets at something deeper concerning object construction and destruction with Cilk and Tapir.
Right now is a particularly busy time for me, but I'll try to get back to you soon.
from tapir-llvm.
Thanks for the quick response, I appreciate any time you can devote to this. Some more thoughts:
The key question is whether child
is guaranteed to have a private copy of obj
after the detach. I'd argue that it should, to preserve the semantics of pass-by-value during a spawn.
Here's my mental model of what should happen:
- Parent calls the outlined function
det.achd
det.achd
gets ready to callchild
, then does a detach.- After this point, other workers are free to steal
parent
's stack frame and continue. This is safe because any arguments passed tochild
live ondet.achd
's stack, having been initialized in step 2.
From the IR, it looks like all the detached children will share a single copy of obj
created on the stack of parent
. But I must be missing something, because on x86 I never observe a race condition bug here.
I've verified that the behavior for this example is the same at -O3
.
from tapir-llvm.
Here's an interesting wrinkle: If I give object
a user-defined destructor, then suddenly Tapir puts the alloca
, constructor call, and destructor call in the outlined function like I expect.
struct object {
long _value;
noinline object(long value) : _value(value) {
*marker = 0xC;
}
noinline object(const object& other) {
*marker = 0xCC;
}
noinline ~object() {
*marker = 0xD;
}
};
// ...
// The rest is unchanged
; Function Attrs: noinline nounwind uwtable
define internal fastcc void @_Z6parentl_invoke.cont.cilk(i64 %x.cilk, i64 %i.015.cilk, %struct.object* align 8 %obj.cilk) unnamed_addr #2 personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*) {
for.body.cilk:
%__cilkrts_sf = alloca %struct.__cilkrts_stack_frame, align 8
call fastcc void @__cilkrts_enter_frame_fast_1(%struct.__cilkrts_stack_frame* nonnull %__cilkrts_sf)
call fastcc void @__cilkrts_detach(%struct.__cilkrts_stack_frame* nonnull %__cilkrts_sf)
%agg.tmp.cilk = alloca %struct.object, align 8
%0 = bitcast %struct.object* %agg.tmp.cilk to i8*
call void @llvm.lifetime.start.p0i8(i64 8, i8* nonnull %0)
%call.cilk = call i64 @add(long, long)(i64 %x.cilk, i64 %i.015.cilk)
%add.cilk = add nsw i64 %i.015.cilk, %x.cilk
call void @object::object(object const&)(%struct.object* nonnull %agg.tmp.cilk, %struct.object* nonnull dereferenceable(8) %obj.cilk)
call void @child(long, long, object)(i64 %add.cilk, i64 %call.cilk, %struct.object* nonnull %agg.tmp.cilk)
call void @object::~object()(%struct.object* nonnull %agg.tmp.cilk) #7
call fastcc void @__cilk_parent_epilogue(%struct.__cilkrts_stack_frame* nonnull %__cilkrts_sf)
ret void
}
from tapir-llvm.
Related Issues (20)
- TapirXLA Compiler
- Name all outlined functions so they can be programmatically mapped back to original, demanglable function names HOT 3
- [InstCombine] May make task closures large by sinking instructions from parent to child tasks HOT 2
- Versions 6 and 7 progress thread HOT 5
- tapir compiler does not terminate HOT 5
- cilksan bug HOT 2
- tapir bug when having double cilk_for loops HOT 2
- tapir crash when compiling without -fcilkplus HOT 2
- caused compiler crash when adding cilk_spawn and cilk_sync HOT 2
- Running the benchmark suite HOT 2
- Different behavior between Cilk code on 1 worker and serial elision on `xla_8` branch? HOT 3
- Inconsistent grain size pragma syntax HOT 5
- [AliasAnalysis] getModRefInfo(DetachInst *, MemoryLocation &) unnecessarily superlinear time, unnecessarily recursive. HOT 3
- Can't demangle outlined function names HOT 4
- Issues with break/return within cilk_for HOT 2
- Automatically build packages hosted on github for latest Tapir/LLVM
- Halide front end HOT 1
- Tapir interaction with Global Value Numbering (GVN) HOT 3
- Compiler segfault when spawning expression
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from tapir-llvm.