OpenCL: To GPGPU and Beyond

By John West

December 11, 2008

This week at SIGGRAPH Asia in Singapore, The Khronos Group announced that version 1.0 of the OpenCL specification has been ratified. In the short term OpenCL is expected to encourage the development of applications that can take advantage of those GPGPUs you can find in just about every machine these days (though not in the way you might expect). But in the long term the implications for HPC may be much more far-reaching than “just” the GPU.

OpenCL originated inside the hallowed halls of Steve Jobs’ Apple – it will be integrated into Snow Leopard, the next release of the company’s operating system, as part of the suite of technologies being introduced to streamline Mac OS X and improve the performance of applications. In June of 2008 Apple turned a draft standard over to The Khronos Group, “a member-funded industry consortium focused on the creation of open standard, royalty-free APIs to enable the authoring and accelerated playback of dynamic media on a wide variety of platforms and devices.” You may not have heard of Khronos, but they are the team that is responsible for the care and feeding of OpenGL, and several other less well known standards.

This week, only six months after it started work, Khronos has announced that the OpenCL consortium has reached consensus on version 1.0 of the specification. That seems pretty impressive, especially when you consider the long list of IT heavyweights who were involved: Intel, AMD, Ericsson, IBM, NVIDIA, Nokia, Texas Instruments, Apple, Motorola (and more; see the full list). OpenCL is based on C99, a dialect of C that was adopted as an ANSI standard in May 2000.

But what’s it do? You’ve no doubt heard that OpenCL will accelerate the development of applications that take advantage of the extra processing power available in the nearly ubiquitous GPU. Both AMD and NVIDIA have announced support for the standard alongside their own Brook+ and CUDA efforts. For example, any card that supports CUDA will support OpenCL. And Intel is a member of the consortium, so the conventional wisdom is that support is expected for Larrabee as well, although Intel has been pretty vague so far while it actively develops its own language for throughput computing, Ct.

OpenCL is an important step in spurring the development of application for GPUs, because developers would like to accelerate their code on all available GPUs rather than locking them — and their customers — into one vendor’s solution. However, OpenCL is a low-level standard when compared with other alternatives. For example, programmers will have to do their own memory management (unlike with CUDA), and overall OpenCL supports fewer productivity-enhancing abstractions. In the Khronos Group’s own slide deck OpenCL is characterized as “approachable, but primarily targeted at expert developers.” This means that OpenCL’s benefits may come to application developers indirectly, through the tools community. Companies like Codeplay and RapidMind are members of the consortium and will likely incorporate the technology into their development platforms.

What about the 800-pound gorilla OS? Microsoft is not part of the consortium, and is in fact developing a competing technology called DirectX 11 Compute. NVIDIA plans to provide support for this effort as well (in an Engadget article NVIDIA says “it will go where the customers are.”) But because the GPUs vendors themselves are planning to support OpenCL directly, Windows developers will be able to get at the specification, or use tools that take advantage of it, whether or not Microsoft officially endorses OpenCL.

OpenCL may prove pretty significant for traditional HPC as well as the commodity user crowd. OpenCL may well provide ISPs an avenue for delivering high levels of performance on traditional scientific computing applications for users of servers and desktops by encouraging more applications to take advantage of the GPU. OpenCL is much more ambitious than just the GPU, however, as it aims to provide a “programming environment for software developers to write efficient, portable code for high-performance compute servers, desktop computer systems and handheld devices using a diverse mix of multicore CPUs, GPUs, Cell-type architectures and other parallel processors such as DSPs.” In fact, The Khronos Group’s web site and briefing materials make frequent mention of HPC, and it is clear that the consortium members have big things in mind for the new standard as it relates to HPC.

SGI’s Bob Pette, the vice president in charge of visualization at the company, sees a real need in the marketplace for the kinds of issues addressed by OpenCL. “The biggest issue we hear about from customers using accelerator and multi-paradigm computing is overcoming the programming challenges,” he says. “The other major concern is protection of their software investment as hardware technology change rapidly. OpenCL is a positive step forward in addressing both of these critical problems and should fuel growth and advancement in utilization of multicore and manycore technologies.”

Multicore CPUs are an important target for HPC, especially for those interested in using low-end HPC or developing technologies to promote the widespread adoption of HPC. OpenCL, or OpenCL-based tools, will enable developers to parallelize an application for a system with multicore processors, GPUs, or both, amplifying the possibilities for high performance computation on commodity hardware. Another nice benefit of OpenCL’s support for both multicore and GPU solutions is that ISVs don’t have to decide for themselves whether, as some companies are betting, GPUs will return to irrelevance for most computation as the number of cores available on processing chips increases.

OpenCL supports both data- and task-parallel programming models. Task-parallel programming doesn’t really fit well on GPUs but is applicable to the Cell processor or Larrabee. This portability will provide developers a single abstraction with the ability to write applications that can run on everything from a run-of-the-mill PC from WalMart to IBM’s RoadRunner (although some target-specific code may be needed for performance reasons, which we won’t know until the specification gets some performance testing in the real world).

OpenCL does impose some restrictions on the programming model. For example, recursion is a no-no, pointers to functions aren’t allowed, and pointers themselves are only allowed within a kernel, not as arguments. Bit fields aren’t supported, and neither are variable length arrays or structures (see slide 38 of the Khronos deck for a more complete discussion of restrictions). Interestingly the language provides a shared memory model with “relaxed consistency,” and implementations map whatever physical memories are available into the private/local/global address spaces of the specification.

So, what does an OpenCL program look like? I’m glad you asked. The OpenCL slide deck referenced above provides two example implementations, a parallel n-body implementation and a simple vector addition. Since the vector addition is conceptually more straightforward, let’s look at it here (this example starts on slide 43, and the slides have pointers to the specification for more details on specific concepts if you really want to dive into this).

The problem is to compute c = a + b, where a, b, and c are vectors of length N. The kernel that is called by the main program is straightforward:

    __kernel void vec_add (__global const float *a,
    __global const float *b,
    __global float *c)
    {
        int gid = get_global_id(0);
        c[gid] = a[gid] + b[gid];
    }

The main program isn’t particularly complicated, but it is surprisingly long, and it has some fairly odd-looking constructs that set up the context, allocate the memory, and then invoke the kernel we just looked at.

The first step is to query the platform and create (in this case) a GPU compute context and the command queue:

    // create the OpenCL context on a GPU device
    cl_context context = clCreateContextFromType(0, // (must be 0)
                    CL_DEVICE_TYPE_GPU,
                    NULL, // error callback
                    NULL, // user data
                    NULL); // error code

    // get the list of GPU devices associated with context
    size_t cb;
    clGetContextInfo(context, CL_CONTEXT_DEVICES, 0, NULL, &cb);
    cl_device_id *devices = malloc(cb);
    clGetContextInfo(context, CL_CONTEXT_DEVICES, cb, devices, NULL);
   
    // create a command-queue
    cl_cmd_queue cmd_queue = clCreateCommandQueue(context,
                    devices[0],
                    0, // default options
                    NULL); // error code

Next, we create memory objects to hold arrays a, b, and c:

    cl_mem memobjs[3];

    // allocate input buffer memory objects
    memobjs[0] = clCreateBuffer(context,
                    CL_MEM_READ_ONLY | // flags
                    CL_MEM_COPY_HOST_PTR,
                    sizeof(cl_float)*n, // size
                    srcA, // host pointer
                    NULL); // error code

    memobjs[1] = clCreateBuffer(context,
                    CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR,
                    sizeof(cl_float)*n, srcB, NULL);

    // allocate input buffer memory object
    memobjs[2] = clCreateBuffer(context, CL_MEM_WRITE_ONLY,
                    sizeof(cl_float)*n, NULL, NULL);

After this, we create and build the program and create (we aren’t calling yet) the kernel:

    // create the program
    cl_program program = clCreateProgramWithSource(
                    context,
                    1, // string count
                    &program_source, // program strings
                    NULL, // string lengths
                    NULL); // error code

    // build the program
    cl_int err = clBuildProgram(program,
                    0, // num devices in device list
                    NULL, // device list
                    NULL, // options
                    NULL, // notifier callback function ptr
                    NULL); // error code

    // create the kernel
    cl_kernel kernel = clCreateKernel(program, “vec_add”, NULL);

I was on board until this last section, especially the creating and building of the program within the program, but for those more familiar with the use of accelerators this code may not look that odd.

Finally we set the kernel arguments to point to a, b, and c:

    // set vector argument 0
    err = clSetKernelArg(kernel,
                    0, // argument index
                    (void *)&memobjs[0], // argument data
                    sizeof(cl_mem)); // argument data size

    // set  vector argument 1
    err |= clSetKernelArg(kernel, 1, (void *)&memobjs[1], sizeof(cl_mem));

    // set vector argument 2
    err |= clSetKernelArg(kernel, 2, (void *)&memobjs[2], sizeof(cl_mem));

Invoke the kernel, and read the results:

    size_t global_work_size[1] = n; // set work-item dimensions

    // execute kernel
    err = clEnqueueNDRangeKernel(cmd_queue, kernel,
                    1, // Work dimensions
                    NULL, // must be NULL (work offset)
                    global_work_size,
                    NULL, // automatic local work size
                    0, // no events to wait on
                    NULL, // event list
                    NULL); // event for this kernel

    // read output array
    err = clEnqueueReadBuffer( context, memobjs[2],
                    CL_TRUE, // blocking
                    0, // offset
                    n*sizeof(cl_float), // size
                    dst, // pointer
                    0, NULL, NULL); // events

All in all, this looks like a lot of code to add a couple vectors in parallel, and this relates to the points made earlier about OpenCL being “approachable” to the regular programmer, but really made for the “expert programmer in you” (with apologies to Frosted Mini-Wheats). Going through the n-body example in the slides (which, if you are still reading, I recommend) shows more of the power of the language relative to the computational tasks being performed.

My feeling is that OpenCL is a significant development for the broader application development community, spanning as it does everything from cell phones to servers. It also appears to have a lot of potential for supporting the democratization of HPC by encouraging ISVs to make the investment to improve the performance of their applications without having to make potentially costly bets on which, and whose, processing technology will dominate over the next 5 to 7 years. As SGI’s Pette points out, there is still a lot of work to be done to realize the potential of OpenCL, “There will likely be a performance penalty — seeing as the major vendors may choose to layer OpenCL on top of their native drivers. And of course, mere ratification does not imply implementation.”

Subscribe to HPCwire's Weekly Update!

Be the most informed person in the room! Stay ahead of the tech trends with industy updates delivered to you every week!

AWS Embraces FPGAs, ‘Elastic’ GPUs

December 2, 2016

A new instance type rolled out this week by Amazon Web Services is based on customizable field programmable gate arrays that promise to strike a balance between performance and cost as emerging workloads create requirements often unmet by general-purpose processors. Read more…

By George Leopold

AWS Launches Massive 100 Petabyte ‘Sneakernet’

December 1, 2016

Amazon Web Services now offers a way to move data into its cloud by the truckload. Read more…

By Tiffany Trader

Weekly Twitter Roundup (Dec. 1, 2016)

December 1, 2016

Here at HPCwire, we aim to keep the HPC community apprised of the most relevant and interesting news items that get tweeted throughout the week. Read more…

By Thomas Ayres

HPC Career Notes (Dec. 2016)

December 1, 2016

In this monthly feature, we’ll keep you up-to-date on the latest career developments for individuals in the high performance computing community. Read more…

By Thomas Ayres

Lighting up Aurora: Behind the Scenes at the Creation of the DOE’s Upcoming 200 Petaflops Supercomputer

December 1, 2016

In April 2015, U.S. Department of Energy Undersecretary Franklin Orr announced that Intel would be the prime contractor for Aurora: Read more…

By Jan Rowell

IBM and NSF Computing Pioneer Erich Bloch Dies at 91

November 30, 2016

Erich Bloch, a computational pioneer whose competitive zeal and commercial bent helped transform the National Science Foundation while he was its director, died last Friday at age 91. Bloch was a productive force to be reckoned. During his long stint at IBM prior to joining NSF Bloch spearheaded development of the “Stretch” supercomputer and IBM’s phenomenally successful System/360. Read more…

By John Russell

Pioneering Programmers Awarded Presidential Medal of Freedom

November 30, 2016

In an awards ceremony on November 22, President Barack Obama recognized 21 recipients with the Presidential Medal of Freedom, the Nation’s highest civilian honor. Read more…

By Tiffany Trader

Seagate-led SAGE Project Delivers Update on Exascale Goals

November 29, 2016

Roughly a year and a half after its launch, the SAGE exascale storage project led by Seagate has delivered a substantive interim report – Data Storage for Extreme Scale. Read more…

By John Russell

AWS Launches Massive 100 Petabyte ‘Sneakernet’

December 1, 2016

Amazon Web Services now offers a way to move data into its cloud by the truckload. Read more…

By Tiffany Trader

Lighting up Aurora: Behind the Scenes at the Creation of the DOE’s Upcoming 200 Petaflops Supercomputer

December 1, 2016

In April 2015, U.S. Department of Energy Undersecretary Franklin Orr announced that Intel would be the prime contractor for Aurora: Read more…

By Jan Rowell

Seagate-led SAGE Project Delivers Update on Exascale Goals

November 29, 2016

Roughly a year and a half after its launch, the SAGE exascale storage project led by Seagate has delivered a substantive interim report – Data Storage for Extreme Scale. Read more…

By John Russell

Nvidia Sees Bright Future for AI Supercomputing

November 23, 2016

Graphics chipmaker Nvidia made a strong showing at SC16 in Salt Lake City last week. Read more…

By Tiffany Trader

HPE-SGI to Tackle Exascale and Enterprise Targets

November 22, 2016

At first blush, and maybe second blush too, Hewlett Packard Enterprise’s (HPE) purchase of SGI seems like an unambiguous win-win. SGI’s advanced shared memory technology, its popular UV product line (Hanna), deep vertical market expertise, and services-led go-to-market capability all give HPE a leg up in its drive to remake itself. Bear in mind HPE came into existence just a year ago with the split of Hewlett-Packard. The computer landscape, including HPC, is shifting with still unclear consequences. One wonders who’s next on the deal block following Dell’s recent merger with EMC. Read more…

By John Russell

Intel Details AI Hardware Strategy for Post-GPU Age

November 21, 2016

Last week at SC16, Intel revealed its product roadmap for embedding its processors with key capabilities and attributes needed to take artificial intelligence (AI) to the next level. Read more…

By Alex Woodie

SC Says Farewell to Salt Lake City, See You in Denver

November 18, 2016

After an intense four-day flurry of activity (and a cold snap that brought some actual snow flurries), the SC16 show floor closed yesterday (Thursday) and the always-extensive technical program wound down today. Read more…

By Tiffany Trader

D-Wave SC16 Update: What’s Bo Ewald Saying These Days

November 18, 2016

Tucked in a back section of the SC16 exhibit hall, quantum computing pioneer D-Wave has been talking up its new 2000-qubit processor announced in September. Forget for a moment the criticism sometimes aimed at D-Wave. This small Canadian company has sold several machines including, for example, ones to Lockheed and NASA, and has worked with Google on mapping machine learning problems to quantum computing. In July Los Alamos National Laboratory took possession of a 1000-quibit D-Wave 2X system that LANL ordered a year ago around the time of SC15. Read more…

By John Russell

Why 2016 Is the Most Important Year in HPC in Over Two Decades

August 23, 2016

In 1994, two NASA employees connected 16 commodity workstations together using a standard Ethernet LAN and installed open-source message passing software that allowed their number-crunching scientific application to run on the whole “cluster” of machines as if it were a single entity. Read more…

By Vincent Natoli, Stone Ridge Technology

IBM Advances Against x86 with Power9

August 30, 2016

After offering OpenPower Summit attendees a limited preview in April, IBM is unveiling further details of its next-gen CPU, Power9, which the tech mainstay is counting on to regain market share ceded to rival Intel. Read more…

By Tiffany Trader

AWS Beats Azure to K80 General Availability

September 30, 2016

Amazon Web Services has seeded its cloud with Nvidia Tesla K80 GPUs to meet the growing demand for accelerated computing across an increasingly-diverse range of workloads. The P2 instance family is a welcome addition for compute- and data-focused users who were growing frustrated with the performance limitations of Amazon's G2 instances, which are backed by three-year-old Nvidia GRID K520 graphics cards. Read more…

By Tiffany Trader

Think Fast – Is Neuromorphic Computing Set to Leap Forward?

August 15, 2016

Steadily advancing neuromorphic computing technology has created high expectations for this fundamentally different approach to computing. Read more…

By John Russell

The Exascale Computing Project Awards $39.8M to 22 Projects

September 7, 2016

The Department of Energy’s Exascale Computing Project (ECP) hit an important milestone today with the announcement of its first round of funding, moving the nation closer to its goal of reaching capable exascale computing by 2023. Read more…

By Tiffany Trader

HPE Gobbles SGI for Larger Slice of $11B HPC Pie

August 11, 2016

Hewlett Packard Enterprise (HPE) announced today that it will acquire rival HPC server maker SGI for $7.75 per share, or about $275 million, inclusive of cash and debt. The deal ends the seven-year reprieve that kept the SGI banner flying after Rackable Systems purchased the bankrupt Silicon Graphics Inc. for $25 million in 2009 and assumed the SGI brand. Bringing SGI into its fold bolsters HPE's high-performance computing and data analytics capabilities and expands its position... Read more…

By Tiffany Trader

ARM Unveils Scalable Vector Extension for HPC at Hot Chips

August 22, 2016

ARM and Fujitsu today announced a scalable vector extension (SVE) to the ARMv8-A architecture intended to enhance ARM capabilities in HPC workloads. Fujitsu is the lead silicon partner in the effort (so far) and will use ARM with SVE technology in its post K computer, Japan’s next flagship supercomputer planned for the 2020 timeframe. This is an important incremental step for ARM, which seeks to push more aggressively into mainstream and HPC server markets. Read more…

By John Russell

IBM Debuts Power8 Chip with NVLink and Three New Systems

September 8, 2016

Not long after revealing more details about its next-gen Power9 chip due in 2017, IBM today rolled out three new Power8-based Linux servers and a new version of its Power8 chip featuring Nvidia’s NVLink interconnect. Read more…

By John Russell

Leading Solution Providers

Vectors: How the Old Became New Again in Supercomputing

September 26, 2016

Vector instructions, once a powerful performance innovation of supercomputing in the 1970s and 1980s became an obsolete technology in the 1990s. But like the mythical phoenix bird, vector instructions have arisen from the ashes. Here is the history of a technology that went from new to old then back to new. Read more…

By Lynd Stringer

US, China Vie for Supercomputing Supremacy

November 14, 2016

The 48th edition of the TOP500 list is fresh off the presses and while there is no new number one system, as previously teased by China, there are a number of notable entrants from the US and around the world and significant trends to report on. Read more…

By Tiffany Trader

Intel Launches Silicon Photonics Chip, Previews Next-Gen Phi for AI

August 18, 2016

At the Intel Developer Forum, held in San Francisco this week, Intel Senior Vice President and General Manager Diane Bryant announced the launch of Intel's Silicon Photonics product line and teased a brand-new Phi product, codenamed "Knights Mill," aimed at machine learning workloads. Read more…

By Tiffany Trader

CPU Benchmarking: Haswell Versus POWER8

June 2, 2015

With OpenPOWER activity ramping up and IBM’s prominent role in the upcoming DOE machines Summit and Sierra, it’s a good time to look at how the IBM POWER CPU stacks up against the x86 Xeon Haswell CPU from Intel. Read more…

By Tiffany Trader

Beyond von Neumann, Neuromorphic Computing Steadily Advances

March 21, 2016

Neuromorphic computing – brain inspired computing – has long been a tantalizing goal. The human brain does with around 20 watts what supercomputers do with megawatts. And power consumption isn’t the only difference. Fundamentally, brains ‘think differently’ than the von Neumann architecture-based computers. While neuromorphic computing progress has been intriguing, it has still not proven very practical. Read more…

By John Russell

Dell EMC Engineers Strategy to Democratize HPC

September 29, 2016

The freshly minted Dell EMC division of Dell Technologies is on a mission to take HPC mainstream with a strategy that hinges on engineered solutions, beginning with a focus on three industry verticals: manufacturing, research and life sciences. "Unlike traditional HPC where everybody bought parts, assembled parts and ran the workloads and did iterative engineering, we want folks to focus on time to innovation and let us worry about the infrastructure," said Jim Ganthier, senior vice president, validated solutions organization at Dell EMC Converged Platforms Solution Division. Read more…

By Tiffany Trader

Container App ‘Singularity’ Eases Scientific Computing

October 20, 2016

HPC container platform Singularity is just six months out from its 1.0 release but already is making inroads across the HPC research landscape. It's in use at Lawrence Berkeley National Laboratory (LBNL), where Singularity founder Gregory Kurtzer has worked in the High Performance Computing Services (HPCS) group for 16 years. Read more…

By Tiffany Trader

Micron, Intel Prepare to Launch 3D XPoint Memory

August 16, 2016

Micron Technology used last week’s Flash Memory Summit to roll out its new line of 3D XPoint memory technology jointly developed with Intel while demonstrating the technology in solid-state drives. Micron claimed its Quantx line delivers PCI Express (PCIe) SSD performance with read latencies at less than 10 microseconds and writes at less than 20 microseconds. Read more…

By George Leopold

  • arrow
  • Click Here for More Headlines
  • arrow
Share This