Commit 481a86ea by Sunil Kumar Veerappa

Deleted accelerator tracker file

parent 60e453cd
# Copyright (c) 2018 Huawei Technologies
# All Rights Reserved.
#
# 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
#
# http://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.
"""
Track accelerator like FPGA GPU and QAT for a host. Provides the
conductor with useful information about availability through the accelerator
model.
"""
from oslo_log import log as logging
from oslo_messaging.rpc.client import RemoteError
from oslo_utils import uuidutils
from stevedore import driver
from stevedore.extension import ExtensionManager
from cyborg.common import exception
from cyborg.conf import CONF
from cyborg.accelerator.drivers.fpga.base import FPGADriver
from cyborg.accelerator.drivers.fpga.m2dc.driver import M2DCFPGADriver
from cyborg.common import utils
from cyborg import objects
LOG = logging.getLogger(__name__)
AGENT_RESOURCE_SEMAPHORE = "agent_resources"
ACCELERATOR_VERSION = "1.0"
ASSIGNABLE ="true"
BOARD="M2DC"
TYPE="FPGA"
ACCELERATOR_HOST_MAPS = {"pcie_address": "identifier",
"vendor": "vendorName",
"name": "deviceName"}
class AcceleratorTracker(object):
"""Agent helper class for keeping track of accelerator usage as instances
are built and destroyed.
"""
def __init__(self, host, cond_api):
self.fpgas = None
self.host = host
self.conductor_api = cond_api
self.acc_drivers = []
#self._initialize_drivers()
'''def _initialize_drivers(self, enabled_drivers_m2dc=[]):
"""
Load accelerator drivers.
:return: [nvidia_gpu_driver_obj, intel_fpga_driver_obj]
"""
LOG.error("control is here in acc tracker")
acc_drivers = []
if not enabled_drivers_m2dc:
enabled_drivers_m2dc = CONF.agent.enabled_drivers_m2dc
LOG.error(" Driver name from conf" + str(enabled_drivers_m2dc))
valid_drivers = ExtensionManager(
namespace='cyborg.accelerator.driver').names()
for d in enabled_drivers_m2dc:
if d not in valid_drivers:
raise exception.InvalidDriver(name=d)
acc_driver = driver.DriverManager(
namespace='cyborg.accelerator.driver', name=d,
invoke_on_load=True).driver
acc_drivers.append(acc_driver)
LOG.error("acc driver in resource " + str(acc_drivers))
self.acc_drivers = acc_drivers'''
@utils.synchronized(AGENT_RESOURCE_SEMAPHORE)
def claim(self, context):
pass
def _fpga_compare_and_update(self, host_dev, accelerator):
need_updated = False
for k, v in ACCELERATOR_HOST_MAPS.items():
if accelerator[k] != host_dev[v]:
need_updated = True
accelerator[k] = host_dev[v]
return need_updated
def _gen_accelerator_from_host_dev(self, host_dev):
dep = {}
for k, v in ACCELERATOR_HOST_MAPS.items():
dep[k] = host_dev[v]
dep["host"] = self.host
dep["version"] = ACCELERATOR_VERSION
dep["availability"] = "free"
dep["uuid"] = uuidutils.generate_uuid()
dep["board"] = BOARD
dep["type"] = TYPE
dep["assignable"] = ASSIGNABLE
return dep
@utils.synchronized(AGENT_RESOURCE_SEMAPHORE)
def update_usage(self, context):
"""Update the resource usage and stats after a change in an
instance
"""
LOG.error("Hello in update usage")
acc_list = []
for acc_driver in self.acc_drivers:
acc_list.extend(acc_driver.discover())
# Call conductor_api here to diff and report acc data. Now, we actually
# do not have the method report_data.
if acc_list:
self.conductor_api.report_data(context, self.host, acc_list)
"""
def create_accelerator(fpgas,bdf):
fpga = fpgas[bdf]
dep = self._gen_accelerator_from_host_dev(fpga)
obj_dep = objects.Accelerator(context, **dep)
new_dep = self.conductor_api.accelerator_create(context, obj_dep)
return new_dep
fpgas = self._get_fpga_devices()
bdfs = set(fpgas["name"])
accelerators = self.conductor_api.accelerator_get_by_host(
context, self.host)
accls = dict([(v["pcie_address"], v) for v in accelerators])
accl_bdfs = set(accls.keys())
# Firstly update if same accelerators available in database
for mutual in accl_bdfs & bdfs:
accl = accls[mutual]
if self._fpga_compare_and_update(fpgas[mutual], accl):
try:
self.conductor_api.accelerator_update(context, accl)
except RemoteError as e:
LOG.error(e)
# Add fpga if it is not in database
new = bdfs - accl_bdfs
for n in new:
new_dep = create_accelerator(fpgas,n)
# Delete fpga if it is not present
for obsolete in accl_bdfs - bdfs:
try:
self.conductor_api.accelerator_delete(context, accls[obsolete])
except RemoteError as e:
LOG.error(e)
del accls[obsolete]
"""
def _get_fpga_devices(self):
available_fpgas=[]
available_fpgas = self.fpga_driver.discover()
return available_fpgas
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment