MCPcopy Create free account
hub / github.com/GoogleCloudPlatform/nodejs-docs-samples / main

Function main

batch/create/create_gpu_job.js:19–119  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

17'use strict';
18
19async function main() {
20 // [START batch_create_gpu_job]
21 // Imports the Batch library
22 const batchLib = require('@google-cloud/batch');
23 const batch = batchLib.protos.google.cloud.batch.v1;
24
25 // Instantiates a client
26 const batchClient = new batchLib.v1.BatchServiceClient();
27
28 /**
29 * TODO(developer): Update these variables before running the sample.
30 */
31 // Project ID or project number of the Google Cloud project you want to use.
32 const projectId = await batchClient.getProjectId();
33 // Name of the region you want to use to run the job. Regions that are
34 // available for Batch are listed on: https://cloud.google.com/batch/docs/get-started#locations
35 const region = 'europe-central2';
36 // The name of the job that will be created.
37 // It needs to be unique for each project and region pair.
38 const jobName = 'batch-gpu-job';
39 // The GPU type. You can view a list of the available GPU types
40 // by using the `gcloud compute accelerator-types list` command.
41 const gpuType = 'nvidia-l4';
42 // The number of GPUs of the specified type.
43 const gpuCount = 1;
44 // Optional. When set to true, Batch fetches the drivers required for the GPU type
45 // that you specify in the policy field from a third-party location,
46 // and Batch installs them on your behalf. If you set this field to false (default),
47 // you need to install GPU drivers manually to use any GPUs for this job.
48 const installGpuDrivers = false;
49 // Accelerator-optimized machine types are available to Batch jobs. See the list
50 // of available types on: https://cloud.google.com/compute/docs/accelerator-optimized-machines
51 const machineType = 'g2-standard-4';
52
53 // Define what will be done as part of the job.
54 const runnable = new batch.Runnable({
55 script: new batch.Runnable.Script({
56 commands: ['-c', 'echo Hello world! This is task ${BATCH_TASK_INDEX}.'],
57 }),
58 });
59
60 const task = new batch.TaskSpec({
61 runnables: [runnable],
62 maxRetryCount: 2,
63 maxRunDuration: {seconds: 3600},
64 });
65
66 // Tasks are grouped inside a job using TaskGroups.
67 const group = new batch.TaskGroup({
68 taskCount: 3,
69 taskSpec: task,
70 });
71
72 // Policies are used to define on what kind of virtual machines the tasks will run on.
73 // In this case, we tell the system to use "g2-standard-4" machine type.
74 // Read more about machine types here: https://cloud.google.com/compute/docs/machine-types
75 const instancePolicy = new batch.AllocationPolicy.InstancePolicy({
76 machineType,

Callers 1

create_gpu_job.jsFile · 0.70

Calls 2

getProjectIdMethod · 0.80
callCreateBatchGPUJobFunction · 0.70

Tested by

no test coverage detected