check transfer  0.1
Check data transfer for SDAccell OpenCL application
xcl2.hpp
Go to the documentation of this file.
1 /**********
2 Copyright (c) 2017, Xilinx, Inc.
3 All rights reserved.
4 
5 Redistribution and use in source and binary forms, with or without modification,
6 are permitted provided that the following conditions are met:
7 
8 1. Redistributions of source code must retain the above copyright notice,
9 this list of conditions and the following disclaimer.
10 
11 2. Redistributions in binary form must reproduce the above copyright notice,
12 this list of conditions and the following disclaimer in the documentation
13 and/or other materials provided with the distribution.
14 
15 3. Neither the name of the copyright holder nor the names of its contributors
16 may be used to endorse or promote products derived from this software
17 without specific prior written permission.
18 
19 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
21 THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22 IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
23 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
27 EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 **********/
29 
30 
31 #pragma once
32 
33 #define CL_HPP_CL_1_2_DEFAULT_BUILD
34 #define CL_HPP_TARGET_OPENCL_VERSION 120
35 #define CL_HPP_MINIMUM_OPENCL_VERSION 120
36 #define CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY 1
37 
38 #include <CL/cl2.hpp>
39 #include <iostream>
40 #include <fstream>
41 
42 // When creating a buffer with user pointer (CL_MEM_USE_HOST_PTR), under the hood
43 // User ptr is used if and only if it is properly aligned (page aligned). When not
44 // aligned, runtime has no choice but to create its own host side buffer that backs
45 // user ptr. This in turn implies that all operations that move data to and from
46 // device incur an extra memcpy to move data to/from runtime's own host buffer
47 // from/to user pointer. So it is recommended to use this allocator if user wish to
48 // Create Buffer/Memory Object with CL_MEM_USE_HOST_PTR to align user buffer to the
49 // page boundary. It will ensure that user buffer will be used when user create
50 // Buffer/Mem Object with CL_MEM_USE_HOST_PTR.
51 template <typename T>
53 {
54  using value_type = T;
55  T* allocate(std::size_t num)
56  {
57  void* ptr = nullptr;
58  if (posix_memalign(&ptr,4096,num*sizeof(T)))
59  throw std::bad_alloc();
60  return reinterpret_cast<T*>(ptr);
61  }
62  void deallocate(T* p, std::size_t num)
63  {
64  free(p);
65  }
66 };
67 
68 namespace xcl {
69 std::vector<cl::Device> get_xil_devices();
70 std::vector<cl::Device> get_devices(const std::string& vendor_name);
71 /* find_xclbin_file
72  *
73  *
74  * Description:
75  * Find precompiled program (as commonly created by the Xilinx OpenCL
76  * flow). Using search path below.
77  *
78  * Search Path:
79  * $XCL_BINDIR/<name>.<target>.<device>.xclbin
80  * $XCL_BINDIR/<name>.<target>.<device_versionless>.xclbin
81  * $XCL_BINDIR/binary_container_1.xclbin
82  * $XCL_BINDIR/<name>.xclbin
83  * xclbin/<name>.<target>.<device>.xclbin
84  * xclbin/<name>.<target>.<device_versionless>.xclbin
85  * xclbin/binary_container_1.xclbin
86  * xclbin/<name>.xclbin
87  * ../<name>.<target>.<device>.xclbin
88  * ../<name>.<target>.<device_versionless>.xclbin
89  * ../binary_container_1.xclbin
90  * ../<name>.xclbin
91  * ./<name>.<target>.<device>.xclbin
92  * ./<name>.<target>.<device_versionless>.xclbin
93  * ./binary_container_1.xclbin
94  * ./<name>.xclbin
95  *
96  * Inputs:
97  * _device_name - Targeted Device name
98  * xclbin_name - base name of the xclbin to import.
99  *
100  * Returns:
101  * An opencl program Binaries object that was created from xclbin_name file.
102  */
103 std::string find_binary_file(const std::string& _device_name, const std::string& xclbin_name);
104 cl::Program::Binaries import_binary_file(std::string xclbin_file_name);
105 bool is_emulation () ;
106 bool is_hw_emulation () ;
107 
108 }
bool is_emulation()
Definition: xcl2.cpp:205
std::string find_binary_file(const std::string &_device_name, const std::string &xclbin_name)
Definition: xcl2.cpp:89
Definition: xcl2.cpp:34
void deallocate(T *p, std::size_t num)
Definition: xcl2.hpp:62
std::vector< cl::Device > get_xil_devices()
Definition: xcl2.cpp:63
std::vector< cl::Device > get_devices(const std::string &vendor_name)
Definition: xcl2.cpp:35
bool is_hw_emulation()
Definition: xcl2.cpp:215
cl::Program::Binaries import_binary_file(std::string xclbin_file_name)
Definition: xcl2.cpp:66
T * allocate(std::size_t num)
Definition: xcl2.hpp:55