Amazon AWS Neuron SDE-2 (Annapurna Labs)
Company: Amazon
Role: SDE II
Interview Stage: Onsite
Location: unknown
Year: unknown
Original Post Content:
Phone Screening
Standard Amazon process - 2 LP questions (Dive Deep, Bias for Action)
DSA question - Given a machine learning workload in the form of graph, find the possible operation order in which this workload can be executed (Solution - Topological sort. There was a follow-up discussion on which order is better in terms of compilers, the solution was to choose the path where less information stay in the memory)
DSA 1
2 LP questions, DSA - https://leetcode.com/problems/number-of-operations-to-make-network-connected/description/
Hiring Manager
A discussion around my experience on compilers and the work done in my current workplace.
Discussions on AutoSchedulers, inference engines, transforms, analysis (talks around compilers)
Bar Raiser
LP Questions on - Customer Obsession, Deliver Results, Insist on high standards
DSA 2
I would not say that this was a DSA round. Here is the question -
Question - Design an algorithm to compute matrix multiplication which takes two tensors A[n,m] and B[m,p] and generates C[n,p]
Assume that we have SIMD intrinsic functions that can process 4 elements at one time:
Y[1] = simd_reduce_add(X[4], Y[1]) #Y[0] = X[0] + X[1] + X[2] + X[3] + Y[0]
Z[4] = simd_multiply(X[4],Y[4]) #element-wise multiplication of X and Y to Z
Assume n,m,p are all multiple of 4
Solution -
vector<float> vecA(4);
vector<float> vecB(4);
vector<float> prod(4);
for(int i=0;i<n;i++) {
for(int j=0;j<p;j++) {
float sum = 0.0f;
for(int k=0;k<m;k+=4) {
load(A[i][k], vecA); // function that copies 4 elements starting from i,k to vecA
load(B[k][j], vecB);
prod = SIMD_MULTIPLY(vecA, vecB);
SIMD_REDUCE_ADD(sum, prod);
}
C[i][j] = sum;
}
}
Follow-up
Try modelling Z[4] = SIMD_ADD(X[4], Y[4]) instead of SIMD_REDUCE_ADD(X[4],Y[1])
vector<float> vecA(4);
vector<float> vecB(4);
vector<float> prod(4);
for(int i=0;i<n;i++) {
for(int j=0;j<p;j++) {
vector<float> sum(4,0.0f);
for(int k=0;k<m;k+=4) {
load(A[i][k], vecA); // function that copies 4 elements starting from i,k to vecA
load(B[k][j], vecB);
prod = SIMD_MULTIPLY(vecA, vecB);
SIMD_ADD(sum, prod);
}
C[i][j] = sum[0] + sum[1] + sum[2] + sum[3];
}
}
Comments - The interviewer told me that I do not have + operation available and required me to do something else. Later I searched, it was something like I needed to shuffle these arrays and add them i.e. array1 = {sum[0],0,0,0}; array2 = {sum[1],0,0,0}, array3 = {sum[2],0,0,0}, array4 = {sum[3],0,0,0} and then call SIMD_ADD on these arrays and store sum[0] in C[i][j]. IDK if you followed this. Honestly, I didn't :)
DSA 3
Suppose you are given an array that depicts a multi-level car parking system. Each element in the array is the size available in each bay.
Now, you have 1 valet driver that will go and park the car for you.
Here are some rules -
1. To park a car of size N in a bay, you will need N contiguous spaces available in the bay.
2. Once a car is parked, it will not be moved until the owner comes to receive it.
Write two functions
int parkCar(int size) // if space for your car (of size size) is available, your car will be parked and you will get a ticket ID. If there is no space available, return -1
void getCar(int ticketNo) // accepts a ticket number and removes that car from it's parked place, leaving behind empty spaces to be reused later.
The max size of a bay can be 20
Here is the boiler plate code -
class CarParking {
public:
CarParking(vector<int>& spaces) // Where each element in the array specifies the number of spaces in each bay
int parkCar(int size);
void getCar(int ticketNo)
};