296 const auto ifm_index{node.
getInputs().
at(Conv2D::Input::INPUT)};
297 const auto ker_index{node.
getInputs().
at(Conv2D::Input::KERNEL)};
298 const auto bias_index{node.
getInputs().
at(Conv2D::Input::BIAS)};
300 auto ofm_tensor = _tensor_reg->getPortableTensor(ofm_index);
301 auto ifm_tensor = _tensor_reg->getPortableTensor(ifm_index);
302 auto ker_tensor = _tensor_reg->getPortableTensor(ker_index);
303 auto bias_tensor = _tensor_reg->getPortableTensor(bias_index);
310 const bool is_cacheable_weights = ker_tensor->is_constant();
312 auto fn = std::make_unique<ops::ConvolutionLayer>();
314 if (_ctx.at(ifm_index).info().isDynamic() || _ctx.at(ker_index).info().isDynamic())
316 fn->configure(ifm_tensor, ker_tensor, bias_tensor, param_padding.type, param_padding.param.left,
317 param_padding.param.right, param_padding.param.top, param_padding.param.bottom,
318 stride.horizontal, stride.vertical, dilation.width_factor, dilation.height_factor,
319 activation, ofm_tensor, is_cacheable_weights);
321 _return_fn = std::move(fn);
324 const auto ifm_shape = _ctx.at(ifm_index).shape().asFeature();
325 const auto ofm_shape = _ctx.at(ofm_index).shape().asFeature();
327 const auto &ker_shape = _ctx.at(ker_index).shape();
328 const auto ker_height = ker_shape.dim(1);
329 const auto ker_width = ker_shape.dim(2);
332 ir::calculatePadding(param_padding, ifm_shape, ofm_shape, stride, ker_width, ker_height,
333 dilation.width_factor, dilation.height_factor);
335 fn->configure(ifm_tensor, ker_tensor, bias_tensor, param_padding.type, padding.left,
336 padding.right, padding.top, padding.bottom, stride.horizontal, stride.vertical,
337 dilation.width_factor, dilation.height_factor, activation, ofm_tensor,
338 is_cacheable_weights);
340 _return_fn = std::move(fn);
348 const auto ifm_index{node.
getInputs().
at(DepthwiseConv2D::Input::INPUT)};
349 const auto ker_index{node.
getInputs().
at(DepthwiseConv2D::Input::KERNEL)};
350 const auto bias_index{node.
getInputs().
at(DepthwiseConv2D::Input::BIAS)};
353 const auto ifm_shape = _ctx.at(ifm_index).shape().asFeature();
354 const auto ofm_shape = _ctx.at(ofm_index).shape().asFeature();
356 const auto &ker_shape = _ctx.at(ker_index).shape();
357 const auto ker_height = ker_shape.dim(1);
358 const auto ker_width = ker_shape.dim(2);
361 const auto padding = ir::calculatePadding(node.
param().
padding, ifm_shape, ofm_shape, stride,
362 ker_width, ker_height, dilation_width, dilation_height);
366 auto ofm_tensor = _tensor_reg->getPortableTensor(ofm_index);
367 auto ifm_tensor = _tensor_reg->getPortableTensor(ifm_index);
368 auto ker_tensor = _tensor_reg->getPortableTensor(ker_index);
369 auto bias_tensor = _tensor_reg->getPortableTensor(bias_index);
371 auto fn = std::make_unique<ops::DepthwiseConvolutionLayer>();
373 fn->configure(ifm_tensor, ker_tensor, bias_tensor, padding.left, padding.right, padding.top,
374 padding.bottom, stride.horizontal, stride.vertical, multiplier, dilation_width,
375 dilation_height, activation, ofm_tensor, _external_context);
377 _return_fn = std::move(fn);
1384 const auto scratch_buffer_index{
1385 node.
getOutputs().
at(ir::operation::LSTM::Output::SCRATCH_BUFFER)};
1386 const auto output_state_out_index{
1387 node.
getOutputs().
at(ir::operation::LSTM::Output::OUTPUT_STATE_OUT)};
1388 const auto cell_state_out_index{
1389 node.
getOutputs().
at(ir::operation::LSTM::Output::CELL_STATE_OUT)};
1390 const auto output_index{node.
getOutputs().
at(ir::operation::LSTM::Output::OUTPUT)};
1392 const auto input_index{node.
getInputs().
at(ir::operation::LSTM::Input::INPUT)};
1393 const auto input_to_input_weights_index{
1394 node.
getInputs().
at(ir::operation::LSTM::Input::INPUT_TO_INPUT_WEIGHTS)};
1395 const auto input_to_forget_weights_index{
1396 node.
getInputs().
at(ir::operation::LSTM::Input::INPUT_TO_FORGET_WEIGHTS)};
1397 const auto input_to_cell_weights_index{
1398 node.
getInputs().
at(ir::operation::LSTM::Input::INPUT_TO_CELL_WEIGHTS)};
1399 const auto input_to_output_weights_index{
1400 node.
getInputs().
at(ir::operation::LSTM::Input::INPUT_TO_OUTPUT_WEIGHTS)};
1401 const auto recurrent_to_input_weights_index{
1402 node.
getInputs().
at(ir::operation::LSTM::Input::RECURRENT_TO_INPUT_WEIGHTS)};
1403 const auto recurrent_to_forget_weights_index{
1404 node.
getInputs().
at(ir::operation::LSTM::Input::RECURRENT_TO_FORGET_WEIGHTS)};
1405 const auto recurrent_to_cell_weights_index{
1406 node.
getInputs().
at(ir::operation::LSTM::Input::RECURRENT_TO_CELL_WEIGHTS)};
1407 const auto recurrent_to_output_weights_index{
1408 node.
getInputs().
at(ir::operation::LSTM::Input::RECURRENT_TO_OUTPUT_WEIGHTS)};
1409 const auto cell_to_input_weights_index{
1410 node.
getInputs().
at(ir::operation::LSTM::Input::CELL_TO_INPUT_WEIGHTS)};
1411 const auto cell_to_forget_weights_index{
1412 node.
getInputs().
at(ir::operation::LSTM::Input::CELL_TO_FORGET_WEIGHTS)};
1413 const auto cell_to_output_weights_index{
1414 node.
getInputs().
at(ir::operation::LSTM::Input::CELL_TO_OUTPUT_WEIGHTS)};
1415 const auto input_gate_bias_index{
1416 node.
getInputs().
at(ir::operation::LSTM::Input::INPUT_GATE_BIAS)};
1417 const auto forget_gate_bias_index{
1418 node.
getInputs().
at(ir::operation::LSTM::Input::FORGET_GATE_BIAS)};
1419 const auto cell_gate_bias_index{node.
getInputs().
at(ir::operation::LSTM::Input::CELL_BIAS)};
1420 const auto output_gate_bias_index{
1421 node.
getInputs().
at(ir::operation::LSTM::Input::OUTPUT_GATE_BIAS)};
1422 const auto projection_weights_index{
1423 node.
getInputs().
at(ir::operation::LSTM::Input::PROJECTION_WEIGHTS)};
1424 const auto projection_bias_index{
1425 node.
getInputs().
at(ir::operation::LSTM::Input::PROJECTION_BIAS)};
1426 const auto output_state_in_index{
1427 node.
getInputs().
at(ir::operation::LSTM::Input::OUTPUT_STATE_IN)};
1428 const auto cell_state_in_index{node.
getInputs().
at(ir::operation::LSTM::Input::CELL_STATE_IN)};
1435 bool has_input_to_input_weights = _ctx.exist(input_to_input_weights_index) &&
1436 (_ctx.at(input_to_input_weights_index).shape().dim(0) != 0 &&
1437 _ctx.at(input_to_input_weights_index).shape().dim(1) != 0);
1438 bool has_recurrent_to_input_weights =
1439 _ctx.exist(recurrent_to_input_weights_index) &&
1440 (_ctx.at(recurrent_to_input_weights_index).shape().dim(0) != 0 &&
1441 _ctx.at(recurrent_to_input_weights_index).shape().dim(1) != 0);
1447 bool has_cell_to_forget_weights = _ctx.exist(cell_to_forget_weights_index) &&
1448 _ctx.at(cell_to_forget_weights_index).shape().dim(0) != 0;
1449 bool has_cell_to_output_weights = _ctx.exist(cell_to_output_weights_index) &&
1450 _ctx.at(cell_to_output_weights_index).shape().dim(0) != 0;
1452 bool has_input_gate_bias =
1453 _ctx.exist(input_gate_bias_index) && _ctx.at(input_gate_bias_index).shape().dim(0);
1455 bool has_projection_weights = _ctx.exist(projection_weights_index) &&
1456 (_ctx.at(projection_weights_index).shape().dim(0) != 0 &&
1457 _ctx.at(projection_weights_index).shape().dim(1) != 0);
1458 bool has_projection_bias =
1459 _ctx.exist(projection_bias_index) && _ctx.at(projection_bias_index).shape().dim(0);
1461 auto scratch_buffer_tensor = _ctx.exist(scratch_buffer_index)
1462 ? _tensor_reg->getPortableTensor(scratch_buffer_index)
1464 auto output_state_out_tensor = _ctx.exist(output_state_out_index)
1465 ? _tensor_reg->getPortableTensor(output_state_out_index)
1467 auto cell_state_out_tensor = _ctx.exist(cell_state_out_index)
1468 ? _tensor_reg->getPortableTensor(cell_state_out_index)
1470 auto output_tensor = _tensor_reg->getPortableTensor(output_index);
1472 auto input_tensor = _tensor_reg->getPortableTensor(input_index);
1474 auto input_to_input_weights_tensor =
1475 has_input_to_input_weights ? _tensor_reg->getPortableTensor(input_to_input_weights_index)
1477 auto input_to_forget_weights_tensor =
1478 _tensor_reg->getPortableTensor(input_to_forget_weights_index);
1479 auto input_to_cell_weights_tensor = _tensor_reg->getPortableTensor(input_to_cell_weights_index);
1480 auto input_to_output_weights_tensor =
1481 _tensor_reg->getPortableTensor(input_to_output_weights_index);
1482 auto recurrent_to_input_weights_tensor =
1483 has_recurrent_to_input_weights
1484 ? _tensor_reg->getPortableTensor(recurrent_to_input_weights_index)
1486 auto recurrent_to_forget_weights_tensor =
1487 _tensor_reg->getPortableTensor(recurrent_to_forget_weights_index);
1488 auto recurrent_to_cell_weights_tensor =
1489 _tensor_reg->getPortableTensor(recurrent_to_cell_weights_index);
1490 auto recurrent_to_output_weights_tensor =
1491 _tensor_reg->getPortableTensor(recurrent_to_output_weights_index);
1493 auto cell_to_input_weights_tensor = _tensor_reg->getPortableTensor(cell_to_input_weights_index);
1494 auto cell_to_forget_weights_tensor =
1495 has_cell_to_forget_weights ? _tensor_reg->getPortableTensor(cell_to_forget_weights_index)
1497 auto cell_to_output_weights_tensor =
1498 has_cell_to_output_weights ? _tensor_reg->getPortableTensor(cell_to_output_weights_index)
1501 auto input_gate_bias_tensor =
1502 has_input_gate_bias ? _tensor_reg->getPortableTensor(input_gate_bias_index) :
nullptr;
1503 auto forget_gate_bias_tensor = _tensor_reg->getPortableTensor(forget_gate_bias_index);
1504 auto cell_gate_bias_tensor = _tensor_reg->getPortableTensor(cell_gate_bias_index);
1505 auto output_gate_bias_tensor = _tensor_reg->getPortableTensor(output_gate_bias_index);
1506 auto output_state_in_tensor = _tensor_reg->getPortableTensor(output_state_in_index);
1507 auto cell_state_in_tensor = _tensor_reg->getPortableTensor(cell_state_in_index);
1509 auto projection_weights_tensor = has_projection_weights
1510 ? _tensor_reg->getPortableTensor(projection_weights_index)
1512 auto projection_bias_tensor = has_projection_bias
1513 ? _tensor_reg->getPortableTensor(projection_bias_index)
1522 const auto input_layer_norm_weights_index{
1523 node.
getInputs().
at(ir::operation::LSTM::Input::INPUT_LAYER_NORMALIZATION_WEIGHTS)};
1524 const auto forget_layer_norm_weights_index{
1525 node.
getInputs().
at(ir::operation::LSTM::Input::FORGET_LAYER_NORMALIZATION_WEIGHTS)};
1526 const auto cell_layer_norm_weights_index{
1527 node.
getInputs().
at(ir::operation::LSTM::Input::CELL_LAYER_NORMALIZATION_WEIGHTS)};
1528 const auto output_layer_norm_weights_index{
1529 node.
getInputs().
at(ir::operation::LSTM::Input::OUTPUT_LAYER_NORMALIZATION_WEIGHTS)};
1531 input_layer_norm_weights_tensor =
1532 _tensor_reg->getPortableTensor(input_layer_norm_weights_index);
1533 forget_layer_norm_weights_tensor =
1534 _tensor_reg->getPortableTensor(forget_layer_norm_weights_index);
1535 cell_layer_norm_weights_tensor = _tensor_reg->getPortableTensor(cell_layer_norm_weights_index);
1536 output_layer_norm_weights_tensor =
1537 _tensor_reg->getPortableTensor(output_layer_norm_weights_index);
1540 auto fn = std::make_unique<ops::LSTMLayer>();
1543 input_tensor, input_to_input_weights_tensor, input_to_forget_weights_tensor,
1544 input_to_cell_weights_tensor, input_to_output_weights_tensor, recurrent_to_input_weights_tensor,
1545 recurrent_to_forget_weights_tensor, recurrent_to_cell_weights_tensor,
1546 recurrent_to_output_weights_tensor, cell_to_input_weights_tensor, cell_to_forget_weights_tensor,
1547 cell_to_output_weights_tensor, input_layer_norm_weights_tensor,
1548 forget_layer_norm_weights_tensor, cell_layer_norm_weights_tensor,
1549 output_layer_norm_weights_tensor,
1554 nullptr, input_gate_bias_tensor, forget_gate_bias_tensor,
1555 cell_gate_bias_tensor, output_gate_bias_tensor, projection_weights_tensor,
1556 projection_bias_tensor, output_state_in_tensor, cell_state_in_tensor, node.
param(),
1558 0, scratch_buffer_tensor, output_state_out_tensor, cell_state_out_tensor,
1560 !_ctx.at(output_state_in_index).info().isVariable() ,
1561 !_ctx.at(cell_state_in_index).info().isVariable());
1563 _return_fn = std::move(fn);