MCPcopy Create free account
hub / github.com/Oneflow-Inc/oneflow / LaunchLazyJob

Method LaunchLazyJob

oneflow/core/framework/instructions_builder.cpp:125–196  ·  view source on GitHub ↗

clang-format off Job e.g.: [wait_and_send_ids] | V | +-------------------+ | | V [cpu_decoder] | | [critcial_section_wait] V | | V [forward_ops...] | | | V +-------------------+ | [copy_loss] | +-----------------------+ | | V V |

Source from the content-addressed store, hash-verified

123// critical_section_callback is a non-blocking opkernel which notifies instruction
124// CriticalSectionEnd done.
125Maybe<void> InstructionsBuilder::LaunchLazyJob(const vm::EagerBlobObjectListPtr& inputs,
126 const vm::EagerBlobObjectListPtr& outputs,
127 const vm::EagerBlobObjectListPtr& parameters,
128 const std::shared_ptr<NNGraphIf>& nn_graph) {
129 JUST(SoftSyncNNGraphBuffers(inputs, nn_graph));
130 JUST(SoftSyncNNGraphBuffers(outputs, nn_graph));
131 JUST(SoftSyncNNGraphBuffers(parameters, nn_graph));
132 {
133 // instruction chain: [CriticalSectionBegin] -> [CriticalSectionEnd]
134 // instructions LaunchLazyJob are launched independent from instruction chains
135 // [CriticalSectionBegin] -> [CriticalSectionEnd]
136 const auto& input_op_name2end_event_record =
137 std::make_shared<HashMap<std::string, std::shared_ptr<SharedEventRecord>>>();
138 {
139 for (const auto& op_name : nn_graph->inputs_op_names()) {
140 const auto& event_record = std::make_shared<SharedEventRecord>();
141 CHECK_OR_RETURN(input_op_name2end_event_record->emplace(op_name, event_record).second)
142 << Error::RuntimeError() << "Duplicate Op name " << op_name;
143 }
144
145 auto stream = JUST(GetCriticalSectionStream());
146 auto* vm_stream = JUST(Singleton<VirtualMachine>::Get()->GetVmStream(stream));
147 auto instruction = intrusive::make_shared<vm::Instruction>(
148 vm_stream, std::make_shared<vm::InputCriticalSectionBeginInstructionPolicy>(
149 nn_graph, inputs, input_op_name2end_event_record, vm_stream));
150 instruction_list_->EmplaceBack(std::move(instruction));
151 }
152 const auto& output_op_name2end_event_record =
153 std::make_shared<HashMap<std::string, std::shared_ptr<SharedEventRecord>>>();
154 {
155 for (const auto& op_name : nn_graph->outputs_op_names()) {
156 const auto& event_record = std::make_shared<SharedEventRecord>();
157 CHECK_OR_RETURN(output_op_name2end_event_record->emplace(op_name, event_record).second)
158 << Error::RuntimeError() << "Duplicate Op name " << op_name;
159 }
160 auto stream = JUST(GetCriticalSectionStream());
161 auto* vm_stream = JUST(Singleton<VirtualMachine>::Get()->GetVmStream(stream));
162 auto instruction = intrusive::make_shared<vm::Instruction>(
163 vm_stream, std::make_shared<vm::OutputCriticalSectionBeginInstructionPolicy>(
164 nn_graph, outputs, output_op_name2end_event_record, vm_stream));
165 instruction_list_->EmplaceBack(std::move(instruction));
166 }
167 {
168 auto stream = JUST(GetLazyJobLauncherStream());
169 auto* vm_stream = JUST(Singleton<VirtualMachine>::Get()->GetVmStream(stream));
170 auto instruction = intrusive::make_shared<vm::Instruction>(
171 vm_stream, std::make_shared<vm::LaunchLazyJobInstructionPolicy>(nn_graph, parameters));
172 instruction_list_->EmplaceBack(std::move(instruction));
173 }
174 auto stream = JUST(GetCriticalSectionStream());
175 auto* vm_stream = JUST(Singleton<VirtualMachine>::Get()->GetVmStream(stream));
176 for (int i = 0; i < nn_graph->inputs_op_names().size(); ++i) {
177 const auto& eager_blob_object = inputs->at(i);
178 const auto& op_name = nn_graph->inputs_op_names().at(i);
179 const auto& event_record = JUST(MapAt(*input_op_name2end_event_record, op_name));
180 auto instruction = intrusive::make_shared<vm::Instruction>(
181 vm_stream, std::make_shared<vm::InputCriticalSectionEndInstructionPolicy>(
182 eager_blob_object, event_record, vm_stream));

Callers 1

RunLazyNNGraphFunction · 0.80

Calls 7

SoftSyncNNGraphBuffersFunction · 0.85
GetFunction · 0.85
MapAtFunction · 0.85
GetVmStreamMethod · 0.80
EmplaceBackMethod · 0.45
sizeMethod · 0.45
atMethod · 0.45

Tested by

no test coverage detected