Apache Singa
A General Distributed Deep Learning Library
opencl_utils.h
1 /************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21 
22 #ifndef SINGA_UTILS_OPENCL_UTILS_H_
23 #define SINGA_UTILS_OPENCL_UTILS_H_
24 
25 #ifdef USE_OPENCL
26 
27 #define CL_USE_DEPRECATED_OPENCL_1_2_APIS
28 
29 #define CL_HPP_MINIMUM_OPENCL_VERSION 120
30 #define CL_HPP_TARGET_OPENCL_VERSION 120
31 
32 #ifndef VIENNACL_WITH_OPENCL
33  #define VIENNACL_WITH_OPENCL
34 #endif
35 
36 #ifndef __APPLE__
37  #include "CL/cl.h"
38 #else
39  #include "OpenCL/cl.h"
40 #endif
41 
42 #include <viennacl/backend/opencl.hpp>
43 
44 #include <viennacl/ocl/device.hpp>
45 #include <viennacl/ocl/platform.hpp>
46 #include <viennacl/ocl/backend.hpp>
47 #include <viennacl/ocl/device_utils.hpp>
48 #include <viennacl/ocl/utils.hpp>
49 #include <viennacl/ocl/program.hpp>
50 #include <viennacl/ocl/kernel.hpp>
51 
52 
53 inline viennacl::ocl::handle<cl_mem>
54 WrapHandle(cl_mem in, viennacl::ocl::context &ctx) {
55  if (in != nullptr) {
56  viennacl::ocl::handle<cl_mem> memhandle(in, ctx);
57  memhandle.inc();
58  return memhandle;
59  } else {
60  cl_int err;
61  cl_mem dummy = clCreateBuffer(ctx.handle().get(), CL_MEM_READ_WRITE, 0,
62  nullptr, &err);
63  viennacl::ocl::handle<cl_mem> memhandle(dummy, ctx);
64  return memhandle;
65  }
66 }
67 
68 #endif // USE_OPENCL
69 
70 #endif // SINGA_UTILS_OPENCL_UTILS_H_