Skip to content

Commit 221bdab

Browse files
authored
A support for GPU (#1866)
1 parent 69f0bab commit 221bdab

3 files changed

Lines changed: 30 additions & 0 deletions

File tree

src/argv.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,10 @@ export class Argv {
388388
return this.map.get("containerEmulate") ?? null;
389389
}
390390

391+
get gpus (): string | null {
392+
return this.map.get("gpus") ?? null;
393+
}
394+
391395
get concurrency (): number | null {
392396
const concurrency = this.map.get("concurrency");
393397
if (!concurrency) return null;

src/index.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,11 @@ process.on("SIGUSR2", async () => {
366366
description: "The name, without the architecture, of a gitlab hosted runner to emulate. See here: https://docs.gitlab.com/ee/ci/runners/hosted_runners/linux.html#machine-types-available-for-linux---x86-64",
367367
choices: GitlabRunnerPresetValues,
368368
})
369+
.option("gpus", {
370+
type: "string",
371+
description: "A list of GPU indexes or 'all'",
372+
requiresArg: true,
373+
})
369374
.option("color", {
370375
requiresArg: false,
371376
default: true,

src/job.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -986,6 +986,10 @@ If you know what you're doing and would like to suppress this warning, use one o
986986
dockerCmd += `--cpus=${cpuConfig} `;
987987
}
988988

989+
if (this.gpus) {
990+
dockerCmd += `--gpus ${this.gpus} --ipc=host --ulimit memlock=-1 --ulimit stack=67108864 `;
991+
}
992+
989993
// host and none networks have to be specified using --network, since they cannot be used with
990994
// `docker network connect`.
991995
for (const network of this.argv.network) {
@@ -1219,6 +1223,19 @@ If you know what you're doing and would like to suppress this warning, use one o
12191223
return image.entrypoint;
12201224
}
12211225

1226+
get gpus (): string | null {
1227+
if (this.argv.gpus) {
1228+
return this.argv.gpus;
1229+
} else if ("tags" in this.jobData) {
1230+
for (const tag of this.jobData["tags"]) {
1231+
if (tag.match(/^(.*-)?gpu(-.*)?$/)) {
1232+
return "all";
1233+
}
1234+
}
1235+
}
1236+
return null;
1237+
}
1238+
12221239
private async validateCiDependencyProxyServerAuthentication (imageName: string) {
12231240
const CI_DEPENDENCY_PROXY_SERVER = this._variables["CI_DEPENDENCY_PROXY_SERVER"];
12241241
if (!imageName.startsWith(CI_DEPENDENCY_PROXY_SERVER)) {
@@ -1579,6 +1596,10 @@ If you know what you're doing and would like to suppress this warning, use one o
15791596
dockerCmd += `--shm-size=${this.argv.shmSize} `;
15801597
}
15811598

1599+
if (this.gpus) {
1600+
dockerCmd += `--gpus ${this.gpus} --ipc=host --ulimit memlock=-1 --ulimit stack=67108864 `;
1601+
}
1602+
15821603
for (const volume of this.argv.volume) {
15831604
dockerCmd += `--volume ${volume} `;
15841605
}

0 commit comments

Comments
 (0)