def create_mock(test_vec): with patch("ethosu.vela.api.npu_encode_weights") as mock_enc_w: with patch("ethosu.vela.api.npu_find_block_configs") as mock_blk_cfg: mock_blk_cfg.return_value = [vapi.NpuShape3D(8, 8, 8)] ethosu_conv2d_calls = extract_ethosu_conv2d_extern_calls(test_vec["tir_module"]) buffer_info = tirtocs.extract_buffer_info( test_vec["tir_module"], test_vec["param_dict"] ) for ethosu_conv2d_call in ethosu_conv2d_calls: npu_op, _ = tirtocs.translate_ethosu_conv2d(ethosu_conv2d_call) weights = buffer_info[npu_op.weights[0].address.buffer_var][0] vela_api.encode_weights(ethosu_conv2d_call, weights, accel) return mock_enc_w
def _encode_weights(tir_extern_call, weights): """Encode the weights for a TIR extern call.""" value_bytes = vela_api.encode_weights(tir_extern_call, weights, accel_config) value = np.frombuffer(value_bytes, dtype="uint8") return value