Tuesday, August 13, 2013

If there is no DirectX12, what comes next?

Slashdot today noticed an interview by AMD VP of Sales Roy Taylor stating he believes there will be no DirectX12, ever. (read the interview, translated into english)

So what comes next?

If there really is no DirectX12, it will be because we've finally generalized the GPU into a general purpose computing architecture. 

For more than two decades we've been on a path away from fixed-function 3d-rendering, towards general purpose parallel computing. Intel "missed" a bit with Larabee, but I think they have the right idea. NVidia Tesla and even Tegra are headed in the same direction. Meanwhile, graphics APIs have actively removed fixed-function capabilities, pushing everything into generic parallel programs to run on GPUs.

The next generation 3d graphics APIs are the now-brewing parallel programming fight between CUDA, OpenCL, OpenMP, Microsoft-Accelerator GPGPU, and the Intel Many Integrated Core. 

Buckle up folks, it's going to be a fun ride.

Thursday, August 1, 2013

Objective-C, Generics, and Parametric Typing

One question I see frequently asked and mis-understood:

Does Objective-C has Generics like Java or C#? 
The short answer is ...
No, Objective-C does not currently support parametric typing for collection elements.
However, this topic is more complex than the question or many existing answers admit..
Parametric-Typing for collections in Objective-C would not be the same as Generics in C#/Java. For example, it is unlikely you would ever see Objective-C add the capability to assure every object added to a collection IS an NSArray type or subtype. Instead, Objective-C could (and IMO should) have the ability to assure every object in a collection CONFORMS to a protocol/interface. (i.e. that it implements a set of required methods)
Why?
Objective-C is a language built on protocol (interface) compatibility, NOT subtyping relationships. That is, objects are compatible if they have all the right methods, we don't look at or care about their actual types. In fact, looking at actual types is a very very bad practice in Obj-C and in highly discouraged. This notion is sometimes called "Duck Typing", because if it quacks like a duck, it's a duck. We don't care if it literally inherited from some specific duck or not. This prevents you from being saddled by someone elses implementation hierarchy. -- The result is that as long as an object coming out of the list has a draw:: method it works, we don't actually care if it is a subclass of some specific JimmyDrawableBase object.
This not only makes code more reusable, but it also encourages a slightly different (more functional?) type of problem decomposition, because you can't rely on objects being derived from a given base class and thus having a bunch of your base-class implementation forced into them.
I personally think it would be nice for the Obj-C compiler to have parametric checking of PROTOCOL*CONFORMANCE*. That is, to make a NSMutableArray which requires all objects placed in it conform to a given protocol (i.e. have a given set of required methods).
Sometimes even this more-flexible protocol-conformance checking is resisted by dynamic programming folks, and with sound reasons. Programmers often have a way of over-specifying conformance requirements.
For example, you might require a list contain objects conforming to the NSArray protocol/interface, but you might ACTUALLY only call two of those methods. This is over-conformance. Someone who wishes to stick a compatible item in your array is forced to implement a ton of methods you are not actually calling -- at least not yet (see next).
Google Go tries to solve this problem by inferring structural compatibility. That is, if you call draw() on items coming out of a list, then the compiler assures everything going into a list contains a draw() method. If it does not contain a draw() method, it's a compiler error to put it into the list. This prevents the code from simply causing the same error to occur at runtime. The problem with this is that it only works for whole-program compilation. If Google-Go could compile modular DLLs (which it can't), then it would run into the problem that there isn't a way for me to say objects in the list need to support a specific interface of three methods, even though I'm not calling them today, because I might call them in the future.
Between those two solution likes the tradeoff and the truth.
Personally, I would like to see Objective-C add parametric protocol conformance, so I could ask the compiler to assure the contents of a particular collection always conform to a given set of protocols.
I would also like the compiler to help me avoid over-conformance. If I'm not calling methods in those protocols on objects, it should generate errors/warnings telling me so. If I want to keep them in the protocol even though I'm not using them, I should have to explicitly make a declaration for each method in the protocol that it "might be used in the future, so elements all need to supply it now". This at least makes the process of over-conformance require MORE work, instead of Java/C# where it requires less work.

Friday, June 27, 2008

Dissecting emotionally moving dance

