Skip to content

Commit

Permalink
Adding alias to gpu resource name
Browse files Browse the repository at this point in the history
  • Loading branch information
visheshtanksale committed May 1, 2024
1 parent 0de8b96 commit bd72ec5
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 42 deletions.
75 changes: 40 additions & 35 deletions cmd/main.go
Original file line number Diff line number Diff line change
@@ -1,35 +1,40 @@
/*
* Copyright (c) 2019, NVIDIA CORPORATION. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of NVIDIA CORPORATION nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

package main

import "kubevirt-gpu-device-plugin/pkg/device_plugin"

func main() {
device_plugin.InitiateDevicePlugin()
}
/*
* Copyright (c) 2019, NVIDIA CORPORATION. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of NVIDIA CORPORATION nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

package main

import (
"kubevirt-gpu-device-plugin/pkg/device_plugin"
"os"
)

func main() {
device_plugin.PGPUAlias = os.Getenv("P_GPU_ALIAS")
device_plugin.VGPUAlias = os.Getenv("V_GPU_ALIAS")
device_plugin.InitiateDevicePlugin()
}
26 changes: 19 additions & 7 deletions pkg/device_plugin/device_plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ var readVgpuIDFromFile = readVgpuIDFromFileFunc
var readGpuIDForVgpu = readGpuIDForVgpuFunc
var startVgpuDevicePlugin = startVgpuDevicePluginFunc
var stop = make(chan struct{})
var PGPUAlias string
var VGPUAlias string

func InitiateDevicePlugin() {
//Identifies GPUs and represents it in appropriate structures
Expand Down Expand Up @@ -101,10 +103,15 @@ func createDevicePlugins() {
Health: pluginapi.Healthy,
})
}
deviceName := getDeviceName(k)
if deviceName == "" {
log.Printf("Error: Could not find device name for device id: %s", k)
deviceName = k
deviceName := ""
if PGPUAlias != "" {
deviceName = PGPUAlias
} else {
deviceName = getDeviceName(k)
if deviceName == "" {
log.Printf("Error: Could not find device name for device id: %s", k)
deviceName = k
}
}
log.Printf("DP Name %s", deviceName)
dp := NewGenericDevicePlugin(deviceName, "/sys/kernel/iommu_groups/", devs)
Expand All @@ -124,9 +131,14 @@ func createDevicePlugins() {
Health: pluginapi.Healthy,
})
}
deviceName := getDeviceName(k)
if deviceName == "" {
deviceName = k
deviceName := ""
if VGPUAlias != "" {
deviceName = VGPUAlias
} else {
deviceName = getDeviceName(k)
if deviceName == "" {
deviceName = k
}
}
log.Printf("DP Name %s", deviceName)
dp := NewGenericVGpuDevicePlugin(deviceName, vGpuBasePath, devs)
Expand Down

0 comments on commit bd72ec5

Please sign in to comment.