| 1 | import * as GCP from "@/GCP"; |
| 2 | import * as Effect from "effect/Effect"; |
| 3 | import { serveProbes } from "../../bindingHost.ts"; |
| 4 | |
| 5 | export const Trainer = GCP.TPU.Node("Trainer", { |
| 6 | location: "us-central1-c", |
| 7 | acceleratorType: "v2-8", |
| 8 | runtimeVersion: "tpu-ubuntu2204-base", |
| 9 | }); |
| 10 | |
| 11 | export const QueuedTrainer = GCP.TPU.QueuedResource("QueuedTrainer", { |
| 12 | location: "us-central1-c", |
| 13 | nodeSpec: [ |
| 14 | { |
| 15 | node: { |
| 16 | acceleratorType: "v2-8", |
| 17 | runtimeVersion: "tpu-ubuntu2204-base", |
| 18 | }, |
| 19 | }, |
| 20 | ], |
| 21 | }); |
| 22 | |
| 23 | /** |
| 24 | * Effect-native Cloud Run service exercising every Cloud TPU binding as |
| 25 | * its own runtime service account. Deployed from |
| 26 | * {@link ../Bindings.test.ts}. |
| 27 | */ |
| 28 | export default class TpuBindingsHost extends GCP.Function<TpuBindingsHost>()( |
| 29 | "TpuBindingsHost", |
| 30 | { main: import.meta.url, invokerIamDisabled: true }, |
| 31 | Effect.gen(function* () { |
| 32 | const getNode = yield* GCP.TPU.GetNode(Trainer); |
| 33 | const getQueuedResource = yield* GCP.TPU.GetQueuedResource(QueuedTrainer); |
| 34 | |
| 35 | return { |
| 36 | fetch: serveProbes({ |
| 37 | getNode: getNode().pipe( |
| 38 | Effect.map((node) => ({ |
| 39 | name: node.name, |
| 40 | acceleratorType: node.acceleratorType, |
| 41 | })), |
| 42 | ), |
| 43 | getQueuedResource: getQueuedResource().pipe( |
| 44 | Effect.map((resource) => ({ name: resource.name })), |
| 45 | ), |
| 46 | }), |
| 47 | }; |
| 48 | }).pipe( |
| 49 | Effect.provide(GCP.TPU.GetNodeHttp), |
| 50 | Effect.provide(GCP.TPU.GetQueuedResourceHttp), |
| 51 | ), |
| 52 | ) {} |