Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions cyborg/accelerator/drivers/aichip/rebellions/driver.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Copyright 2025 Electronics and Telecommunications Research Institute.
#
# This software was supported by the Institute of Information & Communications
# Technology Planning & Evaluation(IITP) grant funded by the Korea government
# (MSIT) (No.RS-2025-02263869, Development of AI Semiconductor Cloud Platform
# Establishment and Optimization Technology)
#
# Modifications Copyright (C) 2020 ZTE Corporation
# Copyright 2018 Beijing Lenovo Software 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
#
# 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.


"""
Cyborg Rebellions AICHIP driver implementation.
"""

from cyborg.accelerator.drivers.aichip.base import AICHIPDriver
from cyborg.accelerator.drivers.aichip.rebellions import sysinfo


class RebellionsAICHIPDriver(AICHIPDriver):
"""Class for Rebellions AICHIP drivers.
Vendor should implement their specific drivers in this class.
"""

VENDOR = "rebellions"
VENDOR_ID = "1eff"

def discover(self):
return sysinfo.discover(self.VENDOR_ID)
167 changes: 167 additions & 0 deletions cyborg/accelerator/drivers/aichip/rebellions/sysinfo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
# Copyright 2025 Electronics and Telecommunications Research Institute.
#
# This software was supported by the Institute of Information & Communications
# Technology Planning & Evaluation(IITP) grant funded by the Korea government
# (MSIT) (No.RS-2025-02263869, Development of AI Semiconductor Cloud Platform
# Establishment and Optimization Technology)
#
# Modifications Copyright (C) 2021 ZTE Corporation
# Copyright 2018 Beijing Lenovo Software 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
#
# 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.


"""
Cyborg Rebellions AICHIP driver implementation.
"""

from oslo_log import log as logging
from oslo_serialization import jsonutils


from cyborg.accelerator.common import utils
from cyborg.accelerator.drivers.aichip import utils as aichip_utils
from cyborg.common import constants
from cyborg.conf import CONF
from cyborg.objects.driver_objects import driver_attach_handle
from cyborg.objects.driver_objects import driver_attribute
from cyborg.objects.driver_objects import driver_controlpath_id
from cyborg.objects.driver_objects import driver_deployable
from cyborg.objects.driver_objects import driver_device

LOG = logging.getLogger(__name__)


def _get_traits(vendor_id, product_id):
"""Generate traits for AICHIPs.
: param vendor_id: vendor_id of AICHIP, eg."1eff"
: param product_id: product_id of AICHIP, eg."0000".
Example AICHIP traits:
{traits:["OWNER_CYBORG", "CUSTOM_REBELLION_0000"]}
"""
traits = ["OWNER_CYBORG"]
# AICHIP trait
aichip_trait = "_".join(
(
"CUSTOM",
aichip_utils.VENDOR_MAPS.get(vendor_id, "").upper(),
product_id.upper(),
)
)
traits.append(aichip_trait)
return {"traits": traits}


def _generate_attribute_list(aichip):
attr_list = []
index = 0
for k, v in aichip.items():
if k == "rc":
driver_attr = driver_attribute.DriverAttribute()
driver_attr.key, driver_attr.value = k, v
attr_list.append(driver_attr)
if k == "traits":
values = aichip.get(k, [])
for val in values:
driver_attr = driver_attribute.DriverAttribute(
key="trait" + str(index), value=val
)
index = index + 1
attr_list.append(driver_attr)
return attr_list


def _generate_attach_handle(aichip, num=None):
driver_ah = driver_attach_handle.DriverAttachHandle()
driver_ah.in_use = False
if aichip["rc"] == "CUSTOM_AICHIP":
driver_ah.attach_type = constants.AH_TYPE_PCI
driver_ah.attach_info = utils.pci_str_to_json(aichip["devices"])
return driver_ah


