WEBVTT

0:00:00.000 --> 0:00:08.700
<v A>Hosting provided by HostTornado. They offer website hosting packages, dedicated servers, and VPS solutions. HostT.net.

0:00:16.640 --> 0:00:21.980
<v A>Programming Throwdown, Episode 29: CUDA and OpenCL. Take it away, Patrick.

0:00:22.760 --> 0:00:26.760
<v B>So I'm a little under the weather, so if I sound stuffy or terrible, I'm going to blame that.

0:00:26.760 --> 0:00:32.620
<v A>Yeah, I dragged him kicking and screaming into the Programming Throwdown studio to record this episode.

0:00:32.880 --> 0:00:33.760
<v B>The studio? Wait.

0:00:34.400 --> 0:00:35.805
<v A>The studio. Am I taking too?

0:00:36.008 --> 0:00:58.640
<v B>Much medicine? All right, so I do have an opening topic, and then maybe I'll lose my voice already and be quiet for the rest of the episode. Hey, stop cheering. All right, so I link a website here in the show notes, origamitessellations.com. But more specifically, my mom was in town to visit, and she likes doing puzzles or whatever. I don't know how I got on it.

0:00:58.660 --> 0:01:01.540
<v A>My mom likes doing—maybe it's a mom thing. It's a

0:01:01.540 --> 0:01:06.585
<v B>connection with moms and puzzles. I mean, I think it's—I like puzzles as well. I just don't have patience for them or whatever. Maybe that's

0:01:06.585 --> 0:01:18.740
<v A>what it is. It is a connection with, like, you know, for example, like my parents are close to retirement. My dad's already retired, so they have plenty of time that we don't have because we're working, kids, all that stuff.

0:01:18.740 --> 0:01:27.460
<v B>Yeah, so I think we could probably be puzzle masters in 40 years. And how many? 30 years, 40 years? Ten. Or the

0:01:27.460 --> 0:01:31.940
<v A>retirement. Oh, really? That's a puzzle. If you can solve that puzzle, let me know.

0:01:32.320 --> 0:02:53.978
<v B>Yeah, yeah. I'll sell a book. Yeah, that's right. So anyway, so she was out to visit us, and we—somehow, I don't remember, I think I had some origami paper I had found at a store or whatever. And I was like, oh, off and on throughout childhood, I had tried doing this amazing art of folding paper and never been very good at it. And then recently, I found some and tried it and decided I was going to search on YouTube. And surprisingly enough, YouTube is an excellent teacher for origami. Right? Sometimes people do stuff. They're like, oh, you just do this. And then they, like, put their hands in front of the paper as they do some crazy trick, awesome voodoo stuff. And then you—it's just as puzzling. But for, like, straightforward things, and for the most part, rather than looking at the diagram, you know, it's a really useful thing. So my mom and I started doing some origami in the evening as, like, something to do as opposed to just sitting and watching TV or whatever. Yeah, totally. And she was really, really excited about it and really excited to watch YouTube videos and see, like, oh, this is really helpful. Like, I never knew how to do this before or whatever. So we folded some animals and some complicated shapes and some simple shapes. It was a lot of fun. But this website, origamitessellations.com, I had come across probably a couple years ago. And the guy here—I believe his first name is Eric. I won't try to pronounce his last name. He does tessellation origami, which is just like you would think tessellation is, like, the same shape. Like triangles? Triangles or squares. Oh, that's

0:02:53.978 --> 0:03:34.427
<v B>right. It shifted around. And, of course, once you have triangles, you can do hexagons. Oh. And so it's basically you first fold the paper into pre-creasing it with, like, let's say, a bunch of squares. Then you do a set of maneuvers—probably not using the right word, anyways—to fold those into something else or, like, also a repeated pattern or a new shape. And I just find it really interesting because normal origami is cool. But sometimes, you know, it's like how many different ways can you fold a penguin? Well, they don't look that much like a penguin or whatever. But this is more, like, artistic and abstract in a way because you're not making specifically something that looks like an animal. You could be making something that is just beautiful for the repetition of it. Oh, yeah. I'm looking

0:03:34.427 --> 0:03:36.480
<v A>at some of these pictures now. It looks pretty awesome.

0:03:36.640 --> 0:03:44.959
<v B>Yeah. So I folded one. So it takes a long time to get the paper pre-creased. But once you do, like, I folded this one. It was, like, a series of repeating overlapping squares.

0:03:45.399 --> 0:03:49.514
<v A>Can you pre-crease, like, 100 sheets at once? No. Like, 20 sheets at once?

0:03:49.540 --> 0:04:30.580
<v B>I tried. Yeah. Or, like, doing multiple. Like, once you fold it in half, doing the rest and essentially doubling it. Yeah. And you can do it to some extent. But you end up building up an error because when the paper bends, right? Like, it bends around a radius that's increasing and it causes problems. And you do learn precision doing this. And I folded this overlapping square thing. And it was beautiful to look at initially. And then I, like, held it up to a light and actually see because some places are only one layer. Some places are three or four layers. Some places are two layers. Oh. And it produces, like, a grayscale picture. I don't know if you've ever seen, like, a lithograph. Is that what it's called? That sounds familiar. Lithophane. Something like that where they take wood and carve a negative of an image. Yeah. And when you hold it up to light, you see the picture.

0:04:30.760 --> 0:04:33.405
<v A>I did that one year with a pumpkin. It took forever, but

0:04:33.405 --> 0:04:34.671
<v B>it was awesome. Wow. That's

0:04:34.671 --> 0:04:42.760
<v A>impressive. Yeah. I actually had a shape where at no point, like, did I puncture all the way through the pumpkin. But it was just, like, at different depths. So it came out pretty cool. Yeah.

0:04:43.000 --> 0:05:08.100
<v B>Yeah. So I did this with origami. And it was mathematical, right? Like, tessellations are very mathematical in nature. You can kind of apply that there. And even just in general, there's a lot of work, which I think his name is Robert Lang, has done work on, like, crease patterns. So what happens when you fold a shape and then you unfold it and you look at the creases or whatever? And how do you describe that when, like, treatments of it? And can you find more optimal ways of folding or crease patterns and that kind of stuff?

0:05:08.421 --> 0:05:09.079
<v A>It's just kind

0:05:09.079 --> 0:05:15.660
<v B>of the nerdy way of that thing you remember doing when so many years ago of, like, folding the paper and making the pirate hat.

0:05:16.180 --> 0:05:49.460
<v A>The pirate hat. That's pretty awesome. Okay. On to the news. So first news article: HTML5. This is—HTML5 is pretty much ubiquitous now. I mean, you'll hear 'not supported in IE6' or something like that. But people are giving up on that, and that might not even be true, actually. It's supported on a ton of browsers, and it's got a bunch of really cool stuff in it. There's some things that didn't quite make the spec, and it's still kind of evolving. One really cool thing that's pretty subtle is WebRTC. Have you seen this?

0:05:49.940 --> 0:05:52.600
<v B>I heard it, but I don't know what it is. Yeah, it's actually—that's all I know.

0:05:52.720 --> 0:06:54.460
<v A>It's like a thing in JavaScript where on your website you can have a video chat, like, between or among the people who are visiting your website. Okay. And so—I think HTML5 Rocks is a link to this. There's a game, a 3D game of Pong where the paddle is big enough that it has a face on the paddle, and you're actually playing, like, your face against the other person's face. Sounds painful. So it's like some kind of video conference with balls hitting you in the nose, like, every time. Yeah. It's pretty awesome. So, yeah, HTML5 Rocks is a website that is sort of like an amalgamation of all the cool things you can do in HTML5 and all the updates to the standard. So many of these things, like WebRTC—you know, when you hear HTML5, your first reaction is, 'Oh, it's like new types of tags or, like, new .html, like, structure,' right? And that's also true. But along with it comes a whole suite of JavaScript libraries that let you do just really cool stuff. And yeah, there's a link to check it out.

0:06:54.620 --> 0:07:21.025
<v B>Yeah. So I keep meaning to—I keep bookmarking all these cool sites and things I run across in other news articles and do that depth-first search or breadth-first search. Yeah. Either way I go, I just end up with all the stuff that I need to read and learn. And yeah, this is on my list. Cool, cool. So the next thing is Nissan announced that by the year 2020, Good Vision—I guess they're going to release a car that drives by itself.

0:07:22.540 --> 0:07:27.977
<v B>So Google is infamous or famous for doing this and working on their self-driving car, and

0:07:27.977 --> 0:07:30.180
<v A>driving all around California and other places.

0:07:30.180 --> 0:07:56.820
<v B>And now Nissan has said that they are going to build, like, a test facility and they're going to have multiple affordable cars that drive themselves by 2020. And I mean, this is something I get very excited about. I remember for, you know, even growing up and being young, hearing about this—they were going to embed pucks in the road and have cars that, you know, drove themselves. And it just never happened. And you needed a lot of adoption. Like, everybody needed to switch over at once. This is a massive problem. And how would you ever do it?

