pytorch  1.0.1
About: PyTorch provides Tensor computation (like NumPy) with strong GPU acceleration and Deep Neural Networks (in Python) built on a tape-based autograd system.
  Fossies Dox: pytorch-1.0.1.tar.gz  ("inofficial" and yet experimental doxygen-generated source code documentation)  

pytorch Documentation

Introduction

For many large applications C++ is the language of choice and so it seems reasonable to define C++ bindings for OpenCL.

The interface is contained with a single C++ header file cl.hpp and all definitions are contained within the namespace cl. There is no additional requirement to include cl.h and to use either the C++ or original C bindings it is enough to simply include cl.hpp.

The bindings themselves are lightweight and correspond closely to the underlying C API. Using the C++ bindings introduces no additional execution overhead.

For detail documentation on the bindings see:

The OpenCL C++ Wrapper API 1.2 (revision 09) http://www.khronos.org/registry/cl/specs/opencl-cplusplus-1.2.pdf

Example

The following example shows a general use case for the C++ bindings, including support for the optional exception feature and also the supplied vector and string classes, see following sections for decriptions of these features.

#define __CL_ENABLE_EXCEPTIONS
#if defined(__APPLE__) || defined(__MACOSX)
#include <OpenCL/cl.hpp>
#else
#include <CL/cl.hpp>
#endif
#include <cstdio>
#include <cstdlib>
#include <iostream>
const char * helloStr = "__kernel void "
"hello(void) "
"{ "
" "
"} ";
int
main(void)
{
cl_int err = CL_SUCCESS;
try {
std::vector<cl::Platform> platforms;
cl::Platform::get(&platforms);
if (platforms.size() == 0) {
std::cout << "Platform size 0\n";
return -1;
}
cl_context_properties properties[] =
{ CL_CONTEXT_PLATFORM, (cl_context_properties)(platforms[0])(), 0};
std::vector<cl::Device> devices = context.getInfo<CL_CONTEXT_DEVICES>();
std::make_pair(helloStr,strlen(helloStr)));
program_.build(devices);
cl::Kernel kernel(program_, "hello", &err);
cl::Event event;
cl::CommandQueue queue(context, devices[0], 0, &err);
queue.enqueueNDRangeKernel(
NULL,
&event);
event.wait();
}
catch (cl::Error err) {
std::cerr
<< "ERROR: "
<< err.what()
<< "("
<< err.err()
<< ")"
<< std::endl;
}
return EXIT_SUCCESS;
}
cl::Platform::get
static cl_int get(VECTOR_CLASS< Platform > *platforms)
Gets a list of available platforms.
Definition: cl.hpp:2306
torch::jit.Error
Error
Definition: __init__.py:1458
cl::Kernel
Class interface for cl_kernel.
Definition: cl.hpp:4816
caffe2::kernel
stride pad lengths and dilation $L_p pooling consists of taking the $L_p norm of a subset of the input tensor according to the kernel size and downsampling the data into the output blob for further processing Pooling layers reduce the spatial dimensionality of the input blob Each of the output blob s dimensions will reduce according kernel
Definition: lp_pool_op.cc:256
cl.hpp
C++ bindings for OpenCL 1.0 (rev 48), OpenCL 1.1 (rev 33) and OpenCL 1.2 (rev 15)
cl::Program
Program interface that implements cl_program.
Definition: cl.hpp:4962
cl::Context
Class interface for cl_context.
Definition: cl.hpp:2436
bench_gen.main
def main(args)
Definition: bench_gen.py:25
context
Module caffe2.python.context.
CL_CONTEXT_DEVICES
#define CL_CONTEXT_DEVICES
Definition: cl.h:313
diagnose_protobuf.err
err
Definition: diagnose_protobuf.py:40
nom::repr::Program
Graph< Value > Program
Definition: ControlFlow.h:99
at::context
Context * context
Definition: GeneratorDerived.h:27
cl::CommandQueue
CommandQueue interface for cl_command_queue.
Definition: cl.hpp:5449
cl::Event
Class interface for cl_event.
Definition: cl.hpp:2809
cl::NDRange
Class interface for specifying NDRange values.
Definition: cl.hpp:4707
cl::Program::build
cl_int build(const VECTOR_CLASS< Device > &devices, const char *options=NULL, void(CL_CALLBACK *notifyFptr)(cl_program, void *)=NULL, void *data=NULL) const
Definition: cl.hpp:5207
CL_SUCCESS
#define CL_SUCCESS
Definition: cl.h:119
build_amd.source
source
Definition: build_amd.py:65
caffe2::db::queue
default queue
Definition: blobs_queue_db.cc:47
CL_DEVICE_TYPE_CPU
#define CL_DEVICE_TYPE_CPU
Definition: cl.h:200
cl::NullRange
static const NDRange NullRange
A zero-dimensional range.
Definition: cl.hpp:4756
CL_CONTEXT_PLATFORM
#define CL_CONTEXT_PLATFORM
Definition: cl.h:318
cl_context_properties
intptr_t cl_context_properties
Definition: cl.h:62
cl::Program::Sources
VECTOR_CLASS< std::pair< const char *, ::size_t > > Sources
Definition: cl.hpp:4966