Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions samples/aliyun-poc-fc-gpu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ functions:
cmd: "npm start"
port: 9000
memory: 512
gpu: TESLA_8
timeout: 10
network:
vpc_id: vpc-2vc8v9btc8470laqui9bk
Expand Down
3 changes: 2 additions & 1 deletion src/parser/functionParser.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { FunctionDomain, FunctionRaw, NasStorageClassEnum } from '../types';
import { FunctionDomain, FunctionGpuEnum, FunctionRaw, NasStorageClassEnum } from '../types';
import { isEmpty } from 'lodash';

export const parseFunction = (functions?: {
Expand All @@ -13,6 +13,7 @@ export const parseFunction = (functions?: {
code: func.code,
container: func.container,
memory: func.memory,
gpu: func.gpu as FunctionGpuEnum,
timeout: func.timeout,
environment: func.environment,
log: func.log,
Expand Down
30 changes: 28 additions & 2 deletions src/stack/rosStack/function.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
import { ActionContext, FunctionDomain, NasStorageClassEnum, ServerlessIac } from '../../types';
import {
ActionContext,
FunctionDomain,
FunctionGpuEnum,
NasStorageClassEnum,
ServerlessIac,
} from '../../types';
import {
CODE_ZIP_SIZE_LIMIT,
encodeBase64ForRosId,
Expand All @@ -25,13 +31,25 @@ const storageClassMap = {
[NasStorageClassEnum.EXTREME_STANDARD]: { fileSystemType: 'extreme', storageType: 'standard' },
[NasStorageClassEnum.EXTREME_ADVANCE]: { fileSystemType: 'extreme', storageType: 'advance' },
};

const securityGroupRangeMap: { [key: string]: string } = {
TCP: '1/65535',
UDP: '1/65535',
ICMP: '-1/-1',
GRE: '-1/-1',
ALL: '-1/-1',
};
const gpuConfigMap = {
[FunctionGpuEnum.TESLA_8]: { gpuMemorySize: 8192, gpuType: 'fc.gpu.tesla.1' },
[FunctionGpuEnum.TESLA_12]: { gpuMemorySize: 12288, gpuType: 'fc.gpu.tesla.1' },
[FunctionGpuEnum.TESLA_16]: { gpuMemorySize: 16384, gpuType: 'fc.gpu.tesla.1' },
[FunctionGpuEnum.AMPERE_8]: { gpuMemorySize: 8192, gpuType: 'fc.gpu.ampere.1' },
[FunctionGpuEnum.AMPERE_12]: { gpuMemorySize: 12288, gpuType: 'fc.gpu.ampere.1' },
[FunctionGpuEnum.AMPERE_16]: { gpuMemorySize: 16384, gpuType: 'fc.gpu.ampere.1' },
[FunctionGpuEnum.AMPERE_24]: { gpuMemorySize: 24576, gpuType: 'fc.gpu.ampere.1' },
[FunctionGpuEnum.ADA_48]: { gpuMemorySize: 49152, gpuType: 'fc.gpu.ada.1' },
};

const transformSecurityRules = (rules: Array<string>, ruleType: 'INGRESS' | 'EGRESS') => {
return rules.map((rule) => {
const [protocol, cidrIp, portRange] = rule.split(':');
Expand All @@ -49,6 +67,13 @@ const transformSecurityRules = (rules: Array<string>, ruleType: 'INGRESS' | 'EGR
});
};

const transformGpuConfig = (gpu: FunctionDomain['gpu']) => {
if (!gpu) {
return undefined;
}

return gpuConfigMap[gpu];
};
export const resolveFunctions = (
scope: ros.Construct,
functions: Array<FunctionDomain> | undefined,
Expand Down Expand Up @@ -248,8 +273,9 @@ export const resolveFunctions = (
{
functionName: replaceReference(fnc.name, context),
memorySize: replaceReference(fnc.memory, context),
timeout: replaceReference(fnc.timeout, context),
diskSize: fnc.storage?.disk,
gpuConfig: transformGpuConfig(fnc.gpu),
timeout: replaceReference(fnc.timeout, context),
environmentVariables: replaceReference(fnc.environment, context),
logConfig,
vpcConfig,
Expand Down
13 changes: 13 additions & 0 deletions src/types/domains/function.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export type FunctionRaw = {
port: number;
};
memory: number;
gpu: string;
timeout: number;
log?: boolean;
environment?: {
Expand Down Expand Up @@ -48,6 +49,7 @@ export type FunctionDomain = {
port: number;
};
memory: number;
gpu?: FunctionGpuEnum;
timeout: number;
log?: boolean;
environment?: {
Expand Down Expand Up @@ -77,3 +79,14 @@ export enum NasStorageClassEnum {
EXTREME_STANDARD = 'EXTREME_STANDARD',
EXTREME_ADVANCE = 'EXTREME_ADVANCE',
}

export enum FunctionGpuEnum {
TESLA_8 = 'TESLA_8',
TESLA_12 = 'TESLA_12',
TESLA_16 = 'TESLA_16',
AMPERE_8 = 'AMPERE_8',
AMPERE_12 = 'AMPERE_12',
AMPERE_16 = 'AMPERE_16',
AMPERE_24 = 'AMPERE_24',
ADA_48 = 'ADA_48',
}
13 changes: 13 additions & 0 deletions src/validator/functionSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,19 @@ export const functionSchema = {
},
},
memory: { type: 'number' },
gpu: {
type: 'string',
enum: [
'TESLA_8',
'TESLA_12',
'TESLA_16',
'AMPERE_8',
'AMPERE_12',
'AMPERE_16',
'AMPERE_24',
'ADA_48',
],
},
timeout: { type: 'number' },
log: { type: 'boolean' },
environment: {
Expand Down
26 changes: 26 additions & 0 deletions tests/fixtures/deployFixture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -994,6 +994,32 @@ export const oneFcWithContainerRos = {
},
};

export const oneFcWithGpuIac = {
...oneFcIac,
functions: [
{
...((oneFcIac.functions && oneFcIac.functions[0]) ?? {}),
gpu: 'TESLA_8',
},
],
} as ServerlessIac;
export const oneFcWithGpuRos = {
...oneFcRos,
Resources: {
...oneFcRos.Resources,
hello_fn: {
...oneFcRos.Resources.hello_fn,
Properties: {
...oneFcRos.Resources.hello_fn.Properties,
GpuConfig: {
GpuMemorySize: 8192,
GpuType: 'fc.gpu.tesla.1',
},
},
},
},
};

export const largeCodeRos = {
Description: 'my-demo-service stack',
Mappings: {
Expand Down
20 changes: 17 additions & 3 deletions tests/stack/deploy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import {
oneFcRos,
oneFcWithContainerIac,
oneFcWithContainerRos,
oneFcWithGpuIac,
oneFcWithGpuRos,
oneFcWithStageRos,
referredServiceIac,
referredServiceRos,
Expand Down Expand Up @@ -217,7 +219,7 @@ describe('Unit tests for stack deployment', () => {
});
});

describe('unit test for function nas attachment', () => {
describe('unit test for serverless Gpu', () => {
it('should deploy function with nas when nas field is provided', async () => {
const stackName = 'my-demo-stack-with-nas';
mockedRosStackDeploy.mockResolvedValue(stackName);
Expand All @@ -231,9 +233,7 @@ describe('Unit tests for stack deployment', () => {
{ stackName },
]);
});
});

describe('unit test for function with container', () => {
it('should deploy function with container when container field is provided', async () => {
const stackName = 'my-demo-stack-with-container';
mockedRosStackDeploy.mockResolvedValue(stackName);
Expand All @@ -247,5 +247,19 @@ describe('Unit tests for stack deployment', () => {
{ stackName },
]);
});

it('should deploy function with gpu configured', async () => {
const stackName = 'my-demo-stack-with-gpu';
mockedRosStackDeploy.mockResolvedValue(stackName);

await deployStack(stackName, oneFcWithGpuIac, { stackName } as ActionContext);

expect(mockedRosStackDeploy).toHaveBeenCalledTimes(2);
expect(mockedRosStackDeploy.mock.calls[1]).toEqual([
stackName,
oneFcWithGpuRos,
{ stackName },
]);
});
});
});