Skip to content

fraguela/hpl

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Heterogenerous Programming Libray (HPL)

The Heterogeneous Programming Library (HPL) is a C++ framework that provides an easy and portable way to exploit heterogeneous computing systems on top of the OpenCL standard. HPL can be used in two ways that can be mixed:

  • on top of existing OpenCL kernels, largely simplifying their usage, or
  • developing the heterogeneous kernels in the embedded language it provides, which is naturally integrated in C++

As an example, the code below computes the SAXPY function Y = alpha * X + Y, which is described in the C++ function saxpy using the HPL embedded language.

#include "HPL.h"

using namespace HPL;

//SAXPY kernel in which thread idx computes y[idx]
void saxpy(Array<float,1> y, Array<float,1> x, Float alpha) 
{
  y[idx] = alpha * x[idx] + y[idx];
}


int main(int argc, char **argv) 
{  Array<float, 1> x(1000), y(1000);
  float alpha;
 
  //the vectors x and y are filled in with data (not shown)
 
  //Run SAXPY on an accelerator, or the CPU if no OpenCL capable accelerator is found
  eval(saxpy)(y, x, alpha);
}

If an OpenCL C kernel is already available, it can be associated to a C++ function that is used to invoke it in HPL. The function parameter list specifies whether each non scalar arguments is an input, an output or both. HPL can get the kernel from a file or a string in the program. The following example illustrates this second possibility.

#include "HPL.h"

using namespace HPL;

//string with the OpenCL C kernel for SAXPY
const char *saxpy_kernel = 
  "__kernel void saxpy(__global float *y, __global float *x, float alpha) {\n \
     int i = get_global_id(0);                                             \n \
     y[i] = alpha * x[i] + y[i];                                           \n \
  }";


//Function whose arguments define the kernel for HPL
void saxpy_handle(InOut< Array<float,1> > y, In< Array<float,1> > x, Float alpha)
{ }


int main(int argc, char **argv) 
{  Array<float, 1> x(1000), y(1000);
   float alpha;
  
   //the vectors x and y are filled in with data (not shown)

   //associate the kernel string with the HPL function handle
   nativeHandle(saxpy_handle, “saxpy”, saxpy_kernel);

   eval(saxpy_handle)(y, x, alpha);
}

Requirements

  • At least one OpenCL distribution that supports version 1.1 of the standard. HPL currently supports AMD, Apple, Intel and NVIDIA implementations.
  • A C++ compiler that supports C++11

Documentation

Publications

About

Heterogeneous Programming Library. Facilitates the use of accelerators on top of OpenCL

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages