mirror of
https://github.com/Ascend/ascend-docker-runtime.git
synced 2025-10-19 06:54:40 +08:00
Match-id-36b288e72058be93e6862f00fb37f3456ff5196f
This commit is contained in:
@@ -10,7 +10,6 @@ import "C"
|
||||
import (
|
||||
"fmt"
|
||||
"math"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -22,6 +21,8 @@ const (
|
||||
|
||||
// maxErrorCodeCount is the max number of error code
|
||||
hiAIMaxCardNum = 16
|
||||
coreNumLen = 32
|
||||
deviceNum = 4294967295 // vfg_id表示指定虚拟设备所属的虚拟分组ID,默认自动分配,默认值为0xFFFFFFFF,转换成10进制为4294967295。
|
||||
)
|
||||
|
||||
// NpuWorker Dcmi worker
|
||||
@@ -107,9 +108,20 @@ func GetDeviceLogicID(cardID, deviceID int32) (int32, error) {
|
||||
func (w *NpuWorker) CreateVDevice(cardID, deviceID int32, coreNum string) (int32, error) {
|
||||
var createInfo C.struct_dcmi_create_vdev_out
|
||||
createInfo.vdev_id = C.uint(math.MaxUint32)
|
||||
coreTemplate := C.CString(coreNum)
|
||||
defer C.free(unsafe.Pointer(coreTemplate))
|
||||
err := C.dcmi_create_vdevice(C.int(cardID), C.int(deviceID), C.int(-1), coreTemplate, &createInfo)
|
||||
var deviceCreateStr C.struct_dcmi_create_vdev_res_stru
|
||||
deviceCreateStr = C.struct_dcmi_create_vdev_res_stru{
|
||||
vdev_id: C.uint(deviceNum),
|
||||
vfg_id: C.uint(deviceNum),
|
||||
}
|
||||
deviceCreateStrArr := [coreNumLen]C.char{0}
|
||||
for i := 0; i < len(coreNum); i++ {
|
||||
if i >= coreNumLen {
|
||||
return math.MaxInt32, fmt.Errorf("wrong template")
|
||||
}
|
||||
deviceCreateStrArr[i] = C.char(coreNum[i])
|
||||
}
|
||||
deviceCreateStr.template_name = deviceCreateStrArr
|
||||
err := C.dcmi_create_vdevice(C.int(cardID), C.int(deviceID), &deviceCreateStr, &createInfo)
|
||||
if err != 0 {
|
||||
errInfo := fmt.Errorf("create virtual device failed, error code: %d", int32(err))
|
||||
return math.MaxInt32, errInfo
|
||||
|
@@ -9,6 +9,7 @@
|
||||
#include <dlfcn.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
@@ -30,6 +31,12 @@ struct dcmi_create_vdev_out {
|
||||
unsigned int vfg_id;
|
||||
unsigned char reserved[DCMI_VDEV_FOR_RESERVE];
|
||||
};
|
||||
struct dcmi_create_vdev_res_stru {
|
||||
unsigned int vdev_id;
|
||||
unsigned int vfg_id;
|
||||
char template_name[32];
|
||||
unsigned char reserved[64];
|
||||
};
|
||||
|
||||
// dcmi
|
||||
int (*dcmi_init_func)();
|
||||
@@ -56,12 +63,14 @@ int dcmi_get_device_logic_id(int *device_logic_id, int card_id, int device_id)
|
||||
CALL_FUNC(dcmi_get_device_logic_id, device_logic_id, card_id, device_id);
|
||||
}
|
||||
|
||||
int (*dcmi_create_vdevice_func)(int card_id, int device_id, int vdev_id, const char *template_name,
|
||||
int (*dcmi_create_vdevice_func)(int card_id, int device_id,
|
||||
struct dcmi_create_vdev_res_stru *vdev,
|
||||
struct dcmi_create_vdev_out *out);
|
||||
int dcmi_create_vdevice(int card_id, int device_id, int vdev_id, const char *template_name,
|
||||
int dcmi_create_vdevice(int card_id, int device_id,
|
||||
struct dcmi_create_vdev_res_stru *vdev,
|
||||
struct dcmi_create_vdev_out *out)
|
||||
{
|
||||
CALL_FUNC(dcmi_create_vdevice, card_id, device_id, vdev_id, template_name, out);
|
||||
CALL_FUNC(dcmi_create_vdevice, card_id, device_id, vdev, out);
|
||||
}
|
||||
|
||||
int (*dcmi_set_destroy_vdevice_func)(int card_id, int device_id, unsigned int VDevid);
|
||||
|
Reference in New Issue
Block a user