/*
 * Copyright (C) 2023 Amazon.com, Inc. or its affiliates.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import * as ec2 from 'aws-cdk-lib/aws-ec2';
import * as assets from 'aws-cdk-lib/aws-ecr-assets';
import * as ecs from 'aws-cdk-lib/aws-ecs';

/**
 * @returns the GPU configuration for running the container.
 */
export const getGpuConfiguration = () => {
  const instance = {
    instanceType: ec2.InstanceType.of(
      ec2.InstanceClass.G5,
      ec2.InstanceSize.XLARGE
    ),
    gpuCount: 1,
    cpuLimit: 4096,
    memoryLimitMiB: 15360
  };

  return ({
    ...instance,
    container: {
      dockerFile: 'Dockerfile',
      platform: assets.Platform.LINUX_AMD64
    },
    machineImage: ecs.EcsOptimizedImage.amazonLinux2(
      ecs.AmiHardwareType.GPU
    )
  });
};
