Wow THAT was a long break

Sunday, August 1, 2021 – 6:50 AM

So blogging sort of dropped of the map while I was building an analytics platform at Tier3/CenturyLink Cloud and now a live video transcoding engine at iStreamPlanet. For the most part I spend my time writing C++ so there just might be some more posts on that. I’ve also been keeping myself entertained writing some trivial C++ games using Cinder. You can find them here CinderExamples.

Once You Know, You Newegg

C++ AMP Algorithms Library Released

Thursday, November 13, 2014 – 6:01 PM

Finally there’s a new release of the C++ AMP Algorithms Library!

This release contains some important bug fixes on 0.9.4.

  • Fixed array initialization bug in radix_sort
  • count_if no longer uses an excessively large number of threads, even for small problem sizes.
  • Removed code to initialize tests for code coverage.
  • Improved unit test stability on different hardware.


What’s up next for the library? A port to Linux and more STL algorithm implementations and bug fixes. Right now I’m busy moving the tests to Google Test. There might be another follow-up post on moving to Google Test. So far it’s been a pretty good experience, more test cases with less code and a much faster turnaround time code/build/test…

C++ AMP Algorithms Library 0.9.4 Released

Thursday, October 2, 2014 – 8:39 PM

Finally there’s a new release of the C++ AMP Algorithms Library! It’s taken a while, largely due to other things, like CppCon taking up my time.

This release contains the following:

  • New C++ AMP features:
    • AMP and STL algorithms no longer depend on DirectX scan implementation.
    • New implementation of amp_algorithms::scan that does not have a direct dependency on theID3DX11Scan and ID3DX11SegmentedScan interfaces.
    • The amp_stl_algorithms::copy_if and remove_if algorithms now use the the new scan implementation for improved performance.
    • Implementation of radix sort amp_algorithms::radix_sort.
    • New utility functions functions; log2, is_power_of_two, count_bits, padded_read, padded_write,pack_byte and unpack_byte
    • New namespace added for DirectX dependent features, amp_algorithms::direct3d. All DirectX code now in a separate header file amp_algorithms_direct3d.h.
  • New C++ AMP STL features:
    • inner_product
    • minmax
    • pair<T1, T2>
    • rotate_copy
  • New SAXPY example.
  • Reorganized unit tests, consistent names and test categories.


What’s up next for the library? A port to Linux and more STL algorithm implementations and bug fixes.

Test Categories for Visual C++

Wednesday, April 30, 2014 – 9:52 PM

Recently I’ve been using the Visual Studio unit test runner for C++ and came across a trick for adding categories to C++ tests. While the test framework supports traits, a little work makes them much more usable.

        TEST_METHOD_ATTRIBUTE(L"TestCategory", "my_category")
        // ... 

That’s a lot of code to  just add a category to each test.