0:07:56.820 --> 0:08:04.022
<v A>It always involved some ridiculous infrastructure. As you mentioned, like, put a puck every foot of all highways in the U.S., or

0:08:04.022 --> 0:08:04.849
<v B>something. It's just

0:08:05.069 --> 0:08:07.260
<v A>like, yeah, it just seemed like it would never take off.

0:08:07.920 --> 0:08:17.489
<v B>And so, I mean, Nissan announcing it, Google working on it. Like, I mean, these things give me hope that, like, maybe by the time my kids learn to drive, they won't have to learn to drive. Yeah, that's

0:08:17.489 --> 0:09:13.900
<v A>right. It's pretty amazing that, I mean, that's one of those things that's really going to sort of revolutionize the way we live. I mean, one of the things that's really done it for me is along the same lines is just a smartphone and the fact that you can just look anything up at any time. And there's really no arguing over. The other day we were arguing over Stephen Hawking—whether I thought he died from Parkinson's or he had Parkinson's. He's not dead yet. But a lot of people thought he had Lou Gehrig's disease. And it turns out they were right. But, like, we saw this immediately by looking it up on the phone. And that's one of these things where it's, like, over, let's say, I guess, 10 or 20 years, you know, something has come about which has, like, completely changed our lives and the way we, you know, the way we work, the way we think. This is one of those things where a self-driving car—I mean, we'll be able to play board games on the drive to work, right? You might be willing to take a job that's an hour away because you don't have to drive yourself, right? I mean, it's just, like, live. I mean, taxi services will be totally different, right?

0:09:14.240 --> 0:10:21.300
<v B>Yeah, I mean, I think that's the big thing we don't anticipate. I think the short-term vision is, like, oh, good, when I get on the highway, I can go to sleep. Right? And okay, actually, in the short term, probably not because most of the laws seem to say you have to have a driver who's licensed and ready to take over, you know, basically there at the driver's seat and ready. Yep. But eventually, you know, that'll adapt. But I mean, I think the huge impacts will be, like, how much safer the roads are, right? Like, I don't know what happened the first time somebody gets sued, but until then, like, I mean, I think there's drastic room for improvement in reducing the number of fatalities that happen on the road. Right? And additionally, like you said, like, you know, further, like, taxi service, right? Like, why would you need to own a car that you don't use most of the time anymore if your car, a car could just be there when you're ready to take it and take you where you want to go? Yep. And it's like a taxi but no taxi driver, and you kind of remove a lot of the stigmas. Or even, like, what if an HOA, you know, your homeowners association owned, like, three cars or whatever and that was part of your community? Right? Or I mean, I don't even know, but there's all these different things you could think about. Or even just driving you to the door and then going home, right? Like, it's your car but it takes you to work and then goes home.

0:10:21.540 --> 0:10:24.500
<v A>Yeah. Or even, like, a truck. You know, so there's no parking problem anymore.

0:10:24.660 --> 0:10:31.840
<v B>Yeah. Or some weird parking structures where your car is, like, the horse where you whistle and the horse comes and gets you up, right? Yeah, right. Yeah, it's like that.

0:10:32.140 --> 0:10:39.540
<v A>Yeah, or even, like, for truck drivers, they could do something completely different, you know, while they're on the road. Like, they could be surfing the internet or something.

0:10:40.180 --> 0:11:13.460
<v B>But I don't know, but it's exciting. I'm glad to see more people getting involved in it, you know, and I hope it'll work out. It hasn't worked out that great for electric cars thus far. Like, I mean, I think we're getting better. But really, I think electric cars are doing really well. Yeah, but I think, like, in my opinion, I'm not a car enthusiast, but, like, I mean, Nissan produced the Leaf, which was a failure. Right? Right? And it kind of seems like maybe they regretted it. Tesla's doing well. Yeah. But, like, other car manufacturers haven't, like, gotten excited and also actually made legitimately good electric cars.

0:11:13.720 --> 0:11:23.740
<v A>One interesting thing, I was reading an article on Quora, and the question in Quora was, for people who don't know, Quora is a social kind of networking type site.

0:11:23.740 --> 0:11:25.480
<v B>Stack Overflow for non-programming questions specifically.

0:11:25.480 --> 0:12:28.000
<v A>That's true. That's a great way to explain it. That's exactly what it is. So someone asked the question, what is the thing about your job that's, like, pretty common knowledge, but to the rest of the world would blow their mind? And the number one answer was that batteries and, you know, storing energy are following Moore's Law, which had never happened in the past. It's just kind of over the past 20, 30 years they've been following Moore's Law. For people who don't know, what Moore's Law means is for the same price, you can do twice as much every 18 months. So, in other words, for a long time, processors were following Moore's Law. So if you had, say, a 100 megahertz processor was $100, 18 months from now, you could be pretty certain that a 200 megahertz processor would be the same amount, $100, whatever I said. So batteries are doing this now. And so what that means is, you know, effectively, however much of the Tesla car is the battery, let's say that's half the cost. I don't know what it is. Let's just pretend. That is going to go down in half. Like, you know, in three years, it's going to get cut into a fourth of what it is now.

0:12:28.220 --> 0:12:31.780
<v B>Or it'll go down by half and be twice as high capacity.

0:12:32.339 --> 0:12:45.295
<v A>Right. Yeah. Like, yeah, that's right. Or you would have twice the capacity at the same price. Yeah. That's another way of looking at it. Yeah. But, yeah, I feel like it's still early, but I regret not buying Tesla stock. Let's just put it that way. I'm

0:12:45.295 --> 0:13:01.340
<v B>pretty excited about it. Yeah. Don't give a start on that. I don't know what it will be in the future, but it's done well so far. Yeah. I hope you'll say the same thing about a self-driving car startup, right? Yeah. It'll do something awesome or Google or Nissan or whoever. I mean, I think it's one of these things that it's good to have it happen.

0:13:01.580 --> 0:13:02.912
<v A>Right. Definitely. And you

0:13:02.946 --> 0:13:07.240
<v B>Know anybody who's working on it, I'll be a cheerleader for it at some level.

0:13:07.500 --> 0:14:23.440
<v A>Yeah, definitely. I think it's great. So, okay, my article is 'Analysis of Flight Dataset.' And this was pretty cool. It was from MongoDB's blog. For people who don't know, MongoDB is a NoSQL database. I think we talked about it. We talked about this on our SQL episode. But they also have this blog where their interns kind of write about cool things they do with MongoDB. And this blog in particular is, I think, really interesting because it's very simple, very easy to read. And you know, a lot of people don't really know what data mining is. It's sort of an overused, very nebulous term. And you know, this is sort of a pretty easy example where they got access to—they didn't get access? I mean, it's open access to all the flight data from all the airplanes that have flown, commercial airplanes that have flown in America over, I think, the past year or so. And it's just a series of cool things they do with that data, like they explore the cascading effects of delays and things like that. I thought it was a really good read—pretty simple, pretty fun. And it uses very simple MongoDB queries. It's not doing some kind of crazy, you know, logistic regression or something like that that you have to pour through a manual to understand. So, yeah, give it a shot. Take a look at it. And you could actually redo all of the experiments yourself.

0:14:23.660 --> 0:14:25.160
<v B>Yeah, this is really interesting. I'm looking at it now.

0:14:25.617 --> 0:14:25.870
<v A>Yeah,

0:14:25.870 --> 0:14:28.180
<v B>Yeah, totally. It kind of makes me want to have a lot more time.

0:14:28.760 --> 0:14:34.180
<v A>Yeah. If they can figure out a way to data mine another hour in my day, that would be pretty epic.

0:14:35.740 --> 0:15:23.960
<v B>Well, okay. I don't want to get sidetracked. That's something interesting. They have that—what is that, the quantified self movement, which is not exactly what you're saying, but similar, which is like, in order to find where you should improve, you first have to track all this stuff, right? Like, if you had more information about how you live your life, you could do that. Like, right now, if you ask that question, how would you even start? You don't have any data, right? So, there's like a group of people out there trying to track basic metrics about themselves—their weight, their what their activity level was, how they feel, like any sort of varying set of parameters over time. So, they can analyze themselves and say, you know, 'How do I do better?' Oh, on days I drink coffee, I feel better immediately, but worse overall, right? You know, so I should stop drinking coffee or things like that.'

0:15:24.140 --> 0:15:33.120
<v A>Yeah, totally. Yeah, I mean, if they can find out certain things you do that cause you to lose a lot of time, then yeah, it's basically giving you free time if you can fix these things.

