Package tpu is an auto-generated package for the Cloud TPU API.
TPU API provides customers with access to Google TPU technology.
General documentation
For information that is relevant for all client libraries please reference https://pkg.go.dev/cloud.google.com/go#pkg-overview. Some information on this page includes:
- Authentication and Authorization
- Timeouts and Cancellation
- Testing against Client Libraries
- Debugging Client Libraries
- Inspecting errors
Example usage
To get started with this package, create a client.
// go get cloud.google.com/go/tpu/apiv1@latest ctx := context.Background() // This snippet has been automatically generated and should be regarded as a code template only. // It will require modifications to work: // - It may require correct/in-range values for request initialization. // - It may require specifying regional endpoints when creating the service client as shown in: // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options c, err := tpu.NewClient(ctx) if err != nil { // TODO: Handle error. } defer c.Close()
The client will use your default application credentials. Clients should be reused instead of created as needed. The methods of Client are safe for concurrent use by multiple goroutines. The returned client must be Closed when it is done being used.
Using the Client
The following is an example of making an API call with the newly created client, mentioned above.
req := &tpupb.CreateNodeRequest{ // TODO: Fill request struct fields. // See https://pkg.go.dev/cloud.google.com/go/tpu/apiv1/tpupb#CreateNodeRequest. } op, err := c.CreateNode(ctx, req) if err != nil { // TODO: Handle error. } resp, err := op.Wait(ctx) if err != nil { // TODO: Handle error. } // TODO: Use resp. _ = resp
Use of Context
The ctx passed to NewClient is used for authentication requests and for creating the underlying connection, but is not used for subsequent calls. Individual methods on the client use the ctx given to them.
To close the open connection, use the Close() method.
Functions
func DefaultAuthScopes
func DefaultAuthScopes() []string
DefaultAuthScopes reports the default set of authentication scopes to use with this package.
AcceleratorTypeIterator
type AcceleratorTypeIterator struct {
// Response is the raw response for the current page.
// It must be cast to the RPC response type.
// Calling Next() or InternalFetch() updates this value.
Response interface{}
// InternalFetch is for use by the Google Cloud Libraries only.
// It is not part of the stable interface of this package.
//
// InternalFetch returns results from a single call to the underlying RPC.
// The number of results is no greater than pageSize.
// If there are no more results, nextPageToken is empty and err is nil.
InternalFetch func(pageSize int, pageToken string) (results []*tpupb.AcceleratorType, nextPageToken string, err error)
// contains filtered or unexported fields
}
AcceleratorTypeIterator manages a stream of *tpupb.AcceleratorType.
func (*AcceleratorTypeIterator) All
func (it *AcceleratorTypeIterator) All() iter.Seq2[*tpupb.AcceleratorType, error]
All returns an iterator. If an error is returned by the iterator, the iterator will stop after that iteration.
func (*AcceleratorTypeIterator) Next
func (it *AcceleratorTypeIterator) Next() (*tpupb.AcceleratorType, error)
Next returns the next result. Its second return value is iterator.Done if there are no more results. Once Next returns Done, all subsequent calls will return Done.
func (*AcceleratorTypeIterator) PageInfo
func (it *AcceleratorTypeIterator) PageInfo() *iterator.PageInfo
PageInfo supports pagination. See the [google.golang.org/api/iterator] package for details.
CallOptions
type CallOptions struct {
ListNodes []gax.CallOption
GetNode []gax.CallOption
CreateNode []gax.CallOption
DeleteNode []gax.CallOption
ReimageNode []gax.CallOption
StopNode []gax.CallOption
StartNode []gax.CallOption
ListTensorFlowVersions []gax.CallOption
GetTensorFlowVersion []gax.CallOption
ListAcceleratorTypes []gax.CallOption
GetAcceleratorType []gax.CallOption
GetLocation []gax.CallOption
ListLocations []gax.CallOption
CancelOperation []gax.CallOption
DeleteOperation []gax.CallOption
GetOperation []gax.CallOption
ListOperations []gax.CallOption
}
CallOptions contains the retry settings for each method of Client.
Client
type Client struct {
// The call options for this service.
CallOptions *CallOptions
// LROClient is used internally to handle long-running operations.
// It is exposed so that its CallOptions can be modified if required.
// Users should not Close this client.
LROClient *lroauto.OperationsClient
// contains filtered or unexported fields
}
Client is a client for interacting with Cloud TPU API. Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
Manages TPU nodes and other resources
TPU API v1
func NewClient
NewClient creates a new tpu client based on gRPC. The returned client must be Closed when it is done being used to clean up its underlying connections.
Manages TPU nodes and other resources
TPU API v1
Example
package main
import (
"context"
tpu "cloud.google.com/go/tpu/apiv1"
)
func main() {
ctx := context.Background()
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in:
// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
c, err := tpu.NewClient(ctx)
if err != nil {
// TODO: Handle error.
}
defer c.Close()
// TODO: Use client.
_ = c
}
func (*Client) CancelOperation
func (c *Client) CancelOperation(ctx context.Context, req *longrunningpb.CancelOperationRequest, opts ...gax.CallOption) error
CancelOperation is a utility method from google.longrunning.Operations.
Example
package main
import (
"context"
longrunningpb "cloud.google.com/go/longrunning/autogen/longrunningpb"
tpu "cloud.google.com/go/tpu/apiv1"
)
func main() {
ctx := context.Background()
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in:
// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
c, err := tpu.NewClient(ctx)
if err != nil {
// TODO: Handle error.
}
defer c.Close()
req := &longrunningpb.CancelOperationRequest{
// TODO: Fill request struct fields.
// See https://pkg.go.dev/cloud.google.com/go/longrunning/autogen/longrunningpb#CancelOperationRequest.
}
err = c.CancelOperation(ctx, req)
if err != nil {
// TODO: Handle error.
}
}
func (*Client) Close
Close closes the connection to the API service. The user should invoke this when the client is no longer required.
func (*Client) Connection (deprecated)
func (c *Client) Connection() *grpc.ClientConn
Connection returns a connection to the API service.
Deprecated: Connections are now pooled so this method does not always return the same resource.
func (*Client) CreateNode
func (c *Client) CreateNode(ctx context.Context, req *tpupb.CreateNodeRequest, opts ...gax.CallOption) (*CreateNodeOperation, error)
CreateNode creates a node.
Example
package main
import (
"context"
tpu "cloud.google.com/go/tpu/apiv1"
tpupb "cloud.google.com/go/tpu/apiv1/tpupb"
)
func main() {
ctx := context.Background()
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in:
// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
c, err := tpu.NewClient(ctx)
if err != nil {
// TODO: Handle error.
}
defer c.Close()
req := &tpupb.CreateNodeRequest{
// TODO: Fill request struct fields.
// See https://pkg.go.dev/cloud.google.com/go/tpu/apiv1/tpupb#CreateNodeRequest.
}
op, err := c.CreateNode(ctx, req)
if err != nil {
// TODO: Handle error.
}
resp, err := op.Wait(ctx)
if err != nil {
// TODO: Handle error.
}
// TODO: Use resp.
_ = resp
}
func (*Client) CreateNodeOperation
func (c *Client) CreateNodeOperation(name string) *CreateNodeOperation
CreateNodeOperation returns a new CreateNodeOperation from a given name. The name must be that of a previously created CreateNodeOperation, possibly from a different process.
func (*Client) DeleteNode
func (c *Client) DeleteNode(ctx context.Context, req *tpupb.DeleteNodeRequest, opts ...gax.CallOption) (*DeleteNodeOperation, error)
DeleteNode deletes a node.
Example
package main
import (
"context"
tpu "cloud.google.com/go/tpu/apiv1"
tpupb "cloud.google.com/go/tpu/apiv1/tpupb"
)
func main() {
ctx := context.Background()
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in:
// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
c, err := tpu.NewClient(ctx)
if err != nil {
// TODO: Handle error.
}
defer c.Close()
req := &tpupb.DeleteNodeRequest{
// TODO: Fill request struct fields.
// See https://pkg.go.dev/cloud.google.com/go/tpu/apiv1/tpupb#DeleteNodeRequest.
}
op, err := c.DeleteNode(ctx, req)
if err != nil {
// TODO: Handle error.
}
resp, err := op.Wait(ctx)
if err != nil {
// TODO: Handle error.
}
// TODO: Use resp.
_ = resp
}
func (*Client) DeleteNodeOperation
func (c *Client) DeleteNodeOperation(name string) *DeleteNodeOperation
DeleteNodeOperation returns a new DeleteNodeOperation from a given name. The name must be that of a previously created DeleteNodeOperation, possibly from a different process.
func (*Client) DeleteOperation
func (c *Client) DeleteOperation(ctx context.Context, req *longrunningpb.DeleteOperationRequest, opts ...gax.CallOption) error
DeleteOperation is a utility method from google.longrunning.Operations.
Example
package main
import (
"context"
longrunningpb "cloud.google.com/go/longrunning/autogen/longrunningpb"
tpu "cloud.google.com/go/tpu/apiv1"
)
func main() {
ctx := context.Background()
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in:
// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
c, err := tpu.NewClient(ctx)
if err != nil {
// TODO: Handle error.
}
defer c.Close()
req := &longrunningpb.DeleteOperationRequest{
// TODO: Fill request struct fields.
// See https://pkg.go.dev/cloud.google.com/go/longrunning/autogen/longrunningpb#DeleteOperationRequest.
}
err = c.DeleteOperation(ctx, req)
if err != nil {
// TODO: Handle error.
}
}
func (*Client) GetAcceleratorType
func (c *