├── NOTICE
├── README.md
├── LICENSE
└── machinelearning.template
/NOTICE:
--------------------------------------------------------------------------------
1 | Copyright 2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2 |
3 | Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with the License. A copy of the License is located at
4 |
5 | http://aws.amazon.com/apache2.0/
6 |
7 | or in the "license" file accompanying this file. This file 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.
8 |
9 | ecs-machine-learning
10 | Copyright 2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
11 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 | # Orchestrating GPU-Accelerated Workloads on Amazon ECS
3 |
4 | ## Background
5 | AWS Solutions Architects are seeing an emerging type of application for ECS: GPU-accelerated workloads, or, more specifically, workloads that need to leverage large amounts of GPUs across many nodes. For example, at Amazon.com, the Amazon Personalization Team runs significant Machine Learning workloads that leverage many GPUs on Amazon ECS. Let’s take a look at how ECS enables GPU workloads.
6 |
7 | ## Solution
8 |
9 | In order to run GPU-enabled work on an ECS cluster, a Docker image configured with [Nvidia CUDA drivers][1], which allow the container to communicate with the GPU hardware, is built and stored in EC2 Container Registry. An [ECS Task Definition][2] is used to point to the container image in ECR and specify configuration for the container at runtime, like how much CPU and memory each container should use, the command to run inside the container, if a data volume should be mounted in the container, where the source dataset lives in S3, and so on.
10 |
11 | Once the ECS Tasks are run, the ECS [scheduler][3] finds a suitable place to run the containers by identifying an instance in the cluster with available resources. As shown in the below architecture diagram, ECS can place containers into the cluster of GPU instances (“GPU slaves” in the diagram)
12 |
13 |
14 |
15 | ## Deploying the architecture
16 |
17 | In this template, we spin up an ECS Cluster with a single GPU instance in an autoscaling group. You can, however, adjust the ASG desired capacity to run a larger cluster if you’d like. The instance is configured with all of the necessary software, like Nvidia drivers, that DSSTNE requires for interaction with the underlying GPU hardware. We also install some development tools, like Make and GCC, so that we can compile the DSSTNE library at boot time. We then build a Docker container with the DSSTNE library packaged up and upload it to EC2 Container Registry. We grab the URL of the resulting container image in ECR and build an ECS Task Definition that points to the container.
18 |
19 | Once the CloudFormation template completes, take a look at the “Outputs” tab to get an idea of where to look for your new resources.
20 |
21 | ### Prerequisistes
22 |
23 | #### Network configuration
24 | The instances launched will need to have access to the internet hence either be in a public subnet and provided a public IP or in a private subnet with acess to a NAT gateway.
25 |
26 | #### Accepting terms
27 |
28 | 0. Accept AWS Marketplace terms for Amazon Linux AMI with NVIDIA GRID GPU Driver by going to the [MarketPlace page][9]
29 |
30 | 1. Click Continue on the right.
31 |
32 | 2. Click on the Manual Launch tab and click on the Accept Software Terms button.
33 |
34 | 3. Wait for an email confirmation that your marketplace subscription is active.
35 |
36 | ### Launch the stack
37 |
38 | 2. Choose **Launch Stack** to launch the template in the us-east-1 region in your account:
39 | [](https://console.aws.amazon.com/cloudformation/home?region=us-east-1#/stacks/new?stackName=ecs-machine-learning&templateURL=https://s3.amazonaws.com/ecs-machine-learning/machinelearning.template)
40 |
41 | (The template will build a DSSTNE container on the ECS cluster instance. Note this can take up to 25 minutes and the CloudFormation stack will not report completion until the entire build process is done.)
42 |
43 | 2. Give a Stack Name and select your preferred key name. If you do not have a key available, see [Amazon EC2 Key Pairs][4].
44 |
45 | ### Run the model
46 |
47 | 3. Find the name of the DSSTNE ECS Task Definition in CloudFormation stack outputs. It will start with "arn:aws[...]" and contain the CloudFormation template name right after "task-defintion/".
48 |
49 | 4. Go to the [ECS Console][10], click on Task Definitions (left column) and find the one you spotted in the step above.
50 |
51 | 5. Tick the one revision you see. Click on the Actions drop-down menu and hit Run task. Make sure to select the ECS Cluster that was brought up by the CloudFormation template. By running this task, you are essentially running the DSSTNE sample modeling as described on the [amazon-dsstne GitHub page][5].
52 |
53 | 6. You can easily check that the GPU is being used by logging to the EC2 instance and running `watch -n1 nvidia-smi`
54 |
55 | ### Collect predictions
56 |
57 | 5. You should be able to find the name of the relevant [CloudWatch][7] Logs Group in CloudFormation stack outputs
58 |
59 | 6. Look at the task logs for details and output from the task run and location of results file in S3
60 |
61 | 8. Navigate to this S3 bucket via the [S3 Console][11]. This is where you will be able to access the results file and confirm that this GPU-enabled Machine Learning run was successful.
62 |
63 | ### Bonus activities
64 | - Bonus activity #1: Repeat step 2 in the *Run the model* section, but change the config URL and training command by overriding the task definition environment variables to perform a [benchmark][6].
65 | - Bonus activity #2: Modify the CloudFormation template (or launch a new stack) and use a g2.8xlarge instead of g2.2xlarge (you could also try a [P2 instance][12]...) Repeat step 2 in the *Run the model* section, but override the training command in the task definition environment variables to use MPI to take advantage of all 4 GPUs: add `mpirun -np ` in front of the `train` command. For this you will have to create a new revision of the task definition.
66 |
67 | In both bonus steps, look at the CloudWatch Logs to view the task logs (different training commands, taking advantage of multiple GPUs, etc.)
68 |
69 | ## Conclusion
70 |
71 | You should now have a good grasp on how to leverage ECS and GPU-optimized EC2 instances for your Machine Learning needs. Head on over to the [AWS Big Data blog][8] to learn more about how DSSTNE interacts with Apache Spark, trains models, generates predictions, and other fun Machine Learning concepts.
72 |
73 |
74 | [1]: http://www.nvidia.com/object/cuda_home_new.html
75 | [2]: http://docs.aws.amazon.com/AmazonECS/latest/developerguide/task_defintions.html
76 | [3]: http://docs.aws.amazon.com/AmazonECS/latest/developerguide/scheduling_tasks.html
77 | [4]: http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-key-pairs.html
78 | [5]: https://github.com/amznlabs/amazon-dsstne/blob/master/docs/getting_started/examples.md
79 | [6]: https://github.com/amznlabs/amazon-dsstne/blob/master/benchmarks/Benchmark.md
80 | [7]: https://console.aws.amazon.com/cloudwatch/home
81 | [8]: https://blogs.aws.amazon.com/bigdata/post/TxGEL8IJ0CAXTK/Generating-Recommendations-at-Amazon-Scale-with-Apache-Spark-and-Amazon-DSSTNE
82 | [9]: https://aws.amazon.com/marketplace/pp/B00FYCDDTE
83 | [10]: https://console.aws.amazon.com/ecs/
84 | [11]: https://console.aws.amazon.com/s3/home
85 | [12]: https://aws.amazon.com/ec2/instance-types/p2/
86 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 |
2 | Apache License
3 | Version 2.0, January 2004
4 | http://www.apache.org/licenses/
5 |
6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7 |
8 | 1. Definitions.
9 |
10 | "License" shall mean the terms and conditions for use, reproduction,
11 | and distribution as defined by Sections 1 through 9 of this document.
12 |
13 | "Licensor" shall mean the copyright owner or entity authorized by
14 | the copyright owner that is granting the License.
15 |
16 | "Legal Entity" shall mean the union of the acting entity and all
17 | other entities that control, are controlled by, or are under common
18 | control with that entity. For the purposes of this definition,
19 | "control" means (i) the power, direct or indirect, to cause the
20 | direction or management of such entity, whether by contract or
21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
22 | outstanding shares, or (iii) beneficial ownership of such entity.
23 |
24 | "You" (or "Your") shall mean an individual or Legal Entity
25 | exercising permissions granted by this License.
26 |
27 | "Source" form shall mean the preferred form for making modifications,
28 | including but not limited to software source code, documentation
29 | source, and configuration files.
30 |
31 | "Object" form shall mean any form resulting from mechanical
32 | transformation or translation of a Source form, including but
33 | not limited to compiled object code, generated documentation,
34 | and conversions to other media types.
35 |
36 | "Work" shall mean the work of authorship, whether in Source or
37 | Object form, made available under the License, as indicated by a
38 | copyright notice that is included in or attached to the work
39 | (an example is provided in the Appendix below).
40 |
41 | "Derivative Works" shall mean any work, whether in Source or Object
42 | form, that is based on (or derived from) the Work and for which the
43 | editorial revisions, annotations, elaborations, or other modifications
44 | represent, as a whole, an original work of authorship. For the purposes
45 | of this License, Derivative Works shall not include works that remain
46 | separable from, or merely link (or bind by name) to the interfaces of,
47 | the Work and Derivative Works thereof.
48 |
49 | "Contribution" shall mean any work of authorship, including
50 | the original version of the Work and any modifications or additions
51 | to that Work or Derivative Works thereof, that is intentionally
52 | submitted to Licensor for inclusion in the Work by the copyright owner
53 | or by an individual or Legal Entity authorized to submit on behalf of
54 | the copyright owner. For the purposes of this definition, "submitted"
55 | means any form of electronic, verbal, or written communication sent
56 | to the Licensor or its representatives, including but not limited to
57 | communication on electronic mailing lists, source code control systems,
58 | and issue tracking systems that are managed by, or on behalf of, the
59 | Licensor for the purpose of discussing and improving the Work, but
60 | excluding communication that is conspicuously marked or otherwise
61 | designated in writing by the copyright owner as "Not a Contribution."
62 |
63 | "Contributor" shall mean Licensor and any individual or Legal Entity
64 | on behalf of whom a Contribution has been received by Licensor and
65 | subsequently incorporated within the Work.
66 |
67 | 2. Grant of Copyright License. Subject to the terms and conditions of
68 | this License, each Contributor hereby grants to You a perpetual,
69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70 | copyright license to reproduce, prepare Derivative Works of,
71 | publicly display, publicly perform, sublicense, and distribute the
72 | Work and such Derivative Works in Source or Object form.
73 |
74 | 3. Grant of Patent License. Subject to the terms and conditions of
75 | this License, each Contributor hereby grants to You a perpetual,
76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77 | (except as stated in this section) patent license to make, have made,
78 | use, offer to sell, sell, import, and otherwise transfer the Work,
79 | where such license applies only to those patent claims licensable
80 | by such Contributor that are necessarily infringed by their
81 | Contribution(s) alone or by combination of their Contribution(s)
82 | with the Work to which such Contribution(s) was submitted. If You
83 | institute patent litigation against any entity (including a
84 | cross-claim or counterclaim in a lawsuit) alleging that the Work
85 | or a Contribution incorporated within the Work constitutes direct
86 | or contributory patent infringement, then any patent licenses
87 | granted to You under this License for that Work shall terminate
88 | as of the date such litigation is filed.
89 |
90 | 4. Redistribution. You may reproduce and distribute copies of the
91 | Work or Derivative Works thereof in any medium, with or without
92 | modifications, and in Source or Object form, provided that You
93 | meet the following conditions:
94 |
95 | (a) You must give any other recipients of the Work or
96 | Derivative Works a copy of this License; and
97 |
98 | (b) You must cause any modified files to carry prominent notices
99 | stating that You changed the files; and
100 |
101 | (c) You must retain, in the Source form of any Derivative Works
102 | that You distribute, all copyright, patent, trademark, and
103 | attribution notices from the Source form of the Work,
104 | excluding those notices that do not pertain to any part of
105 | the Derivative Works; and
106 |
107 | (d) If the Work includes a "NOTICE" text file as part of its
108 | distribution, then any Derivative Works that You distribute must
109 | include a readable copy of the attribution notices contained
110 | within such NOTICE file, excluding those notices that do not
111 | pertain to any part of the Derivative Works, in at least one
112 | of the following places: within a NOTICE text file distributed
113 | as part of the Derivative Works; within the Source form or
114 | documentation, if provided along with the Derivative Works; or,
115 | within a display generated by the Derivative Works, if and
116 | wherever such third-party notices normally appear. The contents
117 | of the NOTICE file are for informational purposes only and
118 | do not modify the License. You may add Your own attribution
119 | notices within Derivative Works that You distribute, alongside
120 | or as an addendum to the NOTICE text from the Work, provided
121 | that such additional attribution notices cannot be construed
122 | as modifying the License.
123 |
124 | You may add Your own copyright statement to Your modifications and
125 | may provide additional or different license terms and conditions
126 | for use, reproduction, or distribution of Your modifications, or
127 | for any such Derivative Works as a whole, provided Your use,
128 | reproduction, and distribution of the Work otherwise complies with
129 | the conditions stated in this License.
130 |
131 | 5. Submission of Contributions. Unless You explicitly state otherwise,
132 | any Contribution intentionally submitted for inclusion in the Work
133 | by You to the Licensor shall be under the terms and conditions of
134 | this License, without any additional terms or conditions.
135 | Notwithstanding the above, nothing herein shall supersede or modify
136 | the terms of any separate license agreement you may have executed
137 | with Licensor regarding such Contributions.
138 |
139 | 6. Trademarks. This License does not grant permission to use the trade
140 | names, trademarks, service marks, or product names of the Licensor,
141 | except as required for reasonable and customary use in describing the
142 | origin of the Work and reproducing the content of the NOTICE file.
143 |
144 | 7. Disclaimer of Warranty. Unless required by applicable law or
145 | agreed to in writing, Licensor provides the Work (and each
146 | Contributor provides its Contributions) on an "AS IS" BASIS,
147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148 | implied, including, without limitation, any warranties or conditions
149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150 | PARTICULAR PURPOSE. You are solely responsible for determining the
151 | appropriateness of using or redistributing the Work and assume any
152 | risks associated with Your exercise of permissions under this License.
153 |
154 | 8. Limitation of Liability. In no event and under no legal theory,
155 | whether in tort (including negligence), contract, or otherwise,
156 | unless required by applicable law (such as deliberate and grossly
157 | negligent acts) or agreed to in writing, shall any Contributor be
158 | liable to You for damages, including any direct, indirect, special,
159 | incidental, or consequential damages of any character arising as a
160 | result of this License or out of the use or inability to use the
161 | Work (including but not limited to damages for loss of goodwill,
162 | work stoppage, computer failure or malfunction, or any and all
163 | other commercial damages or losses), even if such Contributor
164 | has been advised of the possibility of such damages.
165 |
166 | 9. Accepting Warranty or Additional Liability. While redistributing
167 | the Work or Derivative Works thereof, You may choose to offer,
168 | and charge a fee for, acceptance of support, warranty, indemnity,
169 | or other liability obligations and/or rights consistent with this
170 | License. However, in accepting such obligations, You may act only
171 | on Your own behalf and on Your sole responsibility, not on behalf
172 | of any other Contributor, and only if You agree to indemnify,
173 | defend, and hold each Contributor harmless for any liability
174 | incurred by, or claims asserted against, such Contributor by reason
175 | of your accepting any such warranty or additional liability.
176 |
177 | END OF TERMS AND CONDITIONS
178 |
179 | APPENDIX: How to apply the Apache License to your work.
180 |
181 | To apply the Apache License to your work, attach the following
182 | boilerplate notice, with the fields enclosed by brackets "[]"
183 | replaced with your own identifying information. (Don't include
184 | the brackets!) The text should be enclosed in the appropriate
185 | comment syntax for the file format. We also recommend that a
186 | file or class name and description of purpose be included on the
187 | same "printed page" as the copyright notice for easier
188 | identification within third-party archives.
189 |
190 | Copyright 2016 Amazon Web Services
191 |
192 | Licensed under the Apache License, Version 2.0 (the "License");
193 | you may not use this file except in compliance with the License.
194 | You may obtain a copy of the License at
195 |
196 | http://www.apache.org/licenses/LICENSE-2.0
197 |
198 | Unless required by applicable law or agreed to in writing, software
199 | distributed under the License is distributed on an "AS IS" BASIS,
200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201 | See the License for the specific language governing permissions and
202 | limitations under the License.
203 |
--------------------------------------------------------------------------------
/machinelearning.template:
--------------------------------------------------------------------------------
1 | AWSTemplateFormatVersion: '2010-09-09'
2 | Description: Creates environment for running Amazon DSSTNE on EC2 Container Service
3 | Mappings:
4 | AmazonLinuxAMI:
5 | ap-northeast-1: {AMI: ami-78ba6619}
6 | ap-southeast-1: {AMI: ami-56e84c35}
7 | ap-southeast-2: {AMI: ami-2589b946}
8 | eu-central-1: {AMI: ami-d9d62ab6}
9 | eu-west-1: {AMI: ami-b9bd25ca}
10 | us-east-1: {AMI: ami-50b4f047}
11 | us-west-1: {AMI: ami-699ad409}
12 | us-west-2: {AMI: ami-002bf460}
13 | Metadata:
14 | AWS::CloudFormation::Interface:
15 | ParameterGroups:
16 | - Label: {default: SSH Access}
17 | Parameters: [KeyName, SSHLocation]
18 | - Label: {default: 'VPC, Subnets, and Instance'}
19 | Parameters: [VpcId, Subnets, ECSInstanceType]
20 | - Label: {default: Data and Config}
21 | Parameters: [DataUrl, TrainingConfigUrl]
22 | ParameterLabels:
23 | DataUrl: {default: Data URL}
24 | ECSInstanceType: {default: ECS instance type}
25 | KeyName: {default: Key name}
26 | SSHLocation: {default: SSH CIDR range}
27 | Subnets: {default: Subnets}
28 | TrainingConfigUrl: {default: Training config URL}
29 | VpcId: {default: VPC}
30 | Maintainer: {Description: Chad Schmutzer }
31 | Outputs:
32 | CloudWatchLogsGroup:
33 | Description: Name of the CloudWatch Logs Group
34 | Value: {Ref: CloudWatchLogsGroup}
35 | DsstneTaskDefinition:
36 | Description: The task definition for Amazon DSSTNE
37 | Value: {Ref: ECSTaskDefinitionDsstne}
38 | ECRRepository:
39 | Description: The ECR Repository for the Amazon DSSTNE container
40 | Value: {Ref: ECRRepository}
41 | ECSClusterName:
42 | Description: Name of the ECS cluster
43 | Value: {Ref: ECSCluster}
44 | S3BucketResults:
45 | Description: The S3 bucket for storing results
46 | Value: {Ref: S3BucketResults}
47 | Parameters:
48 | DataUrl: {ConstraintDescription: Must be valid URL, Default: 'https://s3-us-west-2.amazonaws.com/amazon-dsstne-samples/data/ml20m-all',
49 | Description: Neural Network Modeling data URL, Type: String}
50 | ECSInstanceType:
51 | AllowedValues: [g2.2xlarge, g2.8xlarge, p2.xlarge, p2.8xlarge, p2.16xlarge]
52 | ConstraintDescription: Must be g2.2xlarge, g2.8xlarge, p2.xlarge, p2.8xlarge,
53 | p2.16xlarge
54 | Default: g2.2xlarge
55 | Description: ECS instance type
56 | Type: String
57 | KeyName: {Description: Name of an existing EC2 KeyPair, Type: 'AWS::EC2::KeyPair::KeyName'}
58 | SSHLocation: {AllowedPattern: '(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})/(\d{1,2})',
59 | ConstraintDescription: Must be a valid CIDR range of the form x.x.x.x/x, Default: 0.0.0.0/0,
60 | Description: Restrict SSH access to CIDR range (default can be accessed from anywhere),
61 | MaxLength: '18', MinLength: '9', Type: String}
62 | Subnets: {ConstraintDescription: Must be a list of existing subnets in the selected
63 | Virtual Private Cloud, Description: Please make sure you select 1 or more subnets
64 | in the Virtual Private Cloud (VPC) ID you chose above, Type: 'List'}
65 | TrainingConfigUrl: {ConstraintDescription: Must be a valid URL, Default: 'https://s3-us-west-2.amazonaws.com/amazon-dsstne-samples/configs/config.json',
66 | Description: Training config URL, Type: String}
67 | VpcId: {ConstraintDescription: Must be the VPC ID of an existing Virtual Private
68 | Cloud, Description: VPC ID of your existing Virtual Private Cloud (VPC), Type: 'AWS::EC2::VPC::Id'}
69 | Resources:
70 | CloudWatchLogsGroup:
71 | Properties: {RetentionInDays: 7}
72 | Type: AWS::Logs::LogGroup
73 | ECRRepository: {Type: 'AWS::ECR::Repository'}
74 | ECSCluster: {Type: 'AWS::ECS::Cluster'}
75 | ECSInstanceAutoScalingGroup:
76 | CreationPolicy:
77 | ResourceSignal: {Count: '1', Timeout: PT120M}
78 | Properties:
79 | DesiredCapacity: '1'
80 | LaunchConfigurationName: {Ref: ECSInstanceLaunchConfiguration}
81 | MaxSize: '1'
82 | MinSize: '1'
83 | Tags:
84 | - Key: Name
85 | PropagateAtLaunch: 'true'
86 | Value: {Ref: 'AWS::StackName'}
87 | VPCZoneIdentifier: {Ref: Subnets}
88 | Type: AWS::AutoScaling::AutoScalingGroup
89 | ECSInstanceLaunchConfiguration:
90 | Metadata:
91 | AWS::CloudFormation::Init:
92 | config:
93 | files:
94 | /etc/ecs/ecs.config:
95 | content:
96 | Fn::Join:
97 | - ''
98 | - - ECS_CLUSTER=
99 | - {Ref: ECSCluster}
100 | - '
101 |
102 | '
103 | - 'ECS_AVAILABLE_LOGGING_DRIVERS=["json-file","awslogs"]
104 |
105 | '
106 | group: root
107 | mode: '000644'
108 | owner: root
109 | /home/ec2-user/.aws/config:
110 | content:
111 | Fn::Join:
112 | - ''
113 | - - '[default]
114 |
115 | '
116 | - 'region = '
117 | - {Ref: 'AWS::Region'}
118 | - '
119 |
120 | '
121 | group: root
122 | mode: '000644'
123 | owner: ec2-user
124 | /home/ec2-user/Dockerfile:
125 | content:
126 | Fn::Join:
127 | - ''
128 | - ['FROM nvidia/cuda:7.5-cudnn5-devel
129 |
130 | ', '
131 |
132 | ', 'RUN apt-get update && \
133 |
134 | ', ' apt-get -y dist-upgrade && \
135 |
136 | ', ' apt-get -y install \
137 |
138 | ', ' kmod \
139 |
140 | ', ' make \
141 |
142 | ', ' build-essential \
143 |
144 | ', ' cmake \
145 |
146 | ', ' cpp \
147 |
148 | ', ' g++ \
149 |
150 | ', ' gcc \
151 |
152 | ', ' libatlas-base-dev \
153 |
154 | ', ' curl \
155 |
156 | ', ' python-pip \
157 |
158 | ', ' openmpi-bin \
159 |
160 | ', ' libopenmpi-dev \
161 |
162 | ', ' libjsoncpp-dev \
163 |
164 | ', ' libhdf5-dev \
165 |
166 | ', ' openssh-client \
167 |
168 | ', ' zlib1g-dev
169 |
170 | ', '
171 |
172 | ', 'RUN pip install awscli
173 |
174 | ', '
175 |
176 | ', 'ENV GPU_DRIVER_VERSION=352.99
177 |
178 | ', '
179 |
180 | ', 'RUN cd /tmp && \
181 |
182 | ', ' curl -LO http://us.download.nvidia.com/XFree86/Linux-x86_64/$GPU_DRIVER_VERSION/NVIDIA-Linux-x86_64-$GPU_DRIVER_VERSION.run
183 | && \
184 |
185 | ', ' chmod +x ./NVIDIA-Linux-x86_64-$GPU_DRIVER_VERSION.run &&
186 | \
187 |
188 | ', ' ./NVIDIA-Linux-x86_64-$GPU_DRIVER_VERSION.run -s --no-kernel-module
189 | && \
190 |
191 | ', ' rm -rf /tmp/*
192 |
193 | ', '
194 |
195 | ', 'RUN ln -s /usr/include/hdf5/serial/* /usr/include/
196 |
197 | ', '
198 |
199 | ', 'RUN ln -s /usr/lib/x86_64-linux-gnu/hdf5/serial/libhdf5* /usr/lib/x86_64-linux-gnu/
200 |
201 | ', '
202 |
203 | ', 'RUN cd /tmp && \
204 |
205 | ', ' curl -LO ftp://ftp.unidata.ucar.edu/pub/netcdf/netcdf-4.1.3.tar.gz
206 | && \
207 |
208 | ', ' tar xvf netcdf-4.1.3.tar.gz && \
209 |
210 | ', ' cd netcdf-4.1.3 && \
211 |
212 | ', ' ./configure --prefix=/usr/local && \
213 |
214 | ', ' make -j16 && \
215 |
216 | ', ' make install && rm -rf /tmp/*
217 |
218 | ', '
219 |
220 | ', 'RUN cd /tmp && \
221 |
222 | ', ' curl -LO http://www.unidata.ucar.edu/downloads/netcdf/ftp/netcdf-cxx4-4.2.tar.gz
223 | && \
224 |
225 | ', ' tar xvf netcdf-cxx4-4.2.tar.gz && \
226 |
227 | ', ' cd netcdf-cxx4-4.2 && \
228 |
229 | ', ' ./configure --prefix=/usr/local && \
230 |
231 | ', ' make -j16 && \
232 |
233 | ', ' make install && rm -rf /tmp/*
234 |
235 | ', '
236 |
237 | ', 'RUN cd /tmp && \
238 |
239 | ', ' curl -LO https://github.com/NVlabs/cub/archive/1.5.2.zip
240 | && \
241 |
242 | ', ' apt-get install -y unzip && \
243 |
244 | ', ' unzip 1.5.2.zip && \
245 |
246 | ', ' cp -rf cub-1.5.2/cub/ /usr/local/include/ && \
247 |
248 | ', ' rm -rf /tmp/*
249 |
250 | ', '
251 |
252 | ', 'ENV PATH=/usr/local/openmpi/bin/:/usr/local/cuda/bin/:${PATH}
253 | \
254 |
255 | ', ' LD_LIBRARY_PATH=/usr/local/lib/:${LD_LIBRARY_PATH}
256 |
257 | ', '
258 |
259 | ', 'RUN ln -sf /usr/lib/openmpi /usr/local/openmpi
260 |
261 | ', '
262 |
263 | ', 'COPY src /opt/amazon/dsstne/src
264 |
265 | ', '
266 |
267 | ', 'RUN sed -i "s/-gencode arch=compute_60,code=sm_60//" /opt/amazon/dsstne/src/amazon/dsstne/Makefile.inc
268 |
269 | ', '
270 |
271 | ', 'RUN cd /opt/amazon/dsstne/src/amazon/dsstne && \
272 |
273 | ', ' make
274 |
275 | ', '
276 |
277 | ', 'ENV PATH /opt/amazon/dsstne/src/amazon/dsstne/bin:${PATH}
278 |
279 | ']
280 | group: root
281 | mode: '000644'
282 | owner: root
283 | /root/.aws/config:
284 | content:
285 | Fn::Join:
286 | - ''
287 | - - '[default]
288 |
289 | '
290 | - 'region = '
291 | - {Ref: 'AWS::Region'}
292 | - '
293 |
294 | '
295 | group: root
296 | mode: '000644'
297 | owner: root
298 | packages:
299 | yum:
300 | docker: []
301 | ecs-init: []
302 | git: []
303 | services:
304 | sysvinit:
305 | docker: {enabled: 'true', ensureRunning: 'true'}
306 | Properties:
307 | BlockDeviceMappings:
308 | - DeviceName: /dev/xvda
309 | Ebs: {VolumeSize: '30'}
310 | IamInstanceProfile: {Ref: ECSInstanceProfile}
311 | ImageId:
312 | Fn::FindInMap:
313 | - AmazonLinuxAMI
314 | - {Ref: 'AWS::Region'}
315 | - AMI
316 | InstanceType: {Ref: ECSInstanceType}
317 | KeyName: {Ref: KeyName}
318 | SecurityGroups:
319 | - {Ref: ECSInstanceSecurityGroup}
320 | UserData:
321 | Fn::Base64:
322 | Fn::Join:
323 | - ''
324 | - - '#!/bin/bash -xe
325 |
326 | '
327 | - 'yum -y update --exclude=kernel* --exclude=nvidia*
328 |
329 | '
330 | - '# Install the files and packages from the metadata
331 |
332 | '
333 | - '/opt/aws/bin/cfn-init -v '
334 | - ' --stack '
335 | - {Ref: 'AWS::StackName'}
336 | - ' --resource ECSInstanceLaunchConfiguration '
337 | - ' --region '
338 | - {Ref: 'AWS::Region'}
339 | - '
340 |
341 | '
342 | - '/sbin/start ecs
343 |
344 | '
345 | - 'cd /root/ && git clone https://github.com/amznlabs/amazon-dsstne.git
346 |
347 | '
348 | - 'cd /root/amazon-dsstne/
349 |
350 | '
351 | - 'cp /home/ec2-user/Dockerfile .
352 |
353 | '
354 | - 'docker build -t '
355 | - {Ref: ECRRepository}
356 | - ' .
357 |
358 | '
359 | - 'aws ecr get-login | sh
360 |
361 | '
362 | - 'docker tag '
363 | - {Ref: ECRRepository}
364 | - ':latest '
365 | - {Ref: 'AWS::AccountId'}
366 | - .dkr.ecr.
367 | - {Ref: 'AWS::Region'}
368 | - .amazonaws.com/
369 | - {Ref: ECRRepository}
370 | - ':latest
371 |
372 | '
373 | - 'docker push '
374 | - {Ref: 'AWS::AccountId'}
375 | - .dkr.ecr.
376 | - {Ref: 'AWS::Region'}
377 | - .amazonaws.com/
378 | - {Ref: ECRRepository}
379 | - ':latest
380 |
381 | '
382 | - '# Signal the status from cfn-init
383 |
384 | '
385 | - '/opt/aws/bin/cfn-signal -e $? '
386 | - ' --stack '
387 | - {Ref: 'AWS::StackName'}
388 | - ' --resource ECSInstanceAutoScalingGroup '
389 | - ' --region '
390 | - {Ref: 'AWS::Region'}
391 | - '
392 |
393 | '
394 | Type: AWS::AutoScaling::LaunchConfiguration
395 | ECSInstanceProfile:
396 | DependsOn: ECSInstanceRole
397 | Properties:
398 | Path: /
399 | Roles:
400 | - {Ref: ECSInstanceRole}
401 | Type: AWS::IAM::InstanceProfile
402 | ECSInstanceRole:
403 | Properties:
404 | AssumeRolePolicyDocument:
405 | Statement:
406 | - Action: ['sts:AssumeRole']
407 | Effect: Allow
408 | Principal:
409 | Service: [ec2.amazonaws.com]
410 | Version: '2012-10-17'
411 | ManagedPolicyArns: ['arn:aws:iam::aws:policy/service-role/AmazonEC2ContainerServiceforEC2Role']
412 | Path: /
413 | Policies:
414 | - PolicyDocument:
415 | Statement:
416 | - Action: s3:ListBucket
417 | Effect: Allow
418 | Resource:
419 | Fn::Join:
420 | - ''
421 | - - 'arn:aws:s3:::'
422 | - {Ref: S3BucketResults}
423 | - Action: ['s3:PutObject', 's3:GetObject', 's3:DeleteObject']
424 | Effect: Allow
425 | Resource:
426 | Fn::Join:
427 | - ''
428 | - - 'arn:aws:s3:::'
429 | - {Ref: S3BucketResults}
430 | - /*
431 | - Action: ['ecr:DescribeRepositories', 'ecr:ListImages', 'ecr:InitiateLayerUpload',
432 | 'ecr:UploadLayerPart', 'ecr:CompleteLayerUpload', 'ecr:PutImage']
433 | Effect: Allow
434 | Resource:
435 | Fn::Join:
436 | - ''
437 | - - 'arn:aws:ecr:'
438 | - {Ref: 'AWS::Region'}
439 | - ':'
440 | - {Ref: 'AWS::AccountId'}
441 | - :repository/
442 | - {Ref: ECRRepository}
443 | Version: '2012-10-17'
444 | PolicyName: Amazon-DSSTNE
445 | Type: AWS::IAM::Role
446 | ECSInstanceSecurityGroup:
447 | Properties:
448 | GroupDescription: Security Group for ECSInstance
449 | SecurityGroupIngress:
450 | - CidrIp: {Ref: SSHLocation}
451 | FromPort: '22'
452 | IpProtocol: tcp
453 | ToPort: '22'
454 | Tags:
455 | - {Key: Name, Value: ECSInstanceSecurityGroup}
456 | VpcId: {Ref: VpcId}
457 | Type: AWS::EC2::SecurityGroup
458 | ECSServiceRole:
459 | Properties:
460 | AssumeRolePolicyDocument:
461 | Statement:
462 | - Action: ['sts:AssumeRole']
463 | Effect: Allow
464 | Principal:
465 | Service: [ecs.amazonaws.com]
466 | Version: '2012-10-17'
467 | ManagedPolicyArns: ['arn:aws:iam::aws:policy/service-role/AmazonEC2ContainerServiceRole']
468 | Path: /
469 | Type: AWS::IAM::Role
470 | ECSTaskDefinitionDsstne:
471 | Properties:
472 | ContainerDefinitions:
473 | - Command: ['curl -Lo data $DATAURL && echo "running $GENERATEINPUTCMD" && $GENERATEINPUTCMD
474 | && echo "running $GENERATEOUTPUTCMD" && $GENERATEOUTPUTCMD && curl -Lo
475 | config $TRAININGCONFIGURL && echo "running $TRAINCMD" && $TRAINCMD &&
476 | echo "running $PREDICTCMD" && $PREDICTCMD && DATE=`date -Iseconds` &&
477 | echo "results being written to s3://$S3BUCKETRESULTS/results.$HOSTNAME.$DATE"
478 | && aws s3 cp results s3://$S3BUCKETRESULTS/results.$HOSTNAME.$DATE &&
479 | echo "Task complete!"']
480 | EntryPoint: [/bin/bash, -c]
481 | Environment:
482 | - Name: DATAURL
483 | Value: {Ref: DataUrl}
484 | - Name: TRAININGCONFIGURL
485 | Value: {Ref: TrainingConfigUrl}
486 | - Name: S3BUCKETRESULTS
487 | Value: {Ref: S3BucketResults}
488 | - {Name: GENERATEINPUTCMD, Value: generateNetCDF -d gl_input -i data -o gl_input.nc
489 | -f features_input -s samples_input -c}
490 | - {Name: GENERATEOUTPUTCMD, Value: generateNetCDF -d gl_output -i data -o
491 | gl_output.nc -f features_output -s samples_input -c}
492 | - {Name: TRAINCMD, Value: train -c config -i gl_input.nc -o gl_output.nc -n
493 | gl.nc -b 256 -e 10}
494 | - {Name: PREDICTCMD, Value: predict -b 1024 -d gl -i features_input -o features_output
495 | -k 10 -n gl.nc -f data -s results -r data}
496 | Image:
497 | Fn::Join:
498 | - ''
499 | - - {Ref: 'AWS::AccountId'}
500 | - .dkr.ecr.
501 | - {Ref: 'AWS::Region'}
502 | - .amazonaws.com/
503 | - {Ref: ECRRepository}
504 | - :latest
505 | LogConfiguration:
506 | LogDriver: awslogs
507 | Options:
508 | awslogs-group: {Ref: CloudWatchLogsGroup}
509 | awslogs-region: {Ref: 'AWS::Region'}
510 | Memory: '15000'
511 | Name: Amazon-DSSTNE
512 | Privileged: 'true'
513 | Type: AWS::ECS::TaskDefinition
514 | S3BucketResults:
515 | Properties: {AccessControl: BucketOwnerFullControl}
516 | Type: AWS::S3::Bucket
517 |
--------------------------------------------------------------------------------