You can add a specific macro to shorten all of this up, especially if you’re adding categories to all of your tests.

    #define TEST_METHOD_CATEGORY(methodName, category)          \
        BEGIN_TEST_METHOD_ATTRIBUTE(methodName)                 \
            TEST_METHOD_ATTRIBUTE(L"TestCategory", L#category)  \
        END_TEST_METHOD_ATTRIBUTE()                             \

Now you an write tests like this:

    TEST_METHOD_CATEGORY(testMethod, "my_category")
        // ...

Better still you can do the same thing for classes. In this case the BEGIN_CLASS_METHOD_ATTRIBUTE can be used within another macro.

    #define TEST_CLASS_CATEGORY(className, category)                \
        TEST_CLASS(className)                                       \
        {                                                           \
            BEGIN_TEST_CLASS_ATTRIBUTE()                            \
                TEST_CLASS_ATTRIBUTE(L"TestCategory", L#category)   \

Note that the MSDN page is incorrect in it’s documentation of this attribute. It is used inside the class and does not take any arguments.

Now you can add a category to a class and, if needed, override the category for individual methods.

    TEST_CLASS_CATEGORY(the_tests, "foo")
    // No '{' required, part of the macro.
        TEST_METHOD_CATEGORY(test, "bar")
            // Test in category 'bar'.

            // Test in category 'foo'.

I’ve used this to organize the tests in the C++AMP Algorithms Library, so you can look what I did there if you want more examples.

Using C++ Classes with C++ AMP

Friday, January 31, 2014 – 6:25 PM

You can use classes with C++ AMP but you have to understand the limitations the CPU/GPU hardware model places on how and were you can use them. The C++ AMP Book says the following:

References and pointers (to a compatible type) may be used locally but cannot be captured by a lambda. Function pointers, pointer-to-pointer, and the like are not allowed; neither are static or global variables.

Classes must meet more rules if you wish to use instances of them. They must have no virtual functions or virtual inheritance. Constructors, destructors, and other non-virtual functions are allowed. The member variables must all be of compatible types, which could of course include instances of other classes as long as those classes meet the same rules. The actual code in your amp-compatible function is not running on a CPU and therefore can’t do certain things that you might be used to doing:

  • recursion
  • pointer casting
  • use of virtual functions
  • new or delete
  • RTTI or dynamic casting
  • goto
  • throw, try, or catch
  • access to globals or statics
  • inline assembler

In some ways this is a little bit misleading as it refers to classes that can be used within a C++ AMP kernel. Here’s an example of a class that meets these requirements.

   1: class stuff
   2: {
   3: public:
   4:      int a;
   6:      stuff() : a(0) {}
   7:      stuff(int v) restrict(amp, cpu) : a(v) { }
   8: };

Note that stuff also has a constructor marked with restrict(amp, cpu). This allows your code to create stuff instances in both CPU and GPU code (line 8 in the code below).

You can also create classes that use C++ AMP within a C++ class. In the example below test_case::test_amp() executes an AMP kernel. This works pretty much how you’d expect.

The gotcha comes when you declare a method on the test_case class that you want to call from within the AMP kernel. There is no way to share the class’ this pointer between the CPU and the GPU so methods that are declared as restrict(amp) must also be declared static. So here amp_method is static.

   1: class test_case
   2: {
   3: public:
   4:      test_case() { }
   6:      static stuff amp_method(stuff s) restrict(amp, cpu)
   7:      {
   8:          return stuff(s.a * s.a);
   9:      };
  11:      void test_amp()
  12:      {
  13:          concurrency::array_view<stuff, 1> data(100);
  14:          concurrency::parallel_for_each(data.extent,
  15:              [data](concurrency::index<1> idx) restrict(amp)
  16:          {
  17:              data[idx] = amp_method(data[idx]);
  18:          });
  19:          data.synchronize();
  20:      };          
  22:      void test_cpu()
  23:      {
  24:          std::vector<stuff> data(100, 0);
  25:          for (auto& d : data)
  26:          {
  27:              d = amp_method(d);
  28:          }
  29:      }
  30: };

Hopefully this clears up any confusion. This is the first of several blog posts I have lined up on C++ AMP and some of the things I’m working on for the C++ AMP Algorithms Library.

Tier 3 Acquired by CentryLink

Tuesday, November 19, 2013 – 10:34 AM

“Tier 3, a Bellevue cloud computing startup backed with $18.5 from Ignition, Madrona and Intel Ventures, has been sold to CenturyLink.” – Geekwire


While I’ve only been here a few months and can’t really take any of the credit for any of this. I am really excited, as Tier 3’s self-service platform, combined with CenturyLink’s infrastructure should be a force to be reckoned with!

AMP Algorithms Library now supports Visual Studio 2013

Monday, November 11, 2013 – 9:30 AM

With the help of the C++ AMP development team (thanks Meng & Lukasz) I’ve been able to resolve the issues I was having building the Library on VS 2013 and shipped a new release.

The AMP Algorithms Library 0.9.3 release includes minor updates on 0.9.2.

  • Support for Visual Studio 2013 (and 2012)
  • Map-reduce sample code.
  • Support for logical_ functors.
  • Improved pre-checkin build script.

I’m hoping to get the next major release done by the new year as I plan to work on it over the holiday breaks. This should include a number of new additions to the algroithms.

C++AMP Samples Updated for Visual Studio 2013

Wednesday, October 23, 2013 – 3:04 PM

Visual Studio 2013 shipped last week and I found some time to look at the new C++AMP features over the weekend. Most importantly to make sure that the book samples still work. The 1.0 (VS 2013 compatible) release fixes a couple of warnings in the DX Util library and one issue with the C++ AMP upgrade.

writeonly_texture_view<T, N> has been deprecated in the 2013 release. The texture_view<T, N> template class now includes this functionality. You can read more about this on the Parallel Programming and Native Code blog.

You’ll find the following in several places in the Chapter 11 sample code.

#if (_MSC_VER >= 1800)
texture_view<int, 2> outputTxVw(outputTx);
writeonly_texture_view<int, 2> outputTxVw(outputTx);

Note: The C++AMP Algorithms Library has not yet been upgraded to VS 2013. I’m working on that.

Seattle Code Camp 2013: Decks and Code Available

Monday, October 7, 2013 – 8:11 AM

Several of the other speakers have made their decks and other resources available online.

Seattle Code Camp 2013

Saturday, September 28, 2013 – 8:27 PM

It’s been a great few weeks since starting at Tier 3. I spent two weeks at the Tier 3 Hack House in Utah. Spent two weeks hanging out with the fantastic Tier 3 engineering team and doing a bit of riding at the same time.

I got back in time to give two talks at my favorite local conference, Seattle Code Camp. I only made it for half the day but met up with several old friends and had some great conversations with some of the attendees. Good times!

Here are the slide decks, source code and other resources for the talks I gave at this year’s Seattle Code Camp.

If anyone found or picked up my Apple Thunderbolt to VGA adaptor I’ve love to get it back. You can contact me or the Code Camp organizers. There’s a six pack in it for you.

Not Your Mother’s C++

Download Slide DeckMore and more apps are build for phones and tablets with less powerful processors and limited battery life. If you want to develop for these devices then it’s important to consider performance when building apps that users will love. C++ has a reputation for been hard to read, let alone write. You paid for the performance C++ gave you with late nights chasing memory leaks and crashes. C++ has moved on in the last few years with new language features, libraries and programming idioms. These all make many of the pitfalls of C++ much easier to avoid. This talk will give an overview of the new features in C++11. Including; how to not worry about memory management (too much), use libraries for graphics, math and data structures, and build apps in a few hundred lines of readable code.


You can download the code samples. Eventually I’ll get them up on GitHub but right now it’s just a zip file. The samples assume that Cinder is installed in yC:\Src\Download\cinder. If you install it somewhere else you will need to modify the project settings.

  • Cinder – The graphics library I used for the GUI in the Life app.
  • Boost – A popular library that implements lots of useful features. I used this to implement file access in the Life app.
  • Standard Library (STL)  – Part of the C++ standard.

The C++11 standard is relatively new, so most compilers don’t support 100% of the standard. C++11 compiler support shootout: Visual Studio, GCC, Clang, Intel gives an overview of which compilers support which features. VS 2013 adds more support for C++11.

You can find videos of sessions from Going Native 2013 online.

Scott Meyer’s books and overview of C++11 are all well worth reading. When I returned to C++ these were the books that got me started.

Someone asked me about game programming books after the talk. Here’s the one I’v been reading Introduction to 3D Game Programming with DirectX 11.

Writing for Developers

Download Slide DeckMaybe you want to write a programming book, maybe just a blog post or some documentation for your team or the users of an open source project. All the great code you wrote is no good if no one else can understand and use it. Learn about the beginning, middle and end of writing anything and what it takes to write great sample code to go along with all those words.


On Writing: A Memoir Of The Craft by Stephen King was one of the books I wrote when I started writing. Obviously it’s mostly focused on fictional writing but I still found it very valuable.

The Elements of Style, Fourth Edition by William Strunk Jr. and E.B. White is the gold standard when it comes to general questions of writing style.

Links to books on MSDN:

Parallel Programming with Microsoft .NET

Parallel Programming with Microsoft Visual C++

You can also find these books on Amazon along with my book on C++ AMP.

C++ AMP: Accelerated Massive Parallelism with Microsoft® Visual C++