Source code for secretflow.device.link

# Copyright 2022 Ant Group Co., Ltd.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import logging
import threading
from threading import Condition
from typing import Any, Dict, List, Union

from .device import PYU, Device

thread_local = threading.local()

SERVER = "server"
CLIENT = "client"


[docs]def get_role(): return thread_local.link.role
[docs]def get_device(): return thread_local.link.device
[docs]def set_mesh(link): thread_local.link = link
[docs]def send_to_clients(name, value, version): """Send message to the target device. this function is non-blocking. Args: name: message name value: message value version: message version, used to distinguish between different training rounds """ thread_local.link.send(name, value, thread_local.link._clients, version)
[docs]def send_to_server(name, value, version): """Send message to the target device. this function is non-blocking. Args: name: message name value: message value version: message version, used to distinguish between different training rounds """ thread_local.link.send(name, value, thread_local.link._server, version)
[docs]def recv_from_clients(name, version): """ Receive messages from the source device. this function is blocking Args: name: message name version: TODO: What is the purpose of the version parameter? Returns: The received message """ return thread_local.link.recv(name, thread_local.link._clients, version)
[docs]def recv_from_server(name, version): """ Receive messages from the source device. this function is blocking Args: name: message name version: message version, used to distinguish between different training rounds Returns: The received message """ return thread_local.link.recv(name, thread_local.link._server, version)