0:15:33.640 --> 0:15:38.567
<v B>Yep. Although, maybe you'll be more efficient and less happy, and then you'll wish you had it. Yeah,

0:15:38.635 --> 0:15:42.160
<v A>That's right. You shouldn't have surfed the internet ever.

0:15:42.720 --> 0:17:22.480
<v B>No. No. So, the last thing in news here is, recently I saw this book—well, I guess a book, online book, e-book released as PDF—all those different formats about Bayesian statistics was released, called 'Probabilistic Programming and Bayesian Methods for Hackers.' I hope I just messed that up too. That sounds good. And it is interesting because not only is it a good read—I've only read through about, I think, the first chapter so far. And so far, it's really good. Mostly stuff I know about covering it really well. And they have this cool thing, which I had seen several times since now, where you kind of embed Python charting in the HTML or whatever. Oh. And so it actually will run a different per run or whatever, but actually show you a graph that is generated from Python when you load the page. At least I think that's what it's doing. Cool. And the PDF, of course, has them just statically generated. But this is pretty cool. And I think later ones, I believe, have even some like interactive things where you can change some stuff and see what happens. And you know, able to tell kind of different parameters effects. Like, if you flip a coin 50 times, what about 500 times? You know what happens. Oh, nice. And just in general, Bayesian analysis—there we go, is left off. I mean, maybe Jason could talk more about this because I think he's been doing some stuff with it. But you know, when I was in high school, we learned a little bit about statistics, but definitely nothing about Bayes. And then even in a statistics class, I think it was mentioned as like a side note. I didn't take in-depth statistics. It was just a basic statistics class. And we did a lot of the conventional—what is it called? Stochastic statistics? Is that what it's called? Frequentist. Frequentist. Okay, whatever that thing is. Anyways, yes. We did a lot of that, but we did almost none other than just cover Bayes' theorem, like what it was. And then we moved on.

0:17:22.520 --> 0:17:25.280
<v A>So do you remember Bayes' theorem? I'm going to hold you to the chopping block.

0:17:25.280 --> 0:17:35.700
<v B>It's like the probability of A given B is equal to, and then, yeah, I could probably sit there and think about it for a minute. But it's like probability of B, probability of B given A divided by something.

0:17:35.940 --> 0:17:37.560
<v A>Yep, divided by probability of A.

0:17:37.840 --> 0:17:38.430
<v B>Ah, okay. Yeah,

0:17:38.430 --> 0:18:15.960
<v A>So just to recap. I got close. I did learn something. So Bayes' rule is like the fundamental theorem behind what's called inferencing, which is the basis of prediction and Machine Learning, right? So the idea here is, so the equation is, as Patrick mentioned, is probability of A given B. So imagine, like, probability that it rained today given that it rained yesterday is equal to the probability that it rained yesterday given the probability it rained today. So that's flipping those two around, like flipping what's here.

0:18:15.977 --> 0:18:20.700
<v B>Which was the hard part for me because it was like, how do we improve things by flipping it?

0:18:20.740 --> 0:18:20.980
<v A>Right.

0:18:21.200 --> 0:18:22.400
<v B>It was not intuitive to me.

0:18:22.560 --> 0:20:07.032
<v A>Yep. So I'll get to that. Multiply by the probability of A over B. And so those two are pretty easy to figure out, right? So the idea here is, in one, you're going forwards. Like A given B means what is it today given yesterday? You're going forwards in time. And so if you were to go another step forward, like, you know, tomorrow given today, that's really sort of that's forecasting, right? But the probability of B given A is going backwards. So that's like saying, using data that you've already seen, how can you—or wait, yeah, I got this right. So, yeah, probability of A given B is going backwards, which means, given data I've already seen, how can I revise my new probability? And so what it does is, obviously if it rains one day, it's probably more likely to rain the next day. You know, because typically clouds hang over a place for more than 24 hours, right? Depending on where you live. But so you might start off with, say, what's called a prior distribution, which is, I don't know. Like you could use, for example, say a Beta distribution or a Normal distribution, which says, look, I don't really know. I have a 50-50 chance of it raining, and I don't really know if the fact that it rained yesterday really matters. But then by observing several rainy days in sequence and applying Bayes Law, you can come up with a new distribution, which is skewed towards, you know, it raining several days at a time. So it's kind of a hard thing to grasp. There's definitely a ton of awesome articles on Bayes. But this, I get the impression that these guys all do a really good job. I haven't read this one in particular. Okay.

0:20:07.032 --> 0:21:07.900
<v B>Yeah. So, I mean, the thing for me, too, like, at least in this introduction, and I intend to go through more, given more time, but recently that's been in short supply, is that, you know, it is kind of, Jason was saying there, I guess, frequentist is the other way where you something happens and you count how often it happens or whatever versus kind of the base. It's actually a different but equally valid way of looking at the world. It's just like two sides of a similar coin. Like, they're both trying to describe, and some have advantages and disadvantages. But the fact that I only ever had one, I guess, I kind of felt like it was missing. Like, there were certain things, like, I would get to it. I wouldn't know how to even think about them properly. It was like, oh, that's just because, like, you know, I only had the tool of applying the Normal probability that you think about. Like, it's 50% likelihood that if I flip this coin, it'll land on heads or whatever. Right. Right. And now, that's the only way I had to think about it. So having another way to think about it, even if I don't remember the specific formulas or code it up, is helpful because sometimes it reveals nuances to a problem or ways of thinking about something. That's been really helpful to me.

0:21:07.920 --> 0:22:15.000
<v A>Yeah. There's many domains which are, I guess, for lack of a better word, I'll say soft. Like, for example, poker. With poker, it's very stochastic. I mean, you don't know what card you're going to draw. If you did, then you just win, right? I mean, well, you wouldn't always win, but you would play very well and make a lot of money, right? The reality is you don't know what card is coming next. And so when you have these very soft environments, what's more interesting than, say, a frequentist, which will tell you, oh, you should probably, you know, you should probably bet more. You should probably raise. It's sort of having a confidence. So if you have, if your output is a distribution, then you can say, you know, the mode of this distribution. So in other words, like what I think you should play is, let's say, raise $15. But you have this huge uncertainty. Or, you know, I'm holding pocket aces. There's two more aces on the table. I have four of a kind aces. Now I have virtually no uncertainty, right? So you can think of Bayesian as sort of living in this realm of distributions instead of numbers, instead of like what's called point values. And that lets you do a bunch of really interesting things.

0:22:15.360 --> 0:22:45.049
<v B>Yeah. And you can do some of it. It's been my impression anyway. It's like the stuff that you can do in one, you can do in the other. It's just how easy or hard it is. So you can do confidence intervals and distributions, you know, in the, I don't want to call it traditional because I don't think it's the right way. But in the frequentist view, right? Like you can't do that stuff. But it was always like the most complicated thing we always did at the end of the semester. Yeah. Like, you know, it was very difficult to do. But in Bayes, it seems to come naturally. Like once you get everything set up, which might be a little more tricky, like all this other stuff comes for free essentially. Yeah.

0:22:45.340 --> 0:23:33.632
<v A>I mean, like the unit of your operations is a distribution. It's like you're working with functions. So in other words, like, for example, if you add to normal distributions, you get a normal distribution with the, you know, average. Or I think it's like the sum of means being the new mean or the average of means and the sum of the variances being the new variance. But the point is like there's operations that you do on distributions rather than on numbers. And that can be really hard. Like, for example, you can't take the product easily of two different distributions. Like if you have a logistic distribution and normal distribution and you try and take the product, there's just no closed form for that. And so in these examples, like you have to do like Monte Carlo methods. I don't know. Does this get to those? Monte Carlo. I don't

0:23:33.632 --> 0:23:38.273
<v B>know. MCMC and all of that. MCMC, yes. Opening the black box of MCMC. Oh, well, there.

0:23:38.273 --> 0:23:42.380
<v A>You go. Yeah. So it's hard. Markov Chain Monte Carlo. Yep. I know.

0:23:42.440 --> 0:23:43.217
<v B>I know what you said. Nice.

0:23:43.940 --> 0:24:32.475
<v A>But then the output is just so awesome, right? I mean, think about that. Like now you have not only an answer, but a distribution over all the possible answers that could exist. So if you're writing, say, an AI to play Monopoly or something, you know, you don't want like you don't want something like what's the minimum amount of like how many houses should I buy? So I don't get, you know, knocked out and have to mortgage. Right. Well, that there's no clear answer because it depends on the dice. Right. But if you use Bayesian, now you can come up with some kind of distribution that says like, oh, I have, say, a 90% confidence I'm not going to have to mortgage and I can buy three houses in my Monopoly game or whatever. Right. So, yeah, it's pretty awesome. I'm definitely going to have to check this out and brush up on my Bayes. All right. With that in mind, let's go to Book of