def _generate_dep_list(aichip):
driver_dep = driver_deployable.DriverDeployable()
driver_dep.attribute_list = _generate_attribute_list(aichip)
driver_dep.attach_handle_list = []
# NOTE(wangzhh): The name of deployable should be unique, its format is
# under disscussion, may looks like
# <ComputeNodeName>_<NumaNodeName>_<CyborgName>_<NumInHost>
# NOTE(yumeng) Since Wallaby release, the deplpyable_name is named as
# <Compute_hostname>_<Device_address>
driver_dep.name = aichip.get("hostname", "") + "_" + aichip["devices"]
driver_dep.driver_name = aichip_utils.VENDOR_MAPS.get(
aichip["vendor_id"], ""
).upper()
# if it is AICHIP, num_accelerators = 1
if aichip["rc"] == constants.RESOURCES["AICHIP"]:
driver_dep.num_accelerators = 1
driver_dep.attach_handle_list = [_generate_attach_handle(aichip)]
return [driver_dep]


def _generate_controlpath_id(aichip):
driver_cpid = driver_controlpath_id.DriverControlPathID()
driver_cpid.cpid_type = "PCI"
driver_cpid.cpid_info = utils.pci_str_to_json(aichip["devices"])
return driver_cpid


def _generate_driver_device(aichip):
driver_device_obj = driver_device.DriverDevice()
driver_device_obj.vendor = aichip["vendor_id"]
driver_device_obj.model = aichip.get("model", "miss model info")
std_board_info = {
"product_id": aichip.get("product_id"),
"controller": aichip.get("controller"),
}
vendor_board_info = {
"vendor_info": aichip.get("vendor_info", "aichip_vb_info")
}
driver_device_obj.std_board_info = jsonutils.dumps(std_board_info)
driver_device_obj.vendor_board_info = jsonutils.dumps(vendor_board_info)
driver_device_obj.type = constants.DEVICE_AICHIP
driver_device_obj.stub = aichip.get("stub", False)
driver_device_obj.controlpath_id = _generate_controlpath_id(aichip)
driver_device_obj.deployable_list = _generate_dep_list(aichip)
return driver_device_obj


def _discover_aichips(vendor_id):
"""param: vendor_id=VENDOR_ID means only discover Rebellions AICHIP
on the host
"""
# discover aichip devices by "lspci"
aichip_list = []
aichips = aichip_utils.get_pci_devices(
aichip_utils.AICHIP_FLAGS, vendor_id
)
# report trait,rc and generate driver object
for aichip in aichips:
m = aichip_utils.AICHIP_INFO_PATTERN.match(aichip)
if m:
aichip_dict = m.groupdict()
# get hostname for deployable_name usage
aichip_dict["hostname"] = CONF.host
aichip_dict["rc"] = constants.RESOURCES["AICHIP"]
traits = _get_traits(
aichip_dict["vendor_id"], aichip_dict["product_id"]
)
aichip_dict.update(traits)
aichip_list.append(_generate_driver_device(aichip_dict))
return aichip_list


