294 const auto ifm_index{node.
getInputs().
at(Conv2D::Input::INPUT)};
295 const auto ker_index{node.
getInputs().
at(Conv2D::Input::KERNEL)};
296 const auto bias_index{node.
getInputs().
at(Conv2D::Input::BIAS)};
298 auto ofm_tensor = _tensor_reg->getPortableTensor(ofm_index);
299 auto ifm_tensor = _tensor_reg->getPortableTensor(ifm_index);
300 auto ker_tensor = _tensor_reg->getPortableTensor(ker_index);
301 auto bias_tensor = _tensor_reg->getPortableTensor(bias_index);
308 const bool is_cacheable_weights =
ker_tensor->is_constant();
310 auto fn = std::make_unique<ops::ConvolutionLayer>();
312 if (_ctx.at(ifm_index).info().isDynamic() || _ctx.at(ker_index).info().isDynamic())
315 param_padding.param.right, param_padding.param.top, param_padding.param.bottom,
316 stride.horizontal, stride.vertical, dilation.width_factor, dilation.height_factor,
317 activation, ofm_tensor, is_cacheable_weights);
319 _return_fn = std::move(fn);
322 const auto ifm_shape = _ctx.at(ifm_index).shape().asFeature();
323 const auto ofm_shape = _ctx.at(ofm_index).shape().asFeature();
325 const auto &ker_shape = _ctx.at(ker_index).shape();
326 const auto ker_height = ker_shape.dim(1);
327 const auto ker_width = ker_shape.dim(2);
330 ir::calculatePadding(param_padding, ifm_shape, ofm_shape, stride, ker_width, ker_height,
331 dilation.width_factor, dilation.height_factor);
334 padding.right, padding.top, padding.bottom, stride.horizontal, stride.vertical,
335 dilation.width_factor, dilation.height_factor, activation, ofm_tensor,
336 is_cacheable_weights);
338 _return_fn = std::move(fn);
346 const auto ifm_index{node.
getInputs().
at(DepthwiseConv2D::Input::INPUT)};
347 const auto ker_index{node.
getInputs().
at(DepthwiseConv2D::Input::KERNEL)};
348 const auto bias_index{node.
getInputs().
at(DepthwiseConv2D::Input::BIAS)};
351 const auto ifm_shape = _ctx.at(ifm_index).shape().asFeature();
352 const auto ofm_shape = _ctx.at(ofm_index).shape().asFeature();
354 const auto &ker_shape = _ctx.at(ker_index).shape();
355 const auto ker_height = ker_shape.dim(1);
356 const auto ker_width = ker_shape.dim(2);
359 const auto padding = ir::calculatePadding(node.
param().
padding, ifm_shape, ofm_shape, stride,
360 ker_width, ker_height, dilation_width, dilation_height);
364 auto ofm_tensor = _tensor_reg->getPortableTensor(ofm_index);
365 auto ifm_tensor = _tensor_reg->getPortableTensor(ifm_index);
366 auto ker_tensor = _tensor_reg->getPortableTensor(ker_index);
367 auto bias_tensor = _tensor_reg->getPortableTensor(bias_index);
369 auto fn = std::make_unique<ops::DepthwiseConvolutionLayer>();
372 padding.bottom, stride.horizontal, stride.vertical, multiplier, dilation_width,
373 dilation_height, activation, ofm_tensor, _external_context);
375 _return_fn = std::move(fn);
1388 const auto scratch_buffer_index{
1389 node.
getOutputs().
at(ir::operation::LSTM::Output::SCRATCH_BUFFER)};
1390 const auto output_state_out_index{
1391 node.
getOutputs().
at(ir::operation::LSTM::Output::OUTPUT_STATE_OUT)};
1392 const auto cell_state_out_index{
1393 node.
getOutputs().
at(ir::operation::LSTM::Output::CELL_STATE_OUT)};
1394 const auto output_index{node.
getOutputs().
at(ir::operation::LSTM::Output::OUTPUT)};
1396 const auto input_index{node.
getInputs().
at(ir::operation::LSTM::Input::INPUT)};
1397 const auto input_to_input_weights_index{
1398 node.
getInputs().
at(ir::operation::LSTM::Input::INPUT_TO_INPUT_WEIGHTS)};
1399 const auto input_to_forget_weights_index{
1400 node.
getInputs().
at(ir::operation::LSTM::Input::INPUT_TO_FORGET_WEIGHTS)};
1401 const auto input_to_cell_weights_index{
1402 node.
getInputs().
at(ir::operation::LSTM::Input::INPUT_TO_CELL_WEIGHTS)};
1403 const auto input_to_output_weights_index{
1404 node.
getInputs().
at(ir::operation::LSTM::Input::INPUT_TO_OUTPUT_WEIGHTS)};
1405 const auto recurrent_to_input_weights_index{
1406 node.
getInputs().
at(ir::operation::LSTM::Input::RECURRENT_TO_INPUT_WEIGHTS)};
1407 const auto recurrent_to_forget_weights_index{
1408 node.
getInputs().
at(ir::operation::LSTM::Input::RECURRENT_TO_FORGET_WEIGHTS)};
1409 const auto recurrent_to_cell_weights_index{
1410 node.
getInputs().
at(ir::operation::LSTM::Input::RECURRENT_TO_CELL_WEIGHTS)};
1411 const auto recurrent_to_output_weights_index{
1412 node.
getInputs().
at(ir::operation::LSTM::Input::RECURRENT_TO_OUTPUT_WEIGHTS)};
1413 const auto cell_to_input_weights_index{
1414 node.
getInputs().
at(ir::operation::LSTM::Input::CELL_TO_INPUT_WEIGHTS)};
1415 const auto cell_to_forget_weights_index{
1416 node.
getInputs().
at(ir::operation::LSTM::Input::CELL_TO_FORGET_WEIGHTS)};
1417 const auto cell_to_output_weights_index{
1418 node.
getInputs().
at(ir::operation::LSTM::Input::CELL_TO_OUTPUT_WEIGHTS)};
1419 const auto input_gate_bias_index{
1420 node.
getInputs().
at(ir::operation::LSTM::Input::INPUT_GATE_BIAS)};
1421 const auto forget_gate_bias_index{
1422 node.
getInputs().
at(ir::operation::LSTM::Input::FORGET_GATE_BIAS)};
1423 const auto cell_gate_bias_index{node.
getInputs().
at(ir::operation::LSTM::Input::CELL_BIAS)};
1424 const auto output_gate_bias_index{
1425 node.
getInputs().
at(ir::operation::LSTM::Input::OUTPUT_GATE_BIAS)};
1426 const auto projection_weights_index{
1427 node.
getInputs().
at(ir::operation::LSTM::Input::PROJECTION_WEIGHTS)};
1428 const auto projection_bias_index{
1429 node.
getInputs().
at(ir::operation::LSTM::Input::PROJECTION_BIAS)};
1430 const auto output_state_in_index{
1431 node.
getInputs().
at(ir::operation::LSTM::Input::OUTPUT_STATE_IN)};
1432 const auto cell_state_in_index{node.
getInputs().
at(ir::operation::LSTM::Input::CELL_STATE_IN)};
1439 bool has_input_to_input_weights = _ctx.exist(input_to_input_weights_index) &&
1440 (_ctx.at(input_to_input_weights_index).shape().dim(0) != 0 &&
1441 _ctx.at(input_to_input_weights_index).shape().dim(1) != 0);
1442 bool has_recurrent_to_input_weights =
1443 _ctx.exist(recurrent_to_input_weights_index) &&
1444 (_ctx.at(recurrent_to_input_weights_index).shape().dim(0) != 0 &&
1445 _ctx.at(recurrent_to_input_weights_index).shape().dim(1) != 0);
1451 bool has_cell_to_forget_weights = _ctx.exist(cell_to_forget_weights_index) &&
1452 _ctx.at(cell_to_forget_weights_index).shape().dim(0) != 0;
1453 bool has_cell_to_output_weights = _ctx.exist(cell_to_output_weights_index) &&
1454 _ctx.at(cell_to_output_weights_index).shape().dim(0) != 0;
1456 bool has_input_gate_bias =
1457 _ctx.exist(input_gate_bias_index) && _ctx.at(input_gate_bias_index).shape().dim(0);
1459 bool has_projection_weights = _ctx.exist(projection_weights_index) &&
1460 (_ctx.at(projection_weights_index).shape().dim(0) != 0 &&
1461 _ctx.at(projection_weights_index).shape().dim(1) != 0);
1462 bool has_projection_bias =
1463 _ctx.exist(projection_bias_index) && _ctx.at(projection_bias_index).shape().dim(0);
1465 auto scratch_buffer_tensor = _ctx.exist(scratch_buffer_index)
1466 ? _tensor_reg->getPortableTensor(scratch_buffer_index)
1468 auto output_state_out_tensor = _ctx.exist(output_state_out_index)
1469 ? _tensor_reg->getPortableTensor(output_state_out_index)
1471 auto cell_state_out_tensor = _ctx.exist(cell_state_out_index)
1472 ? _tensor_reg->getPortableTensor(cell_state_out_index)
1474 auto output_tensor = _tensor_reg->getPortableTensor(output_index);
1476 auto input_tensor = _tensor_reg->getPortableTensor(input_index);
1478 auto input_to_input_weights_tensor =
1479 has_input_to_input_weights ? _tensor_reg->getPortableTensor(input_to_input_weights_index)
1481 auto input_to_forget_weights_tensor =
1482 _tensor_reg->getPortableTensor(input_to_forget_weights_index);
1483 auto input_to_cell_weights_tensor = _tensor_reg->getPortableTensor(input_to_cell_weights_index);
1484 auto input_to_output_weights_tensor =
1485 _tensor_reg->getPortableTensor(input_to_output_weights_index);
1486 auto recurrent_to_input_weights_tensor =
1487 has_recurrent_to_input_weights
1488 ? _tensor_reg->getPortableTensor(recurrent_to_input_weights_index)
1490 auto recurrent_to_forget_weights_tensor =
1491 _tensor_reg->getPortableTensor(recurrent_to_forget_weights_index);
1492 auto recurrent_to_cell_weights_tensor =
1493 _tensor_reg->getPortableTensor(recurrent_to_cell_weights_index);
1494 auto recurrent_to_output_weights_tensor =
1495 _tensor_reg->getPortableTensor(recurrent_to_output_weights_index);
1497 auto cell_to_input_weights_tensor = _tensor_reg->getPortableTensor(cell_to_input_weights_index);
1498 auto cell_to_forget_weights_tensor =
1499 has_cell_to_forget_weights ? _tensor_reg->getPortableTensor(cell_to_forget_weights_index)
1501 auto cell_to_output_weights_tensor =
1502 has_cell_to_output_weights ? _tensor_reg->getPortableTensor(cell_to_output_weights_index)
1505 auto input_gate_bias_tensor =
1506 has_input_gate_bias ? _tensor_reg->getPortableTensor(input_gate_bias_index) :
nullptr;
1507 auto forget_gate_bias_tensor = _tensor_reg->getPortableTensor(forget_gate_bias_index);
1508 auto cell_gate_bias_tensor = _tensor_reg->getPortableTensor(cell_gate_bias_index);
1509 auto output_gate_bias_tensor = _tensor_reg->getPortableTensor(output_gate_bias_index);
1510 auto output_state_in_tensor = _tensor_reg->getPortableTensor(output_state_in_index);
1511 auto cell_state_in_tensor = _tensor_reg->getPortableTensor(cell_state_in_index);
1513 auto projection_weights_tensor = has_projection_weights
1514 ? _tensor_reg->getPortableTensor(projection_weights_index)
1516 auto projection_bias_tensor = has_projection_bias
1517 ? _tensor_reg->getPortableTensor(projection_bias_index)
1526 const auto input_layer_norm_weights_index{
1527 node.
getInputs().
at(ir::operation::LSTM::Input::INPUT_LAYER_NORMALIZATION_WEIGHTS)};
1528 const auto forget_layer_norm_weights_index{
1529 node.
getInputs().
at(ir::operation::LSTM::Input::FORGET_LAYER_NORMALIZATION_WEIGHTS)};
1530 const auto cell_layer_norm_weights_index{
1531 node.
getInputs().
at(ir::operation::LSTM::Input::CELL_LAYER_NORMALIZATION_WEIGHTS)};
1532 const auto output_layer_norm_weights_index{
1533 node.
getInputs().
at(ir::operation::LSTM::Input::OUTPUT_LAYER_NORMALIZATION_WEIGHTS)};
1535 input_layer_norm_weights_tensor =
1536 _tensor_reg->getPortableTensor(input_layer_norm_weights_index);
1537 forget_layer_norm_weights_tensor =
1538 _tensor_reg->getPortableTensor(forget_layer_norm_weights_index);
1539 cell_layer_norm_weights_tensor = _tensor_reg->getPortableTensor(cell_layer_norm_weights_index);
1540 output_layer_norm_weights_tensor =
1541 _tensor_reg->getPortableTensor(output_layer_norm_weights_index);
1544 auto fn = std::make_unique<ops::LSTMLayer>();
1547 input_tensor, input_to_input_weights_tensor, input_to_forget_weights_tensor,
1548 input_to_cell_weights_tensor, input_to_output_weights_tensor, recurrent_to_input_weights_tensor,
1549 recurrent_to_forget_weights_tensor, recurrent_to_cell_weights_tensor,
1550 recurrent_to_output_weights_tensor, cell_to_input_weights_tensor, cell_to_forget_weights_tensor,
1551 cell_to_output_weights_tensor, input_layer_norm_weights_tensor,
1552 forget_layer_norm_weights_tensor, cell_layer_norm_weights_tensor,
1553 output_layer_norm_weights_tensor,
1558 nullptr, input_gate_bias_tensor, forget_gate_bias_tensor,
1559 cell_gate_bias_tensor, output_gate_bias_tensor, projection_weights_tensor,
1560 projection_bias_tensor, output_state_in_tensor, cell_state_in_tensor, node.
param(),
1562 0, scratch_buffer_tensor, output_state_out_tensor, cell_state_out_tensor,
1564 !_ctx.at(output_state_in_index).info().isVariable() ,
1565 !_ctx.at(cell_state_in_index).info().isVariable());
1567 _return_fn = std::move(fn);