0:24:32.475 --> 0:24:34.540
<v B>The Show. Book of the Show. Show. Show.

0:24:35.540 --> 0:25:32.280
<v A>My Book of the Show is I have also been looking into Bayes for a variety of reasons, which is why you have so much to say about it. One of them being that I need to get confidence intervals for some systems I've been working on. And so I've been reading a book that is pretty heavy. So I'll give you a little bit of a disclaimer: it's a heavy book. I definitely recommend, you know, I think Google Books has it. You can read the first like 50 pages without buying it. Right. On the flip side, it's very thorough and you need no background. So in other words, if you're willing to slug it out, you won't have to be a Bayesian expert to understand this book. But it is going to make you a Bayesian expert. So it's definitely a heavy read: Computational Bayesian Statistics. I think it's by—let me look it up—it's by a guy in New Zealand, actually, who's pretty famous for this stuff.

0:25:32.280 --> 0:25:38.060
<v B>So this will cover what we've been talking about in exhaustive and dry detail, it sounds.

0:25:39.460 --> 0:25:50.560
<v A>Yeah. And I mean, it. But that's good. It has one cool thing: it has a bunch of pictures. Like it has like pictures of distributions, things like that. You can see sort of. So the author is William Ballstad.

0:25:52.139 --> 0:25:52.180
<v A>And.

0:25:52.280 --> 0:25:55.620
<v B>Okay. Understanding Computational Bayesian Statistics. Exactly.

0:25:56.100 --> 0:25:58.020
<v A>And it. Oh, yeah. It has understanding.

0:25:59.639 --> 0:26:14.029
<v A>But I will post a link in the show notes that you guys can click on and check it out. I'm reading it now. It's an awesome read. It covers everything in great detail. You don't have to be a math genius or anything to figure it out or to follow along. And it's

0:26:14.029 --> 0:26:24.860
<v B>Highly recommended. But there's this other one with puppies doing Bayesian data analysis. With puppies? It has puppies on the cover. Oh, man. Is it a distribution of puppies? There are three puppies.

0:26:25.040 --> 0:26:27.600
<v A>Oh, man. Okay. Get the puppies book.

0:26:29.360 --> 0:26:29.487
<v A>Never.

0:26:29.487 --> 0:27:10.037
<v B>Mind. We're always playing along at home. So my book is one called Going Postal. It is not a serious book by Terry Pratchett. So this is part of the Discworld series, which I haven't read a lot of books. But I've read like I think three or four. Same here. Books from Terry Pratchett. And they're a series set in this universe of craziness. That's all I can describe it. Maybe I'm missing a lot of the jokes. Probably am. It's not unusual. But it's kind of just like silly adventures in this fantasy world. Right? But the fantasy world makes fun of itself. So there's like trolls that are making fun of troll tropes or whatever. Right? There's a

0:27:10.037 --> 0:27:30.040
<v A>Hydra used chariot salesman. And Hydras have seven heads or whatever. Yeah. And his name is Cut Me Own Throat Dibbler. And if you can find a cheaper deal, he'll cut one of his own heads off and grow ten more. And grow ten more. Yeah. But he's like that's his threat. You know, you find a better deal, 'Cut me own throat.'

0:27:30.780 --> 0:28:00.700
<v B>Yeah. So there's some amount of British humor in it. So I equate it a little bit to Monty Python style. Yeah. That's probably terribly unfair to someone. I'm not sure who. But this book is interesting. And if you like kind of a lighthearted read, that's just fun. When you get to the end, it's not like you can tell somebody you had this deep story that was an epic event. It's just kind of like a fun ride to read along and see what happens and the adventures of the people and the characters will recur in various stories even if the stories themselves aren't really sequential.

0:28:01.380 --> 0:28:07.969
<v A>Yeah, definitely. I mean, in fact, there's an order. There's a reading order guide online. Oh, okay. It's called The L Space. I

0:28:07.969 --> 0:28:10.040
<v B>should probably follow that. I just read them randomly.

0:28:10.360 --> 0:28:21.540
<v A>Yeah. It doesn't matter. But if you read in a certain order, you can catch all of the cameo appearances in the right order. Like you can see a cameo appearance of a character and know what they've done already. Oh.

0:28:22.100 --> 0:28:22.971
<v B>Yeah. That would probably make

0:28:22.971 --> 0:28:30.520
<v A>more sense. And it's not like a normal order. It's kind of like you have to read in kind of a wacky order. Okay? But yeah, the books are amazing.

0:28:30.740 --> 0:28:32.580
<v B>Yeah. It's definitely a lighthearted read.

0:28:32.940 --> 0:28:35.060
<v A>So is this one about like The Postman or something?

0:28:35.320 --> 0:28:38.969
<v B>Yeah. Going Postal? Yeah, yeah. So about this postal guy. Awesome.

0:28:39.140 --> 0:28:40.234
<v A>I don't like sharing too much.

0:28:40.234 --> 0:28:42.260
<v B>About books. Yeah, we won't spoil it because then I feel like, yeah.

0:28:42.260 --> 0:28:51.180
<v A>I definitely spoiled my Computational Bayesian Statistics. Oh, man. You guys know the ending. In the ending, you understand Bayesian Statistics. Bayesian Statistics. Spoiler.

0:28:51.860 --> 0:28:53.100
<v B>Well, hopefully you do anyways.

0:28:53.500 --> 0:28:55.202
<v A>Yeah, or at least you've seen a lot of cool pictures. All

0:28:55.202 --> 0:28:55.962
<v B>Right. Time.

0:28:55.962 --> 0:29:36.540
<v A>For tool of the show. Tool of the show. So this is a total cop-out. I'll be the first one to admit it. My tool of the show is two apps. It is two... My tool of the show are two apps. Anyways, my tools of the show are two apps that I wrote. One is NES Together, and the other one is SNES Together. And as the name suggests, it's a way for you to play Nintendo and Super Nintendo games together with someone else on another Android device. So for example, I can take my phone, start up NES Together, pick an NES game like Ice Hockey or, I don't know, Contra or something, and then invite Patrick. He can join, and we'll both be playing Contra together.

0:29:37.339 --> 0:29:44.700
<v B>I see you post about this sometimes on Google+, and I'm very envious that you have so many friends to play old arcade games or old Nintendo games with.

0:29:44.899 --> 0:29:54.000
<v A>Yeah, I've been doing emulators for a long time, so I've kind of built an audience and a community of people who are really into emulators, so there's always kind of somebody there.

0:29:54.248 --> 0:29:56.360
<v B>But you have your own hacks in the system, so you always win, right?

0:29:56.700 --> 0:30:04.560
<v A>Totally. Nice. Yeah, I just Ice Hockey hack, or it just sets the score to whatever I want. Every time I press volume up on the phone, I score a goal.

0:30:04.560 --> 0:30:06.940
<v B>How did that happen?

0:30:07.419 --> 0:30:25.100
<v A>Yeah, trick shot. But yeah, I think it's pretty fun. You know, a lot of these NES emulators are great, like NES OID, the Android NES emulator is phenomenal. I'm not trying to compete with them. They have a great emulator. But none of them use the phone's internet. Like, all of them require Wi-Fi.

0:30:25.460 --> 0:30:25.760
<v B>Oh.

0:30:26.120 --> 0:30:32.976
<v A>And so that's sort of the niche there, is that you can just, you know, be on a bus and start up an NES game with your friends. So you

0:30:32.976 --> 0:30:34.980
<v B>can rack up your bill while you play.

0:30:35.659 --> 0:30:36.100
<v A>Exactly.

0:30:37.500 --> 0:30:40.030
<v B>Jason's getting a cut from the cell phone carriers. Yeah,

0:30:40.030 --> 0:30:41.959
<v A>Verizon totally has a deal worked out.

0:30:42.580 --> 0:31:08.140
<v B>So my tool to show is Joda, the Java time library. I actually don't know if they have one for C++, but I know of Java for sure. No, just Java. And so I'm terrible at calendar math and doing all things time related. Oh, yeah. It's so hard. And handling things like leap years. Yeah. And Daylight Savings Time. Oh, yeah. It's really messy to begin with. And it's still messy when you use Joda, J-O-D-A.

0:31:08.220 --> 0:31:11.440
<v A>Didn't they change Daylight Savings Time? Like, something happened.

0:31:11.460 --> 0:31:15.700
<v B>It was like leap seconds or something? Oh, yes. Like, a few years ago, yeah. Yeah, something happened. They changed how it's done.

0:31:15.900 --> 0:31:17.695
<v A>Yeah, right. So I mean, like, trying to

0:31:17.695 --> 0:31:19.320
<v B>Keep up with that. Anyways, I don't know.

0:31:19.460 --> 0:31:21.379
<v A>Yeah, it's just, that's kind of like a nightmare.