def discover(vendor_id):
devs = _discover_aichips(vendor_id)
return devs
3 changes: 3 additions & 0 deletions cyborg/api/controllers/v2/devices.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ class Device(base.APIBase):
This class enforces type checking and value constraints, and converts
between the internal object model and the API representation.
"""
id = wsme.wsattr(types.integer, readonly=True)
"""The internal ID (matches deployable.device_id)"""

uuid = types.uuid
"""The UUID of the device"""

Expand Down
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# Copyright 2025 Electronics and Telecommunications Research Institute.
#
# This software was supported by the Institute of Information & Communications
# Technology Planning & Evaluation(IITP) grant funded by the Korea government
# (MSIT) (No.RS-2025-02263869, Development of AI Semiconductor Cloud Platform
# Establishment and Optimization Technology)
#
# 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.

import json
from unittest import mock

from cyborg.accelerator.drivers.aichip.rebellions.driver import (
RebellionsAICHIPDriver
)
from cyborg.tests import base

rebellions_pci_res = (
'0000:00:0c.0 Processing accelerators [1200]: '
'Rebellions NPU [1eff:0000] (rev 01)\n'
'0000:00:0d.0 Processing accelerators [1200]: '
'Rebellions NPU [1eff:0000] (rev 01)\n',)


class TestRebellionsAICHIPDriver(base.TestCase):
"""Test Rebellions AICHIP driver."""

@mock.patch('cyborg.accelerator.drivers.aichip.utils.lspci_privileged',
return_value=rebellions_pci_res)
def test_discover(self, mock_pci):
self.set_defaults(host='host-192-168-32-195', debug=True)

rebellions_driver = RebellionsAICHIPDriver()
npu_list = rebellions_driver.discover()

self.assertEqual(2, len(npu_list))
for rebellions in npu_list:
self.assertEqual('AICHIP', rebellions.type)
self.assertEqual('PCI', rebellions.controlpath_id.cpid_type)
self.assertEqual(
json.loads('{"controller": "Processing accelerators", '
'"product_id": "0000"}'),
json.loads(rebellions.std_board_info))
self.assertEqual('1eff', rebellions.vendor)

self.assertEqual(
{"bus": "00", "device": "0c", "domain": "0000", "function": "0"},
json.loads(npu_list[0].controlpath_id.cpid_info))
self.assertEqual(
{"bus": "00", "device": "0d", "domain": "0000", "function": "0"},
json.loads(npu_list[1].controlpath_id.cpid_info))

self.assertEqual('host-192-168-32-195_0000:00:0c.0',
npu_list[0].deployable_list[0].name)
self.assertEqual('host-192-168-32-195_0000:00:0d.0',
npu_list[1].deployable_list[0].name)
2 changes: 1 addition & 1 deletion cyborg/tests/unit/accelerator/drivers/aichip/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class TestAICHIPDriver(base.TestCase):
def test_create(self):
# FuriosaAICHIPDriver.VENDOR == 'furiosa'
AICHIPDriver.create(FuriosaAICHIPDriver.VENDOR)
self.assertRaises(LookupError, AICHIPDriver.create, "rebellions")
self.assertRaises(LookupError, AICHIPDriver.create, "unknown_vendor")

def test_discover(self):
d = AICHIPDriver()
Expand Down
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ cyborg.accelerator.driver =
intel_nic_driver = cyborg.accelerator.drivers.nic.intel.driver:IntelNICDriver
inspur_nvme_ssd_driver = cyborg.accelerator.drivers.ssd.inspur.driver:InspurNVMeSSDDriver
furiosa_aichip_driver = cyborg.accelerator.drivers.aichip.furiosa.driver:FuriosaAICHIPDriver
rebellions_aichip_driver = cyborg.accelerator.drivers.aichip.rebellions.driver:RebellionsAICHIPDriver

oslo.config.opts =
cyborg = cyborg.conf.opts:list_opts
4 changes: 2 additions & 2 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ setenv =
VIRTUAL_ENV={envdir}
OS_TEST_PATH=cyborg/tests/unit
deps =
-c{env:TOX_CONSTRAINTS_FILE:https://releases.openstack.org/constraints/upper/2024.1}
-c{env:TOX_CONSTRAINTS_FILE:https://raw.githubusercontent.com/openkcloud/kcloud-requirements/refs/heads/kcloud/2024.1/upper-constraints.txt}
-r{toxinidir}/requirements.txt
-r{toxinidir}/test-requirements.txt

Expand Down Expand Up @@ -94,7 +94,7 @@ allowlist_externals =
sphinx-build
rm
deps =
-c{env:TOX_CONSTRAINTS_FILE:https://releases.openstack.org/constraints/upper/2024.1}
-c{env:TOX_CONSTRAINTS_FILE:https://raw.githubusercontent.com/openkcloud/kcloud-requirements/refs/heads/kcloud/2024.1/upper-constraints.txt}
-r{toxinidir}/doc/requirements.txt
commands =
rm -rf doc/build/html
Expand Down
Loading