292 const auto ifm_index{node.
getInputs().
at(Conv2D::Input::INPUT)};
293 const auto ker_index{node.
getInputs().
at(Conv2D::Input::KERNEL)};
294 const auto bias_index{node.
getInputs().
at(Conv2D::Input::BIAS)};
296 auto ofm_tensor = _tensor_reg->getPortableTensor(ofm_index);
297 auto ifm_tensor = _tensor_reg->getPortableTensor(ifm_index);
298 auto ker_tensor = _tensor_reg->getPortableTensor(ker_index);
299 auto bias_tensor = _tensor_reg->getPortableTensor(bias_index);
306 const bool is_cacheable_weights =
ker_tensor->is_constant();
308 auto fn = std::make_unique<ops::ConvolutionLayer>();
310 if (_ctx.at(ifm_index).info().isDynamic() || _ctx.at(ker_index).info().isDynamic())
313 param_padding.param.right, param_padding.param.top, param_padding.param.bottom,
314 stride.horizontal, stride.vertical, dilation.width_factor, dilation.height_factor,
315 activation, ofm_tensor, is_cacheable_weights);
317 _return_fn = std::move(fn);
320 const auto ifm_shape = _ctx.at(ifm_index).shape().asFeature();
321 const auto ofm_shape = _ctx.at(ofm_index).shape().asFeature();
323 const auto &ker_shape = _ctx.at(ker_index).shape();
324 const auto ker_height = ker_shape.dim(1);
325 const auto ker_width = ker_shape.dim(2);
328 ir::calculatePadding(param_padding, ifm_shape, ofm_shape, stride, ker_width, ker_height,
329 dilation.width_factor, dilation.height_factor);
332 padding.right, padding.top, padding.bottom, stride.horizontal, stride.vertical,
333 dilation.width_factor, dilation.height_factor, activation, ofm_tensor,
334 is_cacheable_weights);
336 _return_fn = std::move(fn);
344 const auto ifm_index{node.
getInputs().
at(DepthwiseConv2D::Input::INPUT)};
345 const auto ker_index{node.
getInputs().
at(DepthwiseConv2D::Input::KERNEL)};
346 const auto bias_index{node.
getInputs().
at(DepthwiseConv2D::Input::BIAS)};
349 const auto ifm_shape = _ctx.at(ifm_index).shape().asFeature();
350 const auto ofm_shape = _ctx.at(ofm_index).shape().asFeature();
352 const auto &ker_shape = _ctx.at(ker_index).shape();
353 const auto ker_height = ker_shape.dim(1);
354 const auto ker_width = ker_shape.dim(2);
357 const auto padding = ir::calculatePadding(node.
param().
padding, ifm_shape, ofm_shape, stride,
358 ker_width, ker_height, dilation_width, dilation_height);
362 auto ofm_tensor = _tensor_reg->getPortableTensor(ofm_index);
363 auto ifm_tensor = _tensor_reg->getPortableTensor(ifm_index);
364 auto ker_tensor = _tensor_reg->getPortableTensor(ker_index);
365 auto bias_tensor = _tensor_reg->getPortableTensor(bias_index);
367 auto fn = std::make_unique<ops::DepthwiseConvolutionLayer>();
370 padding.bottom, stride.horizontal, stride.vertical, multiplier, dilation_width,
371 dilation_height, activation, ofm_tensor, _external_context);
373 _return_fn = std::move(fn);
1380 const auto scratch_buffer_index{
1381 node.
getOutputs().
at(ir::operation::LSTM::Output::SCRATCH_BUFFER)};
1382 const auto output_state_out_index{
1383 node.
getOutputs().
at(ir::operation::LSTM::Output::OUTPUT_STATE_OUT)};
1384 const auto cell_state_out_index{
1385 node.
getOutputs().
at(ir::operation::LSTM::Output::CELL_STATE_OUT)};
1386 const auto output_index{node.
getOutputs().
at(ir::operation::LSTM::Output::OUTPUT)};
1388 const auto input_index{node.
getInputs().
at(ir::operation::LSTM::Input::INPUT)};
1389 const auto input_to_input_weights_index{
1390 node.
getInputs().
at(ir::operation::LSTM::Input::INPUT_TO_INPUT_WEIGHTS)};
1391 const auto input_to_forget_weights_index{
1392 node.
getInputs().
at(ir::operation::LSTM::Input::INPUT_TO_FORGET_WEIGHTS)};
1393 const auto input_to_cell_weights_index{
1394 node.
getInputs().
at(ir::operation::LSTM::Input::INPUT_TO_CELL_WEIGHTS)};
1395 const auto input_to_output_weights_index{
1396 node.
getInputs().
at(ir::operation::LSTM::Input::INPUT_TO_OUTPUT_WEIGHTS)};
1397 const auto recurrent_to_input_weights_index{
1398 node.
getInputs().
at(ir::operation::LSTM::Input::RECURRENT_TO_INPUT_WEIGHTS)};
1399 const auto recurrent_to_forget_weights_index{
1400 node.
getInputs().
at(ir::operation::LSTM::Input::RECURRENT_TO_FORGET_WEIGHTS)};
1401 const auto recurrent_to_cell_weights_index{
1402 node.
getInputs().
at(ir::operation::LSTM::Input::RECURRENT_TO_CELL_WEIGHTS)};
1403 const auto recurrent_to_output_weights_index{
1404 node.
getInputs().
at(ir::operation::LSTM::Input::RECURRENT_TO_OUTPUT_WEIGHTS)};
1405 const auto cell_to_input_weights_index{
1406 node.
getInputs().
at(ir::operation::LSTM::Input::CELL_TO_INPUT_WEIGHTS)};
1407 const auto cell_to_forget_weights_index{
1408 node.
getInputs().
at(ir::operation::LSTM::Input::CELL_TO_FORGET_WEIGHTS)};
1409 const auto cell_to_output_weights_index{
1410 node.
getInputs().
at(ir::operation::LSTM::Input::CELL_TO_OUTPUT_WEIGHTS)};
1411 const auto input_gate_bias_index{
1412 node.
getInputs().
at(ir::operation::LSTM::Input::INPUT_GATE_BIAS)};
1413 const auto forget_gate_bias_index{
1414 node.
getInputs().
at(ir::operation::LSTM::Input::FORGET_GATE_BIAS)};
1415 const auto cell_gate_bias_index{node.
getInputs().
at(ir::operation::LSTM::Input::CELL_BIAS)};
1416 const auto output_gate_bias_index{
1417 node.
getInputs().
at(ir::operation::LSTM::Input::OUTPUT_GATE_BIAS)};
1418 const auto projection_weights_index{
1419 node.
getInputs().
at(ir::operation::LSTM::Input::PROJECTION_WEIGHTS)};
1420 const auto projection_bias_index{
1421 node.
getInputs().
at(ir::operation::LSTM::Input::PROJECTION_BIAS)};
1422 const auto output_state_in_index{
1423 node.
getInputs().
at(ir::operation::LSTM::Input::OUTPUT_STATE_IN)};
1424 const auto cell_state_in_index{node.
getInputs().
at(ir::operation::LSTM::Input::CELL_STATE_IN)};
1431 bool has_input_to_input_weights = _ctx.exist(input_to_input_weights_index) &&
1432 (_ctx.at(input_to_input_weights_index).shape().dim(0) != 0 &&
1433 _ctx.at(input_to_input_weights_index).shape().dim(1) != 0);
1434 bool has_recurrent_to_input_weights =
1435 _ctx.exist(recurrent_to_input_weights_index) &&
1436 (_ctx.at(recurrent_to_input_weights_index).shape().dim(0) != 0 &&
1437 _ctx.at(recurrent_to_input_weights_index).shape().dim(1) != 0);
1443 bool has_cell_to_forget_weights = _ctx.exist(cell_to_forget_weights_index) &&
1444 _ctx.at(cell_to_forget_weights_index).shape().dim(0) != 0;
1445 bool has_cell_to_output_weights = _ctx.exist(cell_to_output_weights_index) &&
1446 _ctx.at(cell_to_output_weights_index).shape().dim(0) != 0;
1448 bool has_input_gate_bias =
1449 _ctx.exist(input_gate_bias_index) && _ctx.at(input_gate_bias_index).shape().dim(0);
1451 bool has_projection_weights = _ctx.exist(projection_weights_index) &&
1452 (_ctx.at(projection_weights_index).shape().dim(0) != 0 &&
1453 _ctx.at(projection_weights_index).shape().dim(1) != 0);
1454 bool has_projection_bias =
1455 _ctx.exist(projection_bias_index) && _ctx.at(projection_bias_index).shape().dim(0);
1457 auto scratch_buffer_tensor = _ctx.exist(scratch_buffer_index)
1458 ? _tensor_reg->getPortableTensor(scratch_buffer_index)
1460 auto output_state_out_tensor = _ctx.exist(output_state_out_index)
1461 ? _tensor_reg->getPortableTensor(output_state_out_index)
1463 auto cell_state_out_tensor = _ctx.exist(cell_state_out_index)
1464 ? _tensor_reg->getPortableTensor(cell_state_out_index)
1466 auto output_tensor = _tensor_reg->getPortableTensor(output_index);
1468 auto input_tensor = _tensor_reg->getPortableTensor(input_index);
1470 auto input_to_input_weights_tensor =
1471 has_input_to_input_weights ? _tensor_reg->getPortableTensor(input_to_input_weights_index)
1473 auto input_to_forget_weights_tensor =
1474 _tensor_reg->getPortableTensor(input_to_forget_weights_index);
1475 auto input_to_cell_weights_tensor = _tensor_reg->getPortableTensor(input_to_cell_weights_index);
1476 auto input_to_output_weights_tensor =
1477 _tensor_reg->getPortableTensor(input_to_output_weights_index);
1478 auto recurrent_to_input_weights_tensor =
1479 has_recurrent_to_input_weights
1480 ? _tensor_reg->getPortableTensor(recurrent_to_input_weights_index)
1482 auto recurrent_to_forget_weights_tensor =
1483 _tensor_reg->getPortableTensor(recurrent_to_forget_weights_index);
1484 auto recurrent_to_cell_weights_tensor =
1485 _tensor_reg->getPortableTensor(recurrent_to_cell_weights_index);
1486 auto recurrent_to_output_weights_tensor =
1487 _tensor_reg->getPortableTensor(recurrent_to_output_weights_index);
1489 auto cell_to_input_weights_tensor = _tensor_reg->getPortableTensor(cell_to_input_weights_index);
1490 auto cell_to_forget_weights_tensor =
1491 has_cell_to_forget_weights ? _tensor_reg->getPortableTensor(cell_to_forget_weights_index)
1493 auto cell_to_output_weights_tensor =
1494 has_cell_to_output_weights ? _tensor_reg->getPortableTensor(cell_to_output_weights_index)
1497 auto input_gate_bias_tensor =
1498 has_input_gate_bias ? _tensor_reg->getPortableTensor(input_gate_bias_index) :
nullptr;
1499 auto forget_gate_bias_tensor = _tensor_reg->getPortableTensor(forget_gate_bias_index);
1500 auto cell_gate_bias_tensor = _tensor_reg->getPortableTensor(cell_gate_bias_index);
1501 auto output_gate_bias_tensor = _tensor_reg->getPortableTensor(output_gate_bias_index);
1502 auto output_state_in_tensor = _tensor_reg->getPortableTensor(output_state_in_index);
1503 auto cell_state_in_tensor = _tensor_reg->getPortableTensor(cell_state_in_index);
1505 auto projection_weights_tensor = has_projection_weights
1506 ? _tensor_reg->getPortableTensor(projection_weights_index)
1508 auto projection_bias_tensor = has_projection_bias
1509 ? _tensor_reg->getPortableTensor(projection_bias_index)
1518 const auto input_layer_norm_weights_index{
1519 node.
getInputs().
at(ir::operation::LSTM::Input::INPUT_LAYER_NORMALIZATION_WEIGHTS)};
1520 const auto forget_layer_norm_weights_index{
1521 node.
getInputs().
at(ir::operation::LSTM::Input::FORGET_LAYER_NORMALIZATION_WEIGHTS)};
1522 const auto cell_layer_norm_weights_index{
1523 node.
getInputs().
at(ir::operation::LSTM::Input::CELL_LAYER_NORMALIZATION_WEIGHTS)};
1524 const auto output_layer_norm_weights_index{
1525 node.
getInputs().
at(ir::operation::LSTM::Input::OUTPUT_LAYER_NORMALIZATION_WEIGHTS)};
1527 input_layer_norm_weights_tensor =
1528 _tensor_reg->getPortableTensor(input_layer_norm_weights_index);
1529 forget_layer_norm_weights_tensor =
1530 _tensor_reg->getPortableTensor(forget_layer_norm_weights_index);
1531 cell_layer_norm_weights_tensor = _tensor_reg->getPortableTensor(cell_layer_norm_weights_index);
1532 output_layer_norm_weights_tensor =
1533 _tensor_reg->getPortableTensor(output_layer_norm_weights_index);
1536 auto fn = std::make_unique<ops::LSTMLayer>();
1539 input_tensor, input_to_input_weights_tensor, input_to_forget_weights_tensor,
1540 input_to_cell_weights_tensor, input_to_output_weights_tensor, recurrent_to_input_weights_tensor,
1541 recurrent_to_forget_weights_tensor, recurrent_to_cell_weights_tensor,
1542 recurrent_to_output_weights_tensor, cell_to_input_weights_tensor, cell_to_forget_weights_tensor,
1543 cell_to_output_weights_tensor, input_layer_norm_weights_tensor,
1544 forget_layer_norm_weights_tensor, cell_layer_norm_weights_tensor,
1545 output_layer_norm_weights_tensor,
1550 nullptr, input_gate_bias_tensor, forget_gate_bias_tensor,
1551 cell_gate_bias_tensor, output_gate_bias_tensor, projection_weights_tensor,
1552 projection_bias_tensor, output_state_in_tensor, cell_state_in_tensor, node.
param(),
1554 0, scratch_buffer_tensor, output_state_out_tensor, cell_state_out_tensor,
1556 !_ctx.at(output_state_in_index).info().isVariable() ,
1557 !_ctx.at(cell_state_in_index).info().isVariable());
1559 _return_fn = std::move(fn);