0:31:21.720 --> 0:32:00.860
<v B>Yeah. So this Joda library is a set of Java utility function things that allow you to manipulate times and do things like, what is today minus five days or minus one month? And, you know, set it and handle it appropriately for things like if I'm at March 1st and I subtract today and it's a leap year, it's different than if it's a non-leap year when I go to February. Right. And handling all that stuff and doing it in a way which is at least semi-readable and approachable. And I really have been doing a little bit more than normal with it and appreciate how much less time I have to sit there thinking about, am I doing this correctly when I can just use the library?

0:32:01.340 --> 0:32:18.968
<v A>Yeah, I mean, this stuff is like a total disaster. Like, time stuff is just so hard. And this library makes it so easy. I mean, I think that, I don't know if you do this, but I always do everything in, I think it's called like USEC or something or MSEC. But it's basically

0:32:18.968 --> 0:32:21.880
<v B>like that System.currentTimeMillis. Unix Epoch, yeah.

0:32:22.040 --> 0:32:28.100
<v A>Yeah, right. So I do everything in that and at the last minute I use JodaTime to like convert that to something reasonable.

0:32:28.100 --> 0:33:03.800
<v B>Yeah, so we have some stuff that looks at data over the past and tries to accumulate like in the last seven days or last calendar month or last quarter. And for a long time before, you know, we undertook effort to really make sure we were stringent about how we treat time. And it was like without fail, every end of month or every quarter, unit tests would just start failing. You know, and like it wasn't really that there was a problem. It was normally that just the test was broken. But it sometimes did reveal that we had legitimate problems where our data wasn't being calculated correctly or we'd miss a day here or there. Gotcha. Of course, that's really, really bad.

0:33:04.020 --> 0:33:27.840
<v A>Yeah, totally, totally. Yeah, that's just a total nightmare. I mean, you think about it like let's say you were, say, Groupon or something and you tell someone, oh, you know, this offer is going to be here until midnight. Well, like what does that even mean? I mean, like if I'm in Florida and I take a plane to California, my midnight has just changed, right? I mean, it's like dealing with this stuff is such a nightmare and Joda definitely makes it a lot easier.

0:33:28.300 --> 0:33:31.547
<v B>Yep. So I think we're on to CUDA and OpenSea. All

0:33:31.547 --> 0:33:48.159
<v A>Right. So this is something that Patrick and I have done a lot of in our past life. And hopefully we remember a lot of it. But yeah, it's a pretty awesome, very powerful set of utilities. So I'll cover some of the history maybe.

0:33:48.639 --> 0:34:15.279
<v B>So firstly, I guess we should say that CUDA and OpenSea both are ways of using the GPU, the graphics processing unit in your computer to do something besides draw your 3D video game. Right. So some of it may work with images or representations of images. But for the most part, you're doing general purpose, you know, things which aren't related strictly to what the GPU was initially designed to do.

0:34:15.540 --> 0:35:46.720
<v A>Yeah, exactly. Exactly. And so when GPUs came out, they really revolutionized gaming, right? I mean, I remember Dungeon Keeper 2 or Half-Life 1. Yes. Okay. Yeah. So those were like right on the era where GPUs were coming out. Like Half-Life 1, you could either use a software render, which used your CPU, or it supported Glide, which was one of these early GPUs. And the idea is they're very specialized. They work with—there's two sort of elements in this pipeline: there's a vertex shader and there's a fragment shader. So again, these are meant for doing graphics. And we'll get back to how they can do general stuff. But the vertex shader, so we're real quick on how computer graphics works. Everything is a triangle in computer graphics. Everything is just a bunch of triangles. The three points of the triangle are called vertices. And so you have sort of an army of these vertices, just these triplets of vertices. Like vertex A, B, and C make a triangle. D, E, and F make a triangle. And they all flow through the system and get transformed. Like one possible transformation is, you know, if you're playing like a first-person shooter and you turn your head 90 degrees. Well, the way the graphics processing unit handles that is it rotates the whole world in the other direction 90 degrees. And so every vertex gets rotated in space to, like, counteract your rotation and make you feel like you're turning, right?

0:35:46.799 --> 0:35:48.839
<v B>And that rotation is a matrix operation.

0:35:49.220 --> 0:36:53.900
<v A>Right. That's right. So the vertex can be represented as a vector of three elements, you know, an X, Y, and Z component of the vertex. And then, right, any operation that transforms a vertex is a matrix operation. So, like, rotation, scaling, transformation—these kinds of things. So there's a vertex shader. Once all the vertices have been transformed, then they get crushed into the screen. So you can imagine sort of, like, all the vertices in your screen, but they're all in 3D, so they're all kind of these projections. Then they get crushed into 2D. And then what happens is something called a fragment shader starts at, looks at your three vertices and looks at every pixel that is within that triangle. And then, based on a bunch of different things, figures out the color of that pixel. So, for example, a triangle might be red, but there's a blue light shining on it. And it's facing that blue light. So the fragment shader will sort of use all this data to sort of figure out, like, for this particular point in space, like, what the color should be.

0:36:54.020 --> 0:37:00.960
<v B>So is that also the part responsible for determining, like, oh, it's on the shadow side of the light or facing the light? Right. Yep.

0:37:01.340 --> 0:37:10.382
<v A>And also, you know, some triangles might be one-sided. So if you're facing, like, the back of the triangle, then it won't draw it. This is called, like, backface culling and things.

0:37:10.382 --> 0:37:17.900
<v B>Like that. So this is like, oh, you're looking at a cube, but you can only see some portion of it at any given time. Exactly. You know where you can stand where you see all of it.

0:37:17.980 --> 0:37:30.820
<v A>Right. So the back part of the cube, they won't draw. Okay. And so that's actually—that might be done in the vertex shader. But at some point, like, one of these shaders is responsible for saying which triangles exist, like, should be drawn and which shouldn't.

0:37:31.320 --> 0:37:55.400
<v B>Which is really hard because I remember, I think it was in the first Half-Life, they had, like, a game editor, and they would talk about this. Like, you needed to be careful to place things to block so that the algorithm could decide, like, the thing in the next room isn't visible. Right. So, like, if you drew, like, a door and a wall and you left, like, a tiny gap, like, just two things kind of touching each other. But there was a slight gap there, the algorithm might start attempting to draw all the things in the next room.

0:37:55.560 --> 0:37:55.780
<v A>Yep.

0:37:55.980 --> 0:37:58.340
<v B>And that would make it go really, really slow.

0:37:58.600 --> 0:38:22.839
<v A>Yeah, definitely. Definitely. So, the point is that the people found that this was really useful, and it's very fast. So, one thing that you can think about is, like, as I mentioned with all these operations, like, let's take a vertex shader. You want to take sort of all these vertices and rotate them to fit the way your head is rotating. But you want to do the same rotation on every vertex. So...

0:38:22.839 --> 0:38:29.920
<v B>Where here you're saying head and also meaning camera, right? Oh, yeah. So, not just, like, the model's head is turning, but you're talking about, like, the camera is turning.

0:38:30.240 --> 0:38:35.500
<v A>Exactly. Yeah. So, yeah. So, you're playing some FPS, and you're in the... The camera is sort of where you're

0:38:35.567 --> 0:38:36.023
<v B>looking at.

0:38:36.023 --> 0:38:41.963
<v A>eyes, yeah. Yeah, and your eyes are turning. What's really happening, the whole world is turning. And so, they're doing the same thing on every vertex. Wait, that's what

0:38:41.963 --> 0:38:42.760
<v B>happens to be in real life.

0:38:43.200 --> 0:38:44.280
<v A>The whole world turns?

0:38:44.280 --> 0:38:47.320
<v B>Yeah, yeah. In your head? Really? I'm pretty sure.

0:38:48.100 --> 0:38:55.880
<v A>This is one of those, like, unprovable things, right? Like, nothing exists. Like, I'm in a dream world right now. Have you seen this? Like, an undefeatable argument.

0:38:56.520 --> 0:38:59.024
<v B>No. I think there's a Wikipedia page on this. Yeah, okay. Maybe I should use this. But,

0:38:59.024 --> 0:40:27.640
<v A>Yeah. So, the GPU is highly optimized for doing the same thing on a bunch of different inputs. And, you know, that is actually really useful. I mean, look at, say, machine learning. You might do, say, linear regression, where you want to compute, you know, huge dot products of many variables. So, you want to take a bunch of variables and add them together, or take a bunch of variables and multiply them by something. So, you could do this much, much faster on a GPU than on one CPU. So, people started realizing this and started coming up with all sorts of cool things to do on the GPU that aren't graphics related. But this involved a really, really painful process. So, what they had to do was, you know, convert all their input data to images. So, find some way to put, you know, their math, their, like, you know, going back to the machine learning thing. Find some way to put the weights of their matrix into, you know, a texture on an image. And then, they have to turn off all the special effects because they don't want, you know, lights to be shining on their weight matrix or something like that. It just doesn't make sense, right? Or, oh, as you, as the triangle gets further out, your weights get smaller because of fog. I mean, it's just like crazy. So, you have to turn off all these, render a frame, and then the fragment shader, you know, which is drawing all these pixels on the screen. And that fragment shader will be doing something crazy, like a dot product or something, and putting the answers on the screen in pixels. Then you have to read the screen and interpret that.

