fix: for --gpus device support
This commit is contained in:
@@ -91,7 +91,7 @@ function next_queuable(string $server_id, string $application_id): bool
|
||||
$server = Server::find($server_id);
|
||||
$concurrent_builds = $server->settings->concurrent_builds;
|
||||
|
||||
ray("serverId:{$server->id}", "concurrentBuilds:{$concurrent_builds}", "deployments:{$deployments->count()}", "sameApplicationDeployments:{$same_application_deployments->count()}")->green();
|
||||
// ray("serverId:{$server->id}", "concurrentBuilds:{$concurrent_builds}", "deployments:{$deployments->count()}", "sameApplicationDeployments:{$same_application_deployments->count()}")->green();
|
||||
|
||||
if ($deployments->count() > $concurrent_builds) {
|
||||
return false;
|
||||
|
@@ -667,7 +667,6 @@ function convertDockerRunToCompose(?string $custom_docker_run_options = null)
|
||||
'--ulimit',
|
||||
'--device',
|
||||
'--shm-size',
|
||||
'--gpus',
|
||||
]);
|
||||
$mapping = collect([
|
||||
'--cap-add' => 'cap_add',
|
||||
@@ -684,6 +683,13 @@ function convertDockerRunToCompose(?string $custom_docker_run_options = null)
|
||||
]);
|
||||
foreach ($matches as $match) {
|
||||
$option = $match[1];
|
||||
if ($option === '--gpus') {
|
||||
$regexForParsingDeviceIds = '/device=([0-9A-Za-z-,]+)/';
|
||||
preg_match($regexForParsingDeviceIds, $custom_docker_run_options, $device_matches);
|
||||
$value = $device_matches[1] ?? 'all';
|
||||
$options[$option][] = $value;
|
||||
$options[$option] = array_unique($options[$option]);
|
||||
}
|
||||
if (isset($match[2]) && $match[2] !== '') {
|
||||
$value = $match[2];
|
||||
$options[$option][] = $value;
|
||||
@@ -696,7 +702,6 @@ function convertDockerRunToCompose(?string $custom_docker_run_options = null)
|
||||
$options = collect($options);
|
||||
// Easily get mappings from https://github.com/composerize/composerize/blob/master/packages/composerize/src/mappings.js
|
||||
foreach ($options as $option => $value) {
|
||||
// ray($option,$value);
|
||||
if (! data_get($mapping, $option)) {
|
||||
continue;
|
||||
}
|
||||
@@ -725,6 +730,28 @@ function convertDockerRunToCompose(?string $custom_docker_run_options = null)
|
||||
if (! is_null($value) && is_array($value) && count($value) > 0) {
|
||||
$compose_options->put($mapping[$option], $value[0]);
|
||||
}
|
||||
} elseif ($option === '--gpus') {
|
||||
$payload = [
|
||||
'driver' => 'nvidia',
|
||||
'capabilities' => ['gpu'],
|
||||
];
|
||||
if (! is_null($value) && is_array($value) && count($value) > 0) {
|
||||
if (str($value[0]) != 'all') {
|
||||
if (str($value[0])->contains(',')) {
|
||||
$payload['device_ids'] = str($value[0])->explode(',')->toArray();
|
||||
} else {
|
||||
$payload['device_ids'] = [$value[0]];
|
||||
}
|
||||
}
|
||||
}
|
||||
ray($payload);
|
||||
$compose_options->put('deploy', [
|
||||
'resources' => [
|
||||
'reservations' => [
|
||||
'devices' => [$payload],
|
||||
],
|
||||
],
|
||||
]);
|
||||
} else {
|
||||
if ($list_options->contains($option)) {
|
||||
if ($compose_options->has($mapping[$option])) {
|
||||
|
@@ -38,19 +38,61 @@ test('ConvertUlimit', function () {
|
||||
],
|
||||
]);
|
||||
});
|
||||
test('ConvertGpusWithGpuId', function () {
|
||||
$input = '--gpus "device=GPU-0000000000000000"';
|
||||
$output = convertDockerRunToCompose($input);
|
||||
expect($output)->toBe([
|
||||
'deploy' => [
|
||||
'resources' => [
|
||||
'reservations' => [
|
||||
'devices' => [
|
||||
[
|
||||
'driver' => 'nvidia',
|
||||
'capabilities' => ['gpu'],
|
||||
'device_ids' => ['GPU-0000000000000000'],
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
]);
|
||||
});
|
||||
|
||||
test('ConvertGpus', function () {
|
||||
$input = '--gpus all';
|
||||
$output = convertDockerRunToCompose($input);
|
||||
expect($output)->toBe([
|
||||
'gpus' => 'all',
|
||||
'deploy' => [
|
||||
'resources' => [
|
||||
'reservations' => [
|
||||
'devices' => [
|
||||
[
|
||||
'driver' => 'nvidia',
|
||||
'capabilities' => ['gpu'],
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
]);
|
||||
});
|
||||
|
||||
test('ConvertGpusWithQuotes', function () {
|
||||
$input = '--gpus "device=0"';
|
||||
$input = '--gpus "device=0,1"';
|
||||
$output = convertDockerRunToCompose($input);
|
||||
expect($output)->toBe([
|
||||
'gpus' => '"device=0"',
|
||||
'deploy' => [
|
||||
'resources' => [
|
||||
'reservations' => [
|
||||
'devices' => [
|
||||
[
|
||||
'driver' => 'nvidia',
|
||||
'capabilities' => ['gpu'],
|
||||
'device_ids' => ['0', '1'],
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
]);
|
||||
});
|
||||
|
Reference in New Issue
Block a user