You might not know it from the stream of techie blog posts, but I'm a giant fan of the hit talent shows American Idol, and So you think you can dance. Take a peek underneath why Katee and Joshua's performance to Jordin Sparks' No Air, designed by the amazing choreographer duo Tabitha and Napoleon D'Umo reaches your emotional core and is so moving.


Dance may impress us because of stunts, tricks, and gymnastics. We may gasp or chuckle, for the same reason we stare with our mouths open when Michael Jordan or Dominique Wilkins leave the ground to slam dunk. We simply don't understand how they can DO those amazing feats of talent and strength. However, this moving performance was more than strength and technical excellence. It was moving music; dancers becoming actors; and coreography design that uses synchronization of the action and music to create a mental 'strobe' effect, where we feel like the messages that only last a split second linger, and piece together a story.

Be sure to have the video up. Here is a higher quality version, though the times are slightly offset from my writeup below.

Let's take a look at how many perfectly timed movements Katie and Joshua hit to sell it home. These are dance elements and acting synchronized to the music with sub-second precision. If it seems impossible to unravel this kind of detail, you should know I had help, in the form of the Enounce MySpeed plugin, that lets me change the speed of flash-playback to slow it down. I assure you, your brain works fast enough to process and understand all this information as it happens, even if you didn't realize it.

  • 0:09 - joshua's kiss on her forehead says he cares
  • 0:14 - katie opens the letter to full length
  • 0:16 - katie turns her head and her eyes land on joshua, her movement says disbelief
    • katie stands and walks away to console herself
    • joshua's head turn shows he sympathetically wants to follow her, he tells us to follow her, but he also shows he cannot. she is alone
  • 0:22 - joshua's head turn snaps back into his own world to let us shift our full attention to katie as her sadness over the letter explodes
  • 0:22-0:34 - Katie's rage
    • 0:22-0:26 - rapid sub-second synchroized submarks show her anxiousness.
      • 0:22: - right leg pump
      • 0:23: - left leg pump
      • 0:23: - right leg pump
      • 0:24: - left leg pump and turn
      • 0:25: - paper toss
    • 0:27 - katie's chestpump, lyrics "you took my breath away", and her facial expression are telling us she's terribly upset about the news
    • 0:29 - katie's two handed point is directed at "you" in the audience, synchronizing in your mind the word "you" with the song's lyrical "you". If your brain was distracted watching some random motion she did, you wouldn't process the lyric, it would be background words... She just told you to listen, she told you she's speaking (to joshua), and her words she wants us to understand are "losing you is like living in a world with no air". It's the synchronization of the events that makes it possible for us to pay attention to both.
    • 0.29: - 0:34 - katie continues her emotion
    • 0:33 - katie's violent body movement mimics the look of someone being punched or hit in the stomach. We see it's the message in the letter is hurting her.
  • 0:34 - our attention turns back to Joshua as he begins to move again, timed with Chris Brown's verse in the song, to show us Chris is speaking his words
  • 0:34 - 0:42 - joshua makes his way to katie, his movements are not directly to, but face us, as the lyrics explain "i'm her alone, don't wanna leave".
    • 0:31 - 0:32 - His movements are side to side, as if he's trying to find her, making his way to her.
  • 0:42 - joshua reaches katie and reaches around her. However, he doesn't just hug her, his hands grab her hands. We can tell his embrace is gentle from her reaction, but there is something more from the way he's grabbing her wrists.
  • 0:42-0:45 - Timed with the music he forcefully manipulates her, again causing a synchonization between him making her move and the lyrical phrase "make you understand". His movements have sub-second timing, perfectly synchronized with the music beats. Notice how katie's not looking at us at all. We can't see her face, it's looking down to the floor and hidden behind her hair. We're listening to Joshua. This is my favorite sequence in the dance.
    • 0:43.4 he lifts her arms a little
    • 0:43.9 he lifts her arms further
    • 0:44.3 he pulls her arms together (her head falls, showing us it's not working)
    • 0:45.2 he pulls her right leg out
    • 0:45.6 he pulls her right arm up
    • 0.46.2 he pulls her right arm down
  • 0:46.2 - katie reacts, he face comes into view. We don't see a 'dance move', we see her face. She's acting, and we recognize the emotion on it instantly. Whether you realized or not, your brain noticed. Look closely. She's in agony.
  • 0:46.6 - Katie begins to move again. She moves her arms out, and Joshua's fast arm movements look like they were 'throw' outwards. Together the two of them show us that she 'broke free' and he's not able to 'make' her understand anything.
  • 0:48:52 - Chris Brown's lyrics and Jordin Sparks' begin, but both of them are moving this time. We know what this looks like, it looks like a conversation. One where they are both paying attention to eachother. Where they both care. Watch their perfectly timed synchronized movements.
  • 0:51 - 0:53 Watch katie's face. Despite the two of them dancing together in perfect rythem, her face locks on Joshua's. Again, she's not just dancing, she's acting. More than any other part of the dance she's showing us that her attention is focused on him and she's speaking to him. "..how do you expect me, to live alone with just me.."
  • 0:54 - katie is laid back, and joshua lifts her up and rotates her over her shoulder as the lyrics call out "'cause my world revolves around you..". I don't think most of us has as strong a connection between seeing that motion and the world 'revolve', but it's a similar effect to what occured above, with "you" and "make".
  • 0:57 - katie pushes joshua to the floor, synchronized with the word "hard", in the lyrical phrase "it's so hard for me"
  • 0.58 - Joshua's back leg is up in the air and his face is pressed into the floor, showing us he's hearing her message. She presses down on his leg, softly lifting him from the floor back up during the word 'breathe'. This is my second favorite element of the performance. This move is fluid and perfectly timed, and involves both of them participating precisely. The soft upward motion reminds us of breathing, a soft upward motion of the chest as we inhale. 0:59 - 1:20 - duo dancing resumes as the conversation as the lyrics include both Jordin Sparks and Chris Brown singing in unison.
  • 1:20 1:22 - katie has subtly moved herself back to joshua for my third favorite move of the performance, the embrace.
    • 1:20 - Their heads are perfectly aligned as they tilt together. To us they appear to be tilting in the same direction, but remember, this is a conversation between the two of them. Imagine katie is turned around facing him. When do you tilt your head to the side? Look at the clip and see if you see it. They tilt their heads to the side because they are going to hug.
    • 1:21 - She turns her head around to look directly at Joshua, and moves her hand across. His hand is waiting for hers, and they embrace.
    • 1:22 - She starts facing us for the performance, but his hands are around her waist. We see him hugging her.
  • 1:23 - Are you ready for it? The big shocker? He turns her around and lays her down (on his leg). Look at this position carefully. He not only loves her, he's making love to her. Yes, at 1:23, that pose isn't just some random dance move in the middle of some music. It means sex. (sorry kids).
  • 1:24 - He pulls her up close to him, pulls himself inside her as she reaches the climax
  • 1:25 - She slides down and away from him. Their lovemaking is completed.
  • 1:26 - still holding hands she twirls. for just a moment she's actually happy
  • 1:27 - She shows her face. We've seen it before. We recognize it. It's agony. She's come back from the fantasy of lovemaking and has remembered the reality of the situation.
  • 1:28 - she bursts out, wanting to return to her emotions. However, this time instead of letting her go, he holds onto her. He stops her from entering her rage.
  • 1:29 - She's limp and falling to the floor as he pulls her back to him.
  • 1:30 - He shares his strength, and lifts her up off the floor. Tells her it will be okay, that he's taking care of her.
  • 1:32 - They separate, and she's standing up on her own again. She's not in a rage.
  • 1:33 - He begins to walk across, she watches him, but she's accepted it
  • 1:34 - As he passes by, she takes the sleeve of his shirt, and removes it to keep a piece of him with her
  • 1:38 - He looks at her, both accepting it, and suprised. He's accepting it, and accepting her keeping a piece of him.
  • We feel exhausted from their turmoil, but content that they resolved it.

It took me about two hours to dissect this video. Imagine how long it took them to perfect it. I realized quite a few things that I didn't catch while watching it at normal speed. However, you can be sure my brain caught them every time. That is what made the peformance so moving.

Katee and Josuha, if you are listening, I'm in awe. Thank you for sharing with us such an amazing performance. All that work you put into it paid off. We noticed every movement you did, and your perfection worked to bring us to an emotional state that we loved!

Tabitha and Napoleon D'Umo, if you are listening, I'm in awe. When they later praised your work as 'lyrical hiphop' it was an understatement. This is choreography, and screenwriting, and storytelling, and hiphop with detail at so many levels. Wow.