News for hackers. Stuff that matters.
Re:Why I sometimes like to write my own number crunching code by queuebert on Saturday June 26, 2021 @11:49AM (#27642886)
The author is overconfident and underestimates library writers to a fault. Packing a bunch of dot products into a matrix is only the fastest way to compute a batch of cosine similarities if you are relegated to a parallel matrix product function.

If you write the procedure in raw CUDA, for example, it is faster to simply broadcast the dot products across threads. That is exactly what the matrix multiply is doing except without the overhead of matrix creation and with potentially greater locality of memory accesses.

Edit: I do think it is worthwhile to write your own code so that you better understand what is happening under the hood, so good on the author for that.

Re:Why I sometimes like to write my own number crunching code by klyrs on Saturday June 26, 2021 @12:38PM (#27643372)
> The author is overconfident and underestimates library writers to a fault.

Clicking around the website a bit, it would seem that the author is a library writer (some specifically targeting GPUs), and the article is a plug for the books he's written about numerical analysis. How confident are you?

Re:Why I sometimes like to write my own number crunching code by queuebert on Saturday June 26, 2021 @01:05PM (#27643622)
Not very confident in general. But I have written a LOT of raw CUDA code.
Re:Why I sometimes like to write my own number crunching code by inimino on Saturday June 26, 2021 @05:33PM (#27646094)
This pattern comes up a lot in comments on this type of post. Author makes a dumb but easy-to-follow example to make a point, and then someone points out how the example is dumb. Try to avoid getting hung up on examples -- in this case nobody reading this post should come away thinking they now know more about cosine similarity than a library author. I dare say the author's main points were:

- it's not that much code

- it's not terrifyingly hard to understand

- you might open up performance benefits in your specific circumstance just by knowing how it's calculated after writing the code to do it yourself

Re:Why I sometimes like to write my own number crunching code by queuebert on Sunday June 27, 2021 @03:44PM (#27654630)
Lest you think mine was a shallow, knee-jerk analysis, this is my area of subject matter expertise. I get all the nuances, but I just felt like defending library authors, whom he unjustly threw under the bus, because that stuff is really hard. Like really hard.

Also, if you are using libraries written by grad students, then you probably need to find better libraries. All of the major battle-hardened ones like BLAS, LAPACK, CUDNN, TF, FFTW, etc., have had major big brains looking at them for years. Decades in some cases.

Re:Why I sometimes like to write my own number crunching code by inimino on Sunday June 27, 2021 @05:33PM (#27655655)
I didn't read it that way. I took the audience to be more junior programmers to whom numeric library code can seem inscrutable and terrifying. In my experience "write it yourself first" is very liberating advice that every programmer should take to heart. I would also cut the author a little slack since he is a library author and the post is a kind of ad for his own numeric library. It could have been worded better though.
Re:Why I sometimes like to write my own number crunching code by exmadscientist on Saturday June 26, 2021 @05:37PM (#27646128)
> in this case nobody reading this post should come away thinking they now know more about cosine similarity than a library author

However, if this post leaves you open to the option that you might know more about $THING than a library author... that is probably a very healthy possibility to consider.

(Consider. Some are that grad student who got assigned to write the library because they were too useless to do anything else. Others are David M Gay.)

Re:Why I sometimes like to write my own number crunching code by username90 on Saturday June 26, 2021 @10:40PM (#27648046)
Beating library implementations is usually very easy since you know your use case perfectly and they don't. You need to be way less competent than them to not be able to do something better when you write a tailor made solution. The main reason not to do it is that it takes time and makes the code harder to get into for new hires.
Re:Why I sometimes like to write my own number crunching code by inimino on Saturday June 26, 2021 @08:23PM (#27647291)
Indeed! That you should be optimistic about it is the best thing to take away from the post.
Re:Why I sometimes like to write my own number crunching code by Blackthorn on Saturday June 26, 2021 @12:31PM (#27643296)
The author is a library writer!
Re:Why I sometimes like to write my own number crunching code by queuebert on Saturday June 26, 2021 @01:07PM (#27643642)
My mistake. I took this statement in isolation: "...consider that machine learning libraries are frequently written by grad students on their path to discovery. It's a domain expert with poor programming skills. Or it might be a case of a good programmer who only barely understands the domain…"