0:40:27.960 --> 0:40:37.740
<v B>Yeah, because the GPU often draws directly to the monitor. Like, it is the thing you plug the monitor into, so it has a little bit of memory that holds what everything on the monitor should be.

0:40:37.940 --> 0:40:44.037
<v A>Right. Yep. So, this is really hard. And so, CUDA and OpenCL are ways

0:40:44.037 --> 0:41:02.360
<v B>to... And really, nobody did this. Like, I mean, there were people doing it, like crazy hacker people. Like, you know, awesome guru people and, like, very specialized one-off custom things that they would do. But then any time there was a change in the library or a new graphics, you know, GPU came out, like any of these things, it would completely just mess them up. Because it wasn't... Right. They weren't doing something supported.

0:41:02.720 --> 0:41:46.720
<v A>Right. They were doing something that was like specific to one particular card. And also, like, many of the tasks were graphics-related anyways because those are only people who knew how to program them. Like, I did one thing as part of my Master's thesis, which was like a bouncing light from one place. So, in other words, like, a light shines in and it radiates the whole room. And it was just like... Like, I was only able to do this because of the background and graphics. Like, just nobody could understand like this crazy mess of code. And you have to manually do things like disable fog. Otherwise, your answers were wrong. You didn't know why, right? So, CUDA and OpenCL are a way to sort of relieve us of having to be graphics programmers to do basic things.

0:41:46.840 --> 0:41:49.040
<v B>Which is a good thing because otherwise I never would have been able to do it.

0:41:49.240 --> 0:41:52.836
<v A>Yeah. Totally. Totally. So, you want to cover... Yeah. So,

0:41:52.836 --> 0:43:51.879
<v B>I mean, so the idea is just an abstraction on top of this thing. So, there now, it is true that I guess there's enough people doing this where they make special allowances in this hardware, these very specific pieces of silicon that are made to do this graphics processing to allow for this general-purpose processing. But initially, it's just kind of an abstraction. It's like we have this very specific... And maybe we'll talk about this in the next episode. But kind of, like, you have a general-purpose CPU which can do anything. Then you have these very specialized CPUs which don't have a lot of operations because you either have to simulate them or, you know, have to add essentially and and or gates to represent how to do that thing because the processor just isn't used to doing it because it's not needed for shading and lighting. But as they got more and more sophisticated and more capable, it turned out that people wanted to do crazier and crazier things in both the graphics arena and the normal. And so, people realized it was beneficial to have this abstraction where you could essentially shove any array into the graphics processor and then have what CUDA and OpenCL are mostly about as kind of a way to compile normal C code that operates on a matrix, compile that into a series of graphics operations for those graphics processors to operate on. Right? And then a way to get the data back out without having to... A supported way as opposed to, tell me what should be on the screen right now. Yeah, right. And the benefit of that is that these GPUs not only are they really fast because they do very specific things, but there tend to be a lot of them. Like, I mean, just now we're getting into like people having like eight CPUs in our computer or maybe 16. I don't even know. I don't even keep up with it. A lot. But, I mean, you can easily have like I don't think like when we were doing it, there was like 128, 256, 512 processors. Yeah, they're up to like 1,000 now. Like, 1024 processors. Yeah. Those processors can only do very specific things, but you have a lot of them. Yeah. Which can be a huge advantage.

0:43:52.419 --> 0:44:43.746
<v A>Yeah, definitely. I mean, the big tradeoff here, you know, people say, well, why isn't everything in a GPU, right? And so the tradeoff is, as Patrick was alluding to, so there's only, so the threads are grouped into warps. There might be like 1024 processors or 1024 threads, let's say processors, but they're grouped into blocks of 32. And for a particular block of 32 threads, they can only be doing one thing at any one time. So, in other words, if you have some data and on, you know, the first index, you have to do one thing. On the second index, you have to do a second thing, so on and so forth. Like, it's specific to each index. It's going to take you 32 times as long to do that because, you know, the first processors are going to work on the first, you know, bit of data, and all the other ones are going to wait. And so, in this case, the GPU would be really slow, like, much slower than the CPU.

0:44:44.200 --> 0:45:24.720
<v B>Yeah, it's like if you had a single number. Like, if you had, you know, I have one number, and I want to do these couple of math operations and some branching and then some other math, right? And then I want to run some, like, I'm starting at my program or whatever. That set of operations isn't suitable to the GPU because they, although there's many of them that can run in parallel, each one isn't necessarily as fast as your, as a regular processor at getting a single thing done. Right? So, the advantage is that you can do a lot of things at once. And also, it brings out, because this graphics stuff doesn't have a lot of decisions that need to be made, they're typically, their performance at having branching operations, like an if statement or a for loop, like, those kinds of things start to get a little hairy.

0:45:24.940 --> 0:45:25.160
<v A>Yeah.

0:45:25.280 --> 0:45:27.600
<v B>So, some for loops are good because you can unroll them.

0:45:27.720 --> 0:45:27.920
<v A>Right.

0:45:28.100 --> 0:47:19.279
<v B>And run them, but like a for loop where you're... So, what's unrolling? Oh, okay. So, initially, a for loop is, and this gets into like understanding how computers operate. So, the processor doesn't understand what a for loop is, really. So, what it knows is, okay, I'm going to consider some conditional statement. Is this number in this register more or less than this number in this other register? If it is, branch. If not, execute the, you know, next following statement. Increase the program counter by one or whatever. And so, what loop unrolling says, instead of having to, when you get to the end of the for loop, jump back up to the beginning and execute this conditional again. If your for loop is, for instance, I have a known 1,000 entry array, and I want them to be the number one, the number two, the number three, you know, one plus their index, essentially. If I want that to happen, I already know in advance I'm going to have to do this, what did I say, 100 times or 1,000 times? Sure. 100 times. So, instead of having a loop which says, you know, check if, you know, my current counter is less than 100. If so, do this, then jump back up, right? This code running over and over. You can just do all of that all at once. So, you know, set array 0 to 1. Set array 1 to 2. Set array 2 to 3. Set array 3 to 4. And if you listed all those in order, there's less instructions. If you count actually the number of cycles taken by the CPU, it's a lot less. Right. It used to be much more beneficial, but then CPUs got better and better at understanding that, for instance, if I'm in this loop 1,000 times, there's a very high probability next time I've come to it, I'm going to do the next thing already. And so it knows that. Right. So loop unrolling, in this case, would say, like, oh, if I'm going to do this set of operations in the GPU, like, actually just make them set instructions instead of this branching, which confuses the GPU at some level because it's expecting all of the pixels to be going through the same operations at the same time.

0:47:19.440 --> 0:47:35.120
<v A>Right. Exactly. And if you want to know, you know, based on how many times you've been through a for loop, what is the chance that you'll go through the for loop again, you can read Understanding Computational Patient Statistics where they go over exactly this kind of problem.

0:47:35.220 --> 0:47:39.240
<v B>And the reason you need that is to do pipelining and all this stuff. Yeah.

0:47:39.400 --> 0:47:53.961
<v A>So to your point, the GPU does not have very good pipelining. So in other words, like a CPU will do all sorts of crazy things like, I think, branch prediction where it will actually take both paths of a branch as long as it doesn't have to write anything to memory. Well,

0:47:53.961 --> 0:48:24.040
<v B>Yeah. What it'll assume is, it'll assume in that for loop, it'll assume you're going to go ahead and do the next array operation and actually start doing that operation when it still hasn't figured out if it should or not. Right. And then once it figures out it should, then it just goes ahead and keeps an answer. If it figures out, oops, I wasn't supposed to do that, it has a way to essentially flush the pipeline. Right. And then load whatever the other instruction was supposed to do instead. Right. Like load that now. But the problem is you lose all that time you should have been doing those other operations.

0:48:24.560 --> 0:49:05.919
<v A>Right. Yeah. So the GPU, because it has so many threads and because of the ways designed with this intuition that all the threads do the same thing at the same time, it doesn't have any of this. Like it doesn't have branch prediction. There's a lot of things like this that it does not have. And so to Patrick's point, if you have a branch, let's say you have a branch, like if I am, you know, operating on the first of this array of data, then do something special. While you're doing that special thing on one thread, the other 31 threads are just waiting for you to finish. And so that's bad. So, but, you know, it turns out many very CPU intense programs don't really need a lot of branching. No. So like, you know, video transcoding and things like that.

