-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15 from peiniliu/dev
Add GPU Numbers Support
- Loading branch information
Showing
15 changed files
with
627 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
## Config the volcano device plugin binary | ||
|
||
The volcano device plugin has a number of options that can be configured. These options can be configured as command line flags, environment variables, or via a config file when launching the device plugin. The following section explains these configurations. | ||
|
||
### As command line flags or envvars | ||
|
||
| Flag | Envvar | Default Value | | ||
|--------------------------|-------------------------|-----------------| | ||
| `--gpu-strategy` | `$GPU_STRATEGY` | `"share"` | | ||
| `--config-file` | `$CONFIG_FILE` | `""` | | ||
|
||
when starting volcano-device-plugin.yml, users can specify these parameters by adding args to the container 'volcano-device-plugin'. | ||
For example: | ||
- args: ["--gpu-strategy=number"] will let device plugin using the gpu-number strategy | ||
|
||
### As a configuration file | ||
``` | ||
version: v1 | ||
flags: | ||
GPUStrategy: "number" | ||
``` | ||
|
||
### Configuration Option Details | ||
**`GPU_STRATEGY`**: | ||
the desired strategy for exposing GPU devices | ||
|
||
`[number | share ] (default 'share')` | ||
|
||
The `GPU_STRATEGY` option configures the daemonset to be able to expose | ||
on GPU devices in numbers or sharing mode. More information on what | ||
these strategies are and how to use it in Volcano can be found in Volcano scheduler. | ||
|
||
**`CONFIG_FILE`**: | ||
point the plugin at a configuration file instead of relying on command line | ||
flags or environment variables | ||
|
||
`(default '')` | ||
|
||
The order of precedence for setting each option is (1) command line flag, (2) | ||
environment variable, (3) configuration file. In this way, one could use a | ||
pre-defined configuration file, but then override the values set in it at | ||
launch time. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
/* | ||
Copyright 2022 The Volcano Authors. | ||
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. | ||
*/ | ||
|
||
package apis | ||
|
||
import ( | ||
"fmt" | ||
"io" | ||
"log" | ||
"os" | ||
|
||
cli "github.com/urfave/cli/v2" | ||
"sigs.k8s.io/yaml" | ||
) | ||
|
||
// Version indicates the version of the 'Config' struct used to hold configuration information. | ||
const Version = "v1beta1" | ||
|
||
// Config is a versioned struct used to hold configuration information. | ||
type Config struct { | ||
Version string `json:"version" yaml:"version"` | ||
Flags Flags `json:"flags,omitempty" yaml:"flags,omitempty"` | ||
} | ||
|
||
// NewConfig builds out a Config struct from a config file (or command line flags). | ||
// The data stored in the config will be populated in order of precedence from | ||
// (1) command line, (2) environment variable, (3) config file. | ||
func NewConfig(c *cli.Context, flags []cli.Flag) (*Config, error) { | ||
config := &Config{ | ||
Version: Version, | ||
} | ||
|
||
log.Println(c.String("gpu-strategy")) | ||
|
||
configFile := c.String("config-file") | ||
if configFile != "" { | ||
var err error | ||
config, err = parseConfig(configFile) | ||
if err != nil { | ||
return nil, fmt.Errorf("unable to parse config file: %v", err) | ||
} | ||
} | ||
|
||
config.Flags.CommandLineFlags = NewCommandLineFlags(c) | ||
|
||
return config, nil | ||
} | ||
|
||
// parseConfig parses a config file as either YAML of JSON and unmarshals it into a Config struct. | ||
func parseConfig(configFile string) (*Config, error) { | ||
reader, err := os.Open(configFile) | ||
if err != nil { | ||
return nil, fmt.Errorf("error opening config file: %v", err) | ||
} | ||
defer reader.Close() | ||
|
||
config, err := parseConfigFrom(reader) | ||
if err != nil { | ||
return nil, fmt.Errorf("error parsing config file: %v", err) | ||
} | ||
|
||
return config, nil | ||
} | ||
|
||
func parseConfigFrom(reader io.Reader) (*Config, error) { | ||
var err error | ||
var configYaml []byte | ||
|
||
configYaml, err = io.ReadAll(reader) | ||
if err != nil { | ||
return nil, fmt.Errorf("read error: %v", err) | ||
} | ||
|
||
var config Config | ||
err = yaml.Unmarshal(configYaml, &config) | ||
if err != nil { | ||
return nil, fmt.Errorf("unmarshal error: %v", err) | ||
} | ||
|
||
if config.Version == "" { | ||
config.Version = Version | ||
} | ||
|
||
if config.Version != Version { | ||
return nil, fmt.Errorf("unknown version: %v", config.Version) | ||
} | ||
|
||
return &config, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
Copyright 2022 The Volcano Authors. | ||
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. | ||
*/ | ||
|
||
package apis | ||
|
||
import ( | ||
cli "github.com/urfave/cli/v2" | ||
) | ||
|
||
// Flags holds the full list of flags used to configure the device plugin and GFD. | ||
type Flags struct { | ||
*CommandLineFlags | ||
} | ||
|
||
// CommandLineFlags holds the list of command line flags used to configure the device plugin and GFD. | ||
type CommandLineFlags struct { | ||
GPUStrategy string `json:"GPUStrategy" yaml:"GPUStrategy"` | ||
} | ||
|
||
func NewCommandLineFlags(c *cli.Context) *CommandLineFlags { | ||
return &CommandLineFlags{ | ||
GPUStrategy: c.String("gpu-strategy"), | ||
} | ||
} |
Oops, something went wrong.