i am using the python and tensorflow keras to implemet my neural network,psutil to schdule layers on CPUs. how can i measure the exact communication latency?

i have tried with the following code, but this is not giving the actual latency

import psutil
import time

# function to measure the execution time of layer executing on perticular cpu
def compute_execution_time(target_instance, target_method, core_id=0, *args):
    try:
        psutil.Process().cpu_affinity([core_id])
    except AttributeError:
        pass  
    start_time = time.perf_counter()
    tt=getattr(target_instance, target_method)(*args)
    end_time = time.perf_counter()
    execution_time = end_time - start_time
    # print(f"Execution time on core {core_id}: {execution_time} seconds")
    return execution_time


def get_latency(obj,layer_ids,core_ids,input_data):
    
    temp=[0]*2
    # executing layer on given cpu and taking there execution time
    for lay in range(len(layer_ids)):
        temp[lay]=compute_execution_time(obj,'execute_on_core',core_ids[lay],layer_ids[lay],input_data[lay])
        
    return sum(temp), temp
0

There are 0 best solutions below