0:49:05.919 --> 0:49:40.040
<v B>Or think about like all the like photography. I always think about like photography stuff because it's something I understand a little bit about. But like if you want to apply a blur. Right. Right. You take, you have one image, your input image, and you have your output image and you have your thing you're going to use to do the blurring, which is a matrix. You just need to add every pixel, apply that matrix to the input image. Yeah. There isn't really a lot of branching to be done there. You just know what needs to be done at every pixel. You just go ahead and do it. And you can do them all in parallel. Right. Which is crazy. Right. Like just for every pixel, do this thing. As opposed to for this image, go through it and do this thing.

0:49:40.380 --> 0:49:41.640
<v A>Yeah. Exactly. Exactly.

0:49:43.380 --> 0:49:59.039
<v A>You hear a lot of crazy things about, you know, GPU programming. Like, oh, I have a 60x speed up. I have a 200x speed up. Right. Most of the time, those were things that were programmed badly. You know. Well, I mean, things that are, the term I

0:49:59.039 --> 0:50:08.060
<v B>like is embarrassing. They're embarrassingly parallel or whatever. Yeah. They're embarrassingly suited to GPU. Like, if you give the GPU something that's almost exactly like what it was built to do, it's awesome.

0:50:08.340 --> 0:50:08.540
<v A>Yeah.

0:50:08.780 --> 0:50:26.900
<v B>But it's a very sharp descent. Like, if you get outside of its very, oh, now I'm talking in, like, base. If you have this, like, you know, this thing is really good at it, anything near that thing. Right. It will also get a really huge speed up. But even if you just move a little outside in any one of the directions, you get, like, the performance starts to drop drastically. Right.

0:50:26.900 --> 0:50:42.000
<v A>And there's a lot of things that, you know, CPUs with SIMD and these kind of things can do pretty well. But with that said, GPUs are pretty awesome. The speed up is almost always worth it for the extra, you know, engineering effort.

0:50:42.400 --> 0:50:49.340
<v B>If it's a matrix type thing and you're using images or video or any of these things, yeah, it's going to be awesome.

0:50:49.460 --> 0:50:50.440
<v A>Yeah, totally, totally.

0:50:50.600 --> 0:50:59.333
<v B>For the most part. So somebody will counteract this. But you do have to pay a penalty because you have to move from system RAM to the GPU's RAM. Right. And GPU RAM is

0:50:59.333 --> 0:51:00.420
<v A>really fast, which is great.

0:51:00.779 --> 0:51:08.320
<v B>But you have to pay that penalty to move back and forth over whatever the bus, PCI Express or whatever. Right. And so that is a non-negligible amount of time.

0:51:08.460 --> 0:51:29.200
<v A>Yeah. And that's, to your point, you have to do a lot of pipelining. Like, you have to say, 'Okay, GPU, I want you to do this on this part of the image.' But then, like, while you're doing that, I'm going to be sending you the next image. And as long as you can sort of, so that way it's sort of like the GPU is working and the bus is sending things at the same time. You're not just doing things serially. Yeah.

0:51:29.540 --> 0:51:35.780
<v B>So like any parallel program, much less one that's so crazily highly parallel, debugging is crazy.

0:51:36.060 --> 0:51:37.082
<v A>Oh, yeah. Debugging is kind of

0:51:37.082 --> 0:52:14.900
<v B>high. You don't have a lot of the weird, like, at least if you stick to the most basic kind of stuff that most people do, you don't end up with a lot of race conditions because you shouldn't be doing that kind of stuff in most of this GPU programming. But even still, like, it's hard because if you go through a loop of the program, what does that really mean? Like, you're in one pixel of one image in one processor and you're looking at something. But the interaction is probably something slightly higher level than that. And you need some way to simulate it on your CPU because GPUs don't have the same kind of breakpointing ability as CPUs do. Yep. So, yeah.

0:52:14.960 --> 0:52:15.840
<v A>It's getting better.

0:52:16.220 --> 0:52:17.840
<v B>Yeah, definitely. But it's definitely hard.

0:52:18.340 --> 0:53:45.080
<v A>Yeah, yeah. I mean, when we were doing it, it was kind of a nightmare. I think it has come a long way, though. It's really gotten a lot better there. One interesting thing is for data on the GPU, there's three different types of arrays that you can allocate on the GPU: read-only. So the idea is, you know, you're allowed to write to this array once and that's it. You can only read from it. And only the GPU can read from it, not the CPU. And so if you go there, it's going to put it in some structure, which, you know, the bus isn't allowed to talk to this structure anymore. It sort of locks it off. But it puts it in a place that's very easily accessible by the GPU. Also, it knows that this data is never going to be written to by the CPU. So it can do some optimizations there. Like, it can do some operations, like in a pipeline, knowing that it's not dependent. Yeah, there's no data dependency. There's write-only. So, for example, like all of your input data, you don't want to read that back from the GPU. I mean, you have it already on the CPU and it's completely in its pure form, right? So all your input data, you mark it as write-only. And, again, the GPU knows that you're never going to have to pull that back. So you can do some crazy things, put it in some, like, volatile memory and things like that. Or read-write. And so read-write is the slowest. You know, the GPU expects at any moment you're going to read that data. And so it has to sort of keep it in a state that's stable. But, you know, sometimes you need that.

0:53:45.320 --> 0:53:48.353
<v B>And you bring up one of the things which is confusing at first is

0:53:48.353 --> 0:53:50.209
<v A>Whose perspective are you talking from? So if

0:53:50.243 --> 0:54:00.399
<v B>It's read-only, is it from the CPU or GPU? Write-only, and you just have to be careful to balance that in your head. Like, when you say something, whose perspective are you talking from?

0:54:00.540 --> 0:54:12.200
<v A>Yeah, that's a really good point. Yeah. I mean, so just to recap, read-only means, you know, you send it to the GPU and you never expect to get it back. So the GPU can read it, and you can't.

0:54:12.200 --> 0:54:17.740
<v B>So it's GPU read-only, and then GPU write-only is something that the CPU only will read, not the GPU.

0:54:19.460 --> 0:54:30.962
<v A>Write-GPU write-so write-only is where the CPU writes it, but the CPU will never read it from the GPU. I think that's what you just said for the other one, too. It's okay. There.

0:54:30.962 --> 0:55:05.339
<v B>Are opposites. There's two. One for each of the opposite sides. It's okay. My bad. We got it. We got it. Yeah, I think we've beaten this. You should look it up. So the first one, first library we talked about, CUDA, is something written by NVIDIA, specifically for NVIDIA GPUs. Right? So it has some advantages. They know certain things will be present or that they can rely on our architecture, and they're a company that is very highly invested in keeping you locked into their platform. But in turn, they kind of give you a lot of niceties. Yeah, a good analogy would be DirectX.

0:55:05.680 --> 0:55:17.480
<v A>Yeah. Like DirectX, it's Windows only. And so it's like the OS and the GPU can sort of have an agreement, which OpenGL can't do because it's supported on so many different devices.

0:55:18.340 --> 0:55:38.597
<v B>Yeah. You can have it linked in with your programming language of choice, but then you have specific components, parts, files, which are flagged essentially as CUDA parts. Right? Which are C programs, but written in a restricted set. So you can't have function pointers. You can't. There's a couple of restrictions. I don't.

0:55:38.597 --> 0:55:40.700
<v A>Think you can have global variables? Or maybe you can.

0:55:40.900 --> 0:55:58.763
<v B>Yeah. Some things, like over time, they tend to become more and more relaxed. Like they figure out how to do more things. But you might get a penalty for doing them. So there's a little bit of, in all of these we'll talk about, there's a, more so than normal programming, there's a strong responsibility on the programmer to understand what they're doing and whether it'll be expensive or not.

0:55:58.820 --> 0:56:26.640
<v A>Right. Yeah. Like one thing that you might not expect, integer operations are really expensive. And it's because everything in graphics is floating point. Like where points of a triangle are in space and things like that have always been done in floating point. And so there's, I mean, now this might be different, but when we were doing it, there wasn't really like an integer in operations and hardware. And so that made, it actually was much faster for us to do floating point division. And if there's a little bit of loss, you know, it's okay. Yeah.

0:56:27.299 --> 0:56:54.383
<v B>And like I said, NVIDIA provides some special libraries on top of just CUDA itself that are really good at some of the things a lot of people want to do. Like fast Fourier transform, linear algebra stuff. So the blast stuff, they provide their own versions of this where instead of handling all these things we've been talking about, if you know, I just want to do a Fourier transform on this data, you just call it, and it transfers the data over, performs the operation, and brings it back. Right? And when you get done, you just have it there. Yep.

0:56:54.680 --> 0:56:58.095
<v A>So for people who don't know what fast Fourier transform is, I'll give my two second or

0:56:58.095 --> 0:57:00.492
<v B>Five-second explanation of FFT. Okay, go. Okay.

0:57:01.180 --> 0:57:03.023
<v A>So if you have a series of data, let's

0:57:04.930 --> 0:57:29.900
<v A>say it's a time series or it could be spatial series, you know, like an array, you know, like a 1D image or something like that. Right? What a Fast Fourier Transform tries to do is turn that image into a frequency space. And a really simple way of explaining it is, you know, it tries to find a bunch of coefficients such that you can add a bunch of cosine waves together and recreate your original signal.

0:57:30.440 --> 0:57:34.292
<v B>You described Fourier transform. Yeah. You've got zero seconds left to describe the

0:57:34.292 --> 0:57:35.085
<v A>fast part. I

0:57:37.077 --> 0:58:03.060
<v B>have no idea. Do you know fast? Yeah. So I think it's basically there's Fourier transform is a mathematical notion, right, for continuous signals for the most part. But yet in the computer world, a lot of times we're dealing with discrete signals. So we have a, you know, you want to convert your wave to MP3, right? And you want to, or at least analyze your wave or whatever. But you only have discrete, you only have sample points so far apart. Right? And the signal ends at some point, right? You have an end of your file. Does it go on?

0:58:03.060 --> 0:58:13.200
<v A>So the Fourier transform will turn your discrete signal basically into sort of a continuous signal by storing all of these coefficients of a bunch of cosines that you can then add together at any point.

0:58:13.200 --> 0:58:32.240
<v B>So Fast Fourier just exploits some notions that because it's discrete, because it ends, and there's some symmetries, how do you do it faster? And I don't know the specifics of it. The math always escapes me. I try about once every month to read some article that's supposed to explain it to me, and I still miss it. But it has to do with symmetries and optimizations because of, you know, what you're working with.

0:58:32.380 --> 0:59:16.589
<v A>Gotcha. So, yeah, if you ever wondered how MP3 works, I'll give it to you really quickly. Oh, dear. I mean, it's really like a discrete cosine transform, so it's a little different. But it's like an exact FFT. But just imagine, you know, instead of storing, so, you know, music comes in like a wave. Everyone's seen like this. It's what is that machine where it lets you show different pitches and it shows you the wavelength of the pitch and everything? It's like a... A tuning fork? No, no. It's like a machine, and it has graphs. Okay. And it also has a pitch. And you can, like, turn a knob and the graph will, like, the wavelength will shrink in the graph and the pitch will go... Okay. I don't know. Oh, we had one at... Okay. Anyways. So, music comes in waves. Oh, I do. Okay. Oh, you know what I'm talking about.

0:59:16.589 --> 0:59:17.027
<v B>now. Yeah, yeah, yeah. You

0:59:17.027 --> 1:00:15.660
<v A>don't know the name either. Okay. Oscilloscope. Oscilloscope. That's exactly what I was thinking of. Okay. So, everyone's seen an oscilloscope, which has sort of those waves, right? And how that's connected to music. So, you can store these waves. And the way an MP3 does this is if you have, let's say, like, a cosine, you can find a cosine that kind of fits your wave. And you can, you know, pick a certain amplitude, which is how high the cosine goes, and a certain frequency, which is sort of how narrow each of those up-down hills are. And so, you can find, you know, a frequency and amplitude such that it tries to approximate, you know, like Kanye West's song or something like that, right? And you won't get all of it, of course, with one cosine. You'll get a little bit of it. So, then you take that part out of Kanye's song. And now it sounds a little different, but hopefully you find another cosine wave that can now match that new song. And then you basically keep doing this until you end up with nothing. And you have, like, all these cosine waves. And when you add them together, you get Kanye West's song.

1:00:16.240 --> 1:00:26.660
<v B>Yeah. So, it essentially relies on the fact your ear can't hear all of the little differences. Right? So, if something's changing really, really fast, it's probably unimportant. It's probably just, quote, unquote, noise or whatever that can be filtered away.

1:00:27.259 --> 1:00:28.257
<v A>Yeah. And the same thing.

1:00:28.257 --> 1:00:42.240
<v B>Is true for images. JPEG is the same thing. It tries to say, in this area of a white wall, there's almost no difference between two pixels. So, if I just approximate it, you won't lose very much information. It tries to very carefully pick what information to store as opposed to storing everything.

1:00:42.480 --> 1:00:53.900
<v A>Yep. Exactly. And so, get back to NVIDIA. So, NVIDIA has a QOO FFT library. You could totally use this to write your own GPU-based WAV to MP3 transcoder. That would be super fast.

1:00:54.280 --> 1:01:24.480
<v B>Yep. Okay. Then, okay. So, there's also bindings for CUDA for many languages. Right. And it's pretty easy to write your own. And then OpenCL, a standard very close to OpenGL in that, you know, it supports multiple CPUs and GPUs. Interesting thing there, I said CPUs. Yeah. It can also, you know, your multi-core processor can be treated just like GPU. Right. So, you probably will lose out on doing something specific, but you could approximate something on a computer if someone doesn't have a GPU.

1:01:24.780 --> 1:01:36.220
<v A>Right. And it makes it much—excuse me, it makes it much easier to debug, too. You can actually debug on your CPU, catch any, you know, divide by zero errors and things like that, and then push it to the GPU once you're confident.

1:01:36.955 --> 1:01:40.400
<v B>And you can support multiple brands of graphics cards.

1:01:40.740 --> 1:02:07.180
<v A>Right. Like, if somebody, you know, imagine, like, you're releasing an app, you know, like some program you want people to download, a video game you're writing, or who knows, right? You know, you don't want to just give your game to people with NVIDIA graphics cards. You want everyone to have your game. And so, with OpenCL, it'll use, you know, NVIDIA, it'll use ATI, or I guess they're now AMD graphics cards. If it doesn't have any of those graphics cards, it can fall back to the CPU. And so, it's much more versatile.

1:02:07.800 --> 1:02:29.360
<v B>Yep. But similarly, my experience has been that they tend to implement things a little slower because it's a standard. So, it takes a little longer to get everybody on board. And people tend to prefer their own implementation over OpenCL, talking about manufacturers. So, you know, NVIDIA will support OpenCL at some level, but it's going to support CUDA better. And so, that also causes some problems.

1:02:29.580 --> 1:02:30.651
<v A>Yep. Yeah, totally. Well,

1:02:31.900 --> 1:02:38.464
<v B>That's pretty much it. It was at a high level. We had a little bit of a venture off into Fourier land. Yeah,

1:02:38.464 --> 1:02:43.160
<v A>We started with origami and ended with Fast Fourier Transform. So, this is definitely an awesome show.

1:02:44.860 --> 1:02:59.320
<v B>All right. Well, we've been getting emails still. People were wondering where the show went. We've had busy lives having... Jason had a kid. I had a kid. So, there are two more people in the world who will want to listen to the podcast one day. Yeah, totally. Maybe or not.

1:02:59.340 --> 1:03:02.984
<v A>Yeah, we both had children in the past. What, two months? No. Three.

1:03:02.984 --> 1:03:03.620
<v B>Months? Four months?

1:03:03.760 --> 1:03:35.459
<v A>I don't know. Okay, anyways. It's all become kind of a blur. Yes. We're definitely... We probably get eight hours of sleep between the two of us on a good day. Yeah, on a good day. But you know, our kids are getting, like... How old is your, like four months now? Five months? Five months. Mine's almost four months. And so, now we're starting to get our lives back a little. And we'll, as part of our lives include doing this show for you guys. So, definitely thanks for all the love and support. And hey, when are you guys doing an episode? That's really actually good that it sort of motivates us.

1:03:35.680 --> 1:03:36.799
<v B>Yeah. Keeps us honest.

1:03:37.000 --> 1:03:47.700
<v A>Yeah, definitely. And so, we appreciate all the support. And thanks for looking at the books. We have, you know, I haven't looked at the numbers lately. But there's a good amount of people buying the books we're recommending, which is great.

1:03:47.972 --> 1:03:50.976
<v B>Or at least clicking on the link and then buying something else. Yeah. Which also helps. That works too.

1:03:50.976 --> 1:04:26.270
<v A>works too. But yeah, I mean, all of these books are ones that we've read. Not both of us, but the one who's recommending the book has read. And it's really good that you guys are getting into it too, so. All right. Till next time. See you later. The intro music is Axo by Binar Pilot. Programming Throwdown is distributed under a Creative Commons Attribution Sharealike 2.0 license. You're free to share, copy, distribute, transmit the work, to remix, adapt the work. But you must provide attribution to Patrick and I. And share alike in kind. Link

