diff --git a/cyborg/accelerator/drivers/fake.py b/cyborg/accelerator/drivers/fake.py new file mode 100644 index 00000000..8ab72879 --- /dev/null +++ b/cyborg/accelerator/drivers/fake.py @@ -0,0 +1,79 @@ +from cyborg.accelerator.drivers.driver import GenericDriver +from cyborg.objects.driver_objects import driver_deployable, driver_device, \ + driver_attach_handle, driver_controlpath_id, driver_attribute + +from cyborg.agent import rc_fields +from cyborg.common import constants + +import os_resource_classes as orc +from oslo_serialization import jsonutils + + +class FakeDriver(GenericDriver): + """Base class for Fake drivers. + + This is just a Fake drivers interface. + """ + VENDOR = "fake" + + def _generate_controlpath_id(self, pci): + driver_cpid = driver_controlpath_id.DriverControlPathID() + driver_cpid.cpid_type = "PCI" + driver_cpid.cpid_info = pci["slot"] + return driver_cpid + + def _generate_attach_handle(self, pci): + driver_ah = driver_attach_handle.DriverAttachHandle() + # The virt driver will ignore this type when attaching + driver_ah.attach_type = "fake" + driver_ah.in_use = False + driver_ah.attach_info = pci["slot"] + return driver_ah + + def _generate_attribute_list(self): + attr_traits = driver_attribute.DriverAttribute() + attr_traits.key = "traits1" + attr_traits.value = "CUSTOM_FAKE_DEVICE" + attr_rc = driver_attribute.DriverAttribute() + attr_rc.key = "rc" + attr_rc.value = rc_fields.ResourceClass.normalize_name( + rc_fields.ResourceClass.FPGA) + return [attr_traits, attr_rc] + + def _generate_dep_list(self, pci): + driver_dep = driver_deployable.DriverDeployable() + driver_dep.attach_handle_list = [self._generate_attach_handle(pci)] + driver_dep.name = pci.get('device') + driver_dep.num_accelerators = 1 + driver_dep.attribute_list = self._generate_attribute_list() + return [driver_dep] + + def discover(self): + npu_list = [] + pci_addr = '{"domain":"0000","bus":"0c","device":"00","function":"0"}' + pci_dict = { + 'slot': pci_addr, # PCI slot address + 'device': 'FakeDevice', # Name of the device + 'vendor_id': 'fake', # ID of the vendor + 'class': 'Fake class', # Name of the class + 'device_id': 'fake', # ID of the device + 'revision': '20' # Revision number + } + device = driver_device.DriverDevice() + device.vendor = pci_dict["vendor_id"] + device.model = pci_dict.get('model', 'miss model info') + std_board_info = {'device_id': pci_dict.get('device_id', None), + 'class': pci_dict.get('class', None)} + device.std_board_info = jsonutils.dumps(std_board_info) + device.vendor_board_info = 'fake_vendor_info' + device.type = orc.PGPU + device.controlpath_id = self._generate_controlpath_id(pci_dict) + device.deployable_list = self._generate_dep_list(pci_dict) + npu_list.append(device) + return npu_list + + def update(self, control_path, image_path): + return True + + def get_stats(self): + return {} diff --git a/requirements.txt b/requirements.txt index 909bf2d0..a24ebae9 100644 --- a/requirements.txt +++ b/requirements.txt @@ -15,6 +15,7 @@ oslo.messaging>=5.29.0 # Apache-2.0 oslo.concurrency>=3.26.0 # Apache-2.0 oslo.service>=1.0.0,!=1.28.1 # Apache-2.0 oslo.db>=4.1.0 # Apache-2.0 +os-resource-classes>=0.5.0 # Apache-2.0 oslo.upgradecheck>=0.1.0 # Apache-2.0 oslo.utils>=3.33.0 # Apache-2.0 oslo.versionedobjects>=1.31.2 # Apache-2.0 diff --git a/setup.cfg b/setup.cfg index 0af26dda..9b3985f6 100644 --- a/setup.cfg +++ b/setup.cfg @@ -48,6 +48,7 @@ cyborg.accelerator.driver = intel_fpga_driver = cyborg.accelerator.drivers.fpga.intel.driver:IntelFPGADriver nvmf_spdk_driver = cyborg.accelerator.drivers.spdk.nvmf.nvmf:NVMFDRIVER nvidia_gpu_driver = cyborg.accelerator.drivers.gpu.nvidia.driver:NVIDIAGPUDriver + fake_driver = cyborg.accelerator.drivers.fake:FakeDriver oslo.config.opts = cyborg = cyborg.conf.opts:list_opts