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!

UCSD Web-based Tool Tracking CA Wildfires Generates 1.5M Views

October 16, 2017

Tracking the wildfires raging in northern CA is an unpleasant but necessary part of guiding efforts to fight the fires and safely evacuate affected residents. One such tool – Firemap – is a web-based tool developed b Read more…

By John Russell

Exascale Imperative: New Movie from HPE Makes a Compelling Case

October 13, 2017

Why is pursuing exascale computing so important? In a new video – Hewlett Packard Enterprise: Eighteen Zeros – four HPE executives, a prominent national lab HPC researcher, and HPCwire managing editor Tiffany Trader Read more…

By John Russell

Intel Delivers 17-Qubit Quantum Chip to European Research Partner

October 10, 2017

On Tuesday, Intel delivered a 17-qubit superconducting test chip to research partner QuTech, the quantum research institute of Delft University of Technology (TU Delft) in the Netherlands. The announcement marks a major milestone in the 10-year, $50-million collaborative relationship with TU Delft and TNO, the Dutch Organization for Applied Research, to accelerate advancements in quantum computing. Read more…

By Tiffany Trader

HPE Extreme Performance Solutions

“Lunch & Learn” to Explore the Growing Applications of Genomic Analytics

In the digital age of medicine, healthcare providers are rapidly transforming their approach to patient care. Traditional technologies are no longer sufficient to process vast quantities of medical data (including patient histories, treatment plans, diagnostic reports, and more), challenging organizations to invest in a new style of IT to enable faster and higher-quality care. Read more…

Fujitsu Tapped to Build 37-Petaflops ABCI System for AIST

October 10, 2017

Fujitsu announced today it will build the long-planned AI Bridging Cloud Infrastructure (ABCI) which is set to become the fastest supercomputer system in Japan and will begin operation in fiscal 2018 (starts in April). A Read more…

By John Russell

Intel Delivers 17-Qubit Quantum Chip to European Research Partner

October 10, 2017

On Tuesday, Intel delivered a 17-qubit superconducting test chip to research partner QuTech, the quantum research institute of Delft University of Technology (TU Delft) in the Netherlands. The announcement marks a major milestone in the 10-year, $50-million collaborative relationship with TU Delft and TNO, the Dutch Organization for Applied Research, to accelerate advancements in quantum computing. Read more…

By Tiffany Trader

Fujitsu Tapped to Build 37-Petaflops ABCI System for AIST

October 10, 2017

Fujitsu announced today it will build the long-planned AI Bridging Cloud Infrastructure (ABCI) which is set to become the fastest supercomputer system in Japan Read more…

By John Russell

HPC Chips – A Veritable Smorgasbord?

October 10, 2017

For the first time since AMD's ill-fated launch of Bulldozer the answer to the question, 'Which CPU will be in my next HPC system?' doesn't have to be 'Whichever variety of Intel Xeon E5 they are selling when we procure'. Read more…

By Dairsie Latimer

Delays, Smoke, Records & Markets – A Candid Conversation with Cray CEO Peter Ungaro

October 5, 2017

Earlier this month, Tom Tabor, publisher of HPCwire and I had a very personal conversation with Cray CEO Peter Ungaro. Cray has been on something of a Cinderell Read more…

By Tiffany Trader & Tom Tabor

Intel Debuts Programmable Acceleration Card

October 5, 2017

With a view toward supporting complex, data-intensive applications, such as AI inference, video streaming analytics, database acceleration and genomics, Intel i Read more…

By Doug Black

OLCF’s 200 Petaflops Summit Machine Still Slated for 2018 Start-up

October 3, 2017

The Department of Energy’s planned 200 petaflops Summit computer, which is currently being installed at Oak Ridge Leadership Computing Facility, is on track t Read more…

By John Russell

US Exascale Program – Some Additional Clarity

September 28, 2017

The last time we left the Department of Energy’s exascale computing program in July, things were looking very positive. Both the U.S. House and Senate had pas Read more…

By Alex R. Larzelere

US Coalesces Plans for First Exascale Supercomputer: Aurora in 2021

September 27, 2017

At the Advanced Scientific Computing Advisory Committee (ASCAC) meeting, in Arlington, Va., yesterday (Sept. 26), it was revealed that the "Aurora" supercompute Read more…

By Tiffany Trader

How ‘Knights Mill’ Gets Its Deep Learning Flops

June 22, 2017

Intel, the subject of much speculation regarding the delayed, rewritten or potentially canceled “Aurora” contract (the Argonne Lab part of the CORAL “ Read more…

By Tiffany Trader

Reinders: “AVX-512 May Be a Hidden Gem” in Intel Xeon Scalable Processors

June 29, 2017

Imagine if we could use vector processing on something other than just floating point problems.  Today, GPUs and CPUs work tirelessly to accelerate algorithms Read more…

By James Reinders

NERSC Scales Scientific Deep Learning to 15 Petaflops

August 28, 2017

A collaborative effort between Intel, NERSC and Stanford has delivered the first 15-petaflops deep learning software running on HPC platforms and is, according Read more…

By Rob Farber

Oracle Layoffs Reportedly Hit SPARC and Solaris Hard

September 7, 2017

Oracle’s latest layoffs have many wondering if this is the end of the line for the SPARC processor and Solaris OS development. As reported by multiple sources Read more…

By John Russell

US Coalesces Plans for First Exascale Supercomputer: Aurora in 2021

September 27, 2017

At the Advanced Scientific Computing Advisory Committee (ASCAC) meeting, in Arlington, Va., yesterday (Sept. 26), it was revealed that the "Aurora" supercompute Read more…

By Tiffany Trader

Google Releases Deeplearn.js to Further Democratize Machine Learning

August 17, 2017

Spreading the use of machine learning tools is one of the goals of Google’s PAIR (People + AI Research) initiative, which was introduced in early July. Last w Read more…

By John Russell

Graphcore Readies Launch of 16nm Colossus-IPU Chip

July 20, 2017

A second $30 million funding round for U.K. AI chip developer Graphcore sets up the company to go to market with its “intelligent processing unit” (IPU) in Read more…

By Tiffany Trader

GlobalFoundries Puts Wind in AMD’s Sails with 12nm FinFET

September 24, 2017

From its annual tech conference last week (Sept. 20), where GlobalFoundries welcomed more than 600 semiconductor professionals (reaching the Santa Clara venue Read more…

By Tiffany Trader

Leading Solution Providers

Amazon Debuts New AMD-based GPU Instances for Graphics Acceleration

September 12, 2017

Last week Amazon Web Services (AWS) streaming service, AppStream 2.0, introduced a new GPU instance called Graphics Design intended to accelerate graphics. The Read more…

By John Russell

Nvidia Responds to Google TPU Benchmarking

April 10, 2017

Nvidia highlights strengths of its newest GPU silicon in response to Google's report on the performance and energy advantages of its custom tensor processor. Read more…

By Tiffany Trader

EU Funds 20 Million Euro ARM+FPGA Exascale Project

September 7, 2017

At the Barcelona Supercomputer Centre on Wednesday (Sept. 6), 16 partners gathered to launch the EuroEXA project, which invests €20 million over three-and-a-half years into exascale-focused research and development. Led by the Horizon 2020 program, EuroEXA picks up the banner of a triad of partner projects — ExaNeSt, EcoScale and ExaNoDe — building on their work... Read more…

By Tiffany Trader

Cray Moves to Acquire the Seagate ClusterStor Line

July 28, 2017

This week Cray announced that it is picking up Seagate's ClusterStor HPC storage array business for an undisclosed sum. "In short we're effectively transitioning the bulk of the ClusterStor product line to Cray," said CEO Peter Ungaro. Read more…

By Tiffany Trader

Delays, Smoke, Records & Markets – A Candid Conversation with Cray CEO Peter Ungaro

October 5, 2017

Earlier this month, Tom Tabor, publisher of HPCwire and I had a very personal conversation with Cray CEO Peter Ungaro. Cray has been on something of a Cinderell Read more…

By Tiffany Trader & Tom Tabor

IBM Advances Web-based Quantum Programming

September 5, 2017

IBM Research is pairing its Jupyter-based Data Science Experience notebook environment with its cloud-based quantum computer, IBM Q, in hopes of encouraging a new class of entrepreneurial user to solve intractable problems that even exceed the capabilities of the best AI systems. Read more…

By Alex Woodie

Intel Launches Software Tools to Ease FPGA Programming

September 5, 2017

Field Programmable Gate Arrays (FPGAs) have a reputation for being difficult to program, requiring expertise in specialty languages, like Verilog or VHDL. Easin Read more…

By Tiffany Trader

Intel, NERSC and University Partners Launch New Big Data Center

August 17, 2017

A collaboration between the Department of Energy’s National Energy Research Scientific Computing Center (NERSC), Intel and five Intel Parallel Computing Cente Read more…

By Linda Barney

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