check transfer  0.1
Check data transfer for SDAccell OpenCL application
Functions
xcl Namespace Reference

Functions

std::string find_binary_file (const std::string &_device_name, const std::string &xclbin_name)
 
std::vector< cl::Device > get_devices (const std::string &vendor_name)
 
std::vector< cl::Device > get_xil_devices ()
 
cl::Program::Binaries import_binary_file (std::string xclbin_file_name)
 
bool is_emulation ()
 
bool is_hw_emulation ()
 

Function Documentation

◆ find_binary_file()

std::string xcl::find_binary_file ( const std::string &  _device_name,
const std::string &  xclbin_name 
)

Definition at line 89 of file xcl2.cpp.

Referenced by aligned_allocator< T >::deallocate().

90 {
91  std::cout << "XCLBIN File Name: " << xclbin_name.c_str() << std::endl;
92  char *xcl_mode = getenv("XCL_EMULATION_MODE");
93  char *xcl_target = getenv("XCL_TARGET");
94  std::string mode;
95 
96  /* Fall back mode if XCL_EMULATION_MODE is not set is "hw" */
97  if(xcl_mode == NULL) {
98  mode = "hw";
99  } else {
100  /* if xcl_mode is set then check if it's equal to true*/
101  if(strcmp(xcl_mode,"true") == 0) {
102  /* if it's true, then check if xcl_target is set */
103  if(xcl_target == NULL) {
104  /* default if emulation but not specified is software emulation */
105  mode = "sw_emu";
106  } else {
107  /* otherwise, it's what ever is specified in XCL_TARGET */
108  mode = xcl_target;
109  }
110  } else {
111  /* if it's not equal to true then it should be whatever
112  * XCL_EMULATION_MODE is set to */
113  mode = xcl_mode;
114  }
115  }
116  char *xcl_bindir = getenv("XCL_BINDIR");
117 
118  // typical locations of directory containing xclbin files
119  const char *dirs[] = {
120  xcl_bindir, // $XCL_BINDIR-specified
121  "xclbin", // command line build
122  "..", // gui build + run
123  ".", // gui build, run in build directory
124  NULL
125  };
126  const char **search_dirs = dirs;
127  if (xcl_bindir == NULL) {
128  search_dirs++;
129  }
130 
131  char *device_name = strdup(_device_name.c_str());
132  if (device_name == NULL) {
133  printf("Error: Out of Memory\n");
134  exit(EXIT_FAILURE);
135  }
136 
137  // fix up device name to avoid colons and dots.
138  // xilinx:xil-accel-rd-ku115:4ddr-xpr:3.2 -> xilinx_xil-accel-rd-ku115_4ddr-xpr_3_2
139  for (char *c = device_name; *c != 0; c++) {
140  if (*c == ':' || *c == '.') {
141  *c = '_';
142  }
143  }
144 
145  char *device_name_versionless = strdup(_device_name.c_str());
146  if (device_name_versionless == NULL) {
147  printf("Error: Out of Memory\n");
148  exit(EXIT_FAILURE);
149  }
150 
151  unsigned short colons = 0;
152  for (char *c = device_name_versionless; *c != 0; c++) {
153  if (*c == ':') {
154  colons++;
155  *c = '_';
156  }
157  /* Zero out version area */
158  if (colons == 3) {
159  *c = '\0';
160  }
161  }
162 
163  const char *file_patterns[] = {
164  "%1$s/%2$s.%3$s.%4$s.xclbin", // <kernel>.<target>.<device>.xclbin
165  "%1$s/%2$s.%3$s.%5$s.xclbin", // <kernel>.<target>.<device_versionless>.xclbin
166  "%1$s/binary_container_1.xclbin", // default for gui projects
167  "%1$s/%2$s.xclbin", // <kernel>.xclbin
168  NULL
169  };
170  char xclbin_file_name[PATH_MAX];
171  memset(xclbin_file_name, 0, PATH_MAX);
172  ino_t ino = 0; // used to avoid errors if an xclbin found via multiple/repeated paths
173  for (const char **dir = search_dirs; *dir != NULL; dir++) {
174  struct stat sb;
175  if (stat(*dir, &sb) == 0 && S_ISDIR(sb.st_mode)) {
176  for (const char **pattern = file_patterns; *pattern != NULL; pattern++) {
177  char file_name[PATH_MAX];
178  memset(file_name, 0, PATH_MAX);
179  snprintf(file_name, PATH_MAX, *pattern, *dir, xclbin_name.c_str(), mode.c_str(), device_name, device_name_versionless);
180  if (stat(file_name, &sb) == 0 && S_ISREG(sb.st_mode)) {
181  char* bindir = strdup(*dir);
182  if (bindir == NULL) {
183  printf("Error: Out of Memory\n");
184  exit(EXIT_FAILURE);
185  }
186  if (*xclbin_file_name && sb.st_ino != ino) {
187  printf("Error: multiple xclbin files discovered:\n %s\n %s\n", file_name, xclbin_file_name);
188  exit(EXIT_FAILURE);
189  }
190  ino = sb.st_ino;
191  strncpy(xclbin_file_name, file_name, PATH_MAX);
192  }
193  }
194  }
195  }
196  // if no xclbin found, preferred path for error message from xcl_import_binary_file()
197  if (*xclbin_file_name == '\0') {
198  snprintf(xclbin_file_name, PATH_MAX, file_patterns[0], *search_dirs, xclbin_name.c_str(), mode.c_str(), device_name);
199  }
200 
201  free(device_name);
202  return (xclbin_file_name);
203 }

◆ get_devices()

std::vector< cl::Device > xcl::get_devices ( const std::string &  vendor_name)

Definition at line 35 of file xcl2.cpp.

Referenced by aligned_allocator< T >::deallocate(), and get_xil_devices().

35  {
36 
37  size_t i;
38  std::vector<cl::Platform> platforms;
39  cl::Platform::get(&platforms);
40  cl::Platform platform;
41  for (i = 0 ; i < platforms.size(); i++){
42  platform = platforms[i];
43  std::string platformName = platform.getInfo<CL_PLATFORM_NAME>();
44  std::cout << "platform Name: " << platformName.c_str() << std::endl
45  << "Vendor Name : " << vendor_name.c_str()
46  << std::endl;
47  if (platformName == vendor_name){
48  std::cout << "Found Platform" << std::endl;
49  break;
50  }
51  }
52  if (i == platforms.size()) {
53  std::cout << "Error: Failed to find Xilinx platform" << std::endl;
54  exit(EXIT_FAILURE);
55  }
56 
57  //Getting ACCELERATOR Devices and selecting 1st such device
58  std::vector<cl::Device> devices;
59  platform.getDevices(CL_DEVICE_TYPE_ACCELERATOR, &devices);
60  return devices;
61 }

◆ get_xil_devices()

std::vector< cl::Device > xcl::get_xil_devices ( )

Definition at line 63 of file xcl2.cpp.

References get_devices().

Referenced by aligned_allocator< T >::deallocate(), and TF_Device::TF_Device().

63  {
64  return get_devices("Xilinx");
65 }
std::vector< cl::Device > get_devices(const std::string &vendor_name)
Definition: xcl2.cpp:35

◆ import_binary_file()

cl::Program::Binaries xcl::import_binary_file ( std::string  xclbin_file_name)

Definition at line 66 of file xcl2.cpp.

Referenced by aligned_allocator< T >::deallocate(), and TF_Device::TF_Device().

67 {
68  std::cout << "INFO: Importing " << xclbin_file_name << std::endl;
69 
70  if(access(xclbin_file_name.c_str(), R_OK) != 0) {
71  printf("ERROR: %s xclbin not available please build\n", xclbin_file_name.c_str());
72  exit(EXIT_FAILURE);
73  }
74  //Loading XCL Bin into char buffer
75  std::cout << "Loading: '" << xclbin_file_name.c_str() << "'\n";
76  std::ifstream bin_file(xclbin_file_name.c_str(), std::ifstream::binary);
77  bin_file.seekg (0, bin_file.end);
78  unsigned nb = bin_file.tellg();
79  bin_file.seekg (0, bin_file.beg);
80  char *buf = new char [nb];
81  bin_file.read(buf, nb);
82 
83  cl::Program::Binaries bins;
84  bins.push_back({buf,nb});
85  return bins;
86 }

◆ is_emulation()

bool xcl::is_emulation ( )

Definition at line 205 of file xcl2.cpp.

Referenced by aligned_allocator< T >::deallocate().

206 {
207  bool ret =false;
208  char *xcl_mode = getenv("XCL_EMULATION_MODE");
209  if (xcl_mode != NULL){
210  ret = true;
211  }
212  return ret;
213 }

◆ is_hw_emulation()

bool xcl::is_hw_emulation ( )

Definition at line 215 of file xcl2.cpp.

Referenced by aligned_allocator< T >::deallocate().

216 {
217  bool ret =false;
218  char *xcl_mode = getenv("XCL_EMULATION_MODE");
219  if ((xcl_mode != NULL) && !strcmp(xcl_mode, "hw_emu")){
220  ret = true;
221  }
222  return ret;
223 }