Favorite Technical Interview Questions?

That’s 147ns, so roughly 500 clocks on a Xeon Skylake. 4 loads should take 5 clocks (from L1). 4 vector multiply-adds should take 20 clocks, so it should take roughly 25 clocks total or 8ns. There is also capacity to do more than one of these in parallel if need be. If the one matrix needs to be transposed, probably another 4 clocks or so (so 9-10ns), so what you have there is roughly an order of magnitude slower. As the matrix gets bigger I would expect the hand-rolled vs vDSP implementation to converge.
The peripheral code is probably the biggest lag. Best not to bother with 2D structures, just leave the data in a 1D, which avoids all the flatMap, map computes, and then also not have the inverse cost either re stride, map.

In either case in my world that compute would have been more than adequate; anybody chasing improvement over that would seen as mucking around, different world, different priorities.

Edit: surprisingly the peripheral code wasn't that heavy, but it did knock off another 0. From here it's probably a bit of the cost for the Swift Double type versus a more optimised SIMD type.
 
Last edited:
Yup! Also you can ask in what situations can the compiler elide the copy for value types. Eg, can it elide it in C/C++ if the value is declared “const”?

I have no idea what you just said.
 
I have no idea what you just said.

When passing by value a copy is made (or rather, at least the code has to have that behavior). In what cases if any can the compiler skip that copy? And does making the value const help?
 
When passing by value a copy is made (or rather, at least the code has to have that behavior). In what cases if any can the compiler skip that copy? And does making the value const help?

What follows is the reason I'll never get paid millions of USD a year :p , but I assume that if the value is never modified or used the compiler can skip the copy (so making it a constant will help).

How far off am I?
 
What follows is the reason I'll never get paid millions of USD a year :p , but I assume that if the value is never modified or used the compiler can skip the copy (so making it a constant will help).

How far off am I?

So it turns out that const doesn’t help at all. The compiler can only skip the copy if it can detect that the passed data is not being changed by the called function by parsing it and doing the appropriate analysis. It can only do this if the function is in the scope of the object file being compiled (extended somewhat for link time optimization) and is also relatively simple.

The reason that the const doesn’t help is that it’s just there to hint at semantics and detect errors. The const object could be const casted to a non-const object and modified in the function being called. If it decided not to copy, the original by value object would be changed and you would see different behavior.
 
That's where a compiler that "milks" a COW just makes life so much more simpler.
 
Last edited:
I havent applied for a job in a very long time. If these are the type of questions asked in an interview then I'm stuck for life in my current job. :-)
 
I havent applied for a job in a very long time. If these are the type of questions asked in an interview then I'm stuck for life in my current job. :)

Ugh, you and me both. I can't interview to save my life. Reminds me of exam time in school.
 
"Where do you see yourself in 5 years from now"

I see myself as that guy that has a job and hopefully still working here :p

Works every time.
 
"Where do you see yourself in 5 years from now"

I see myself as that guy that has a job and hopefully still working here :p

Works every time.

What about I see my self as your boss.
 
I havent applied for a job in a very long time. If these are the type of questions asked in an interview then I'm stuck for life in my current job. :)
The questions in this thread are more relevant wrt specialization, not mainstream.
 
I've grown up and realised asking somebody the difference between value and reference types is both stupid and pointless.

I now ask them a simple whiteboard question to describe the class structure, another one to see if Mr Senior dev over here can solve a problem optimally without throwing more for loops at the problem and a basic SQL question.

I've changed questions I asked over time but the current set works pretty well for what we're looking for in South Africa.
 
How would you test to whether or not a ray in 3D intersects a triangle?

How would you do it efficiently?
 
How would you test to whether or not a ray in 3D intersects a triangle?

How would you do it efficiently?

Off the top of my head, I'd split this into two parts.

Does the vector representing the ray intersect the plane on which the triangle sits? If it does intersect, what are the coordinates on the plane where intersection occurs?

Because this is an intersection between a vector and a plane, we know that there will be either 0 or 1 intersections, never more than that.

Given the coordinates on the plane where intersection takes place, we can get rid of the third dimension, so now we have a simple problem in which we have to work out if a point is inside or outside of a triangle. I don't know much about bounds checking algorithms, but you could do a simple first pass by checking the whether the point is outside the least minimum and highest maximum of each of the x and y coordinates. If it is inside those coordinates... then I'm not sure. Probably some simple mathematical trick involving linear algebra.
 
Off the top of my head, I'd split this into two parts.

Does the vector representing the ray intersect the plane on which the triangle sits? If it does intersect, what are the coordinates on the plane where intersection occurs?

Because this is an intersection between a vector and a plane, we know that there will be either 0 or 1 intersections, never more than that.

Given the coordinates on the plane where intersection takes place, we can get rid of the third dimension, so now we have a simple problem in which we have to work out if a point is inside or outside of a triangle. I don't know much about bounds checking algorithms, but you could do a simple first pass by checking the whether the point is outside the least minimum and highest maximum of each of the x and y coordinates. If it is inside those coordinates... then I'm not sure. Probably some simple mathematical trick involving linear algebra.

Great! My follow up questions in an interview from this would be:
1) When getting rid of the third dimension after finding the intersection point, how would you choose which of the 3 dimensions to remove? Removing the wrong one, could result in a degenerate triangle.
2) Intersecting the ray with the plane requires a (expensive) divide. Is there a way to answer this question without the divide?
 
Great! My follow up questions in an interview from this would be:
1) When getting rid of the third dimension after finding the intersection point, how would you choose which of the 3 dimensions to remove? Removing the wrong one, could result in a degenerate triangle.
2) Intersecting the ray with the plane requires a (expensive) divide. Is there a way to answer this question without the divide?

I know you'd have to map from 3 dimensions to 2, because you can't assume that the plane is aligned to one of the axes.

You'd have to map the vertices of the triangle as well as the intersection point from their 3 dimensional coordinates to a 2 dimensional plane. So, you're not completely discarding a dimension - part of the information contained in that dimension could end up in the 2 dimensional coordinates. Unless you have a plane with something like z=0, then you can be sure.

How exactly that mapping would work - don't know, need a linear algebra textbook!

I'm thinking you could use a dot product operation for the intersection, but I'm not sure.
 
Top
Sign up to the MyBroadband newsletter
X