35 std::vector<cl::Device>
get_devices(
const std::string& vendor_name) {
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()
47 if (platformName == vendor_name){
48 std::cout <<
"Found Platform" << std::endl;
52 if (i == platforms.size()) {
53 std::cout <<
"Error: Failed to find Xilinx platform" << std::endl;
58 std::vector<cl::Device> devices;
59 platform.getDevices(CL_DEVICE_TYPE_ACCELERATOR, &devices);
68 std::cout <<
"INFO: Importing " << xclbin_file_name << std::endl;
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());
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);
83 cl::Program::Binaries bins;
84 bins.push_back({buf,nb});
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");
97 if(xcl_mode == NULL) {
101 if(strcmp(xcl_mode,
"true") == 0) {
103 if(xcl_target == NULL) {
116 char *xcl_bindir = getenv(
"XCL_BINDIR");
119 const char *dirs[] = {
126 const char **search_dirs = dirs;
127 if (xcl_bindir == NULL) {
131 char *device_name = strdup(_device_name.c_str());
132 if (device_name == NULL) {
133 printf(
"Error: Out of Memory\n");
139 for (
char *c = device_name; *c != 0; c++) {
140 if (*c ==
':' || *c ==
'.') {
145 char *device_name_versionless = strdup(_device_name.c_str());
146 if (device_name_versionless == NULL) {
147 printf(
"Error: Out of Memory\n");
151 unsigned short colons = 0;
152 for (
char *c = device_name_versionless; *c != 0; c++) {
163 const char *file_patterns[] = {
164 "%1$s/%2$s.%3$s.%4$s.xclbin",
165 "%1$s/%2$s.%3$s.%5$s.xclbin",
166 "%1$s/binary_container_1.xclbin",
170 char xclbin_file_name[PATH_MAX];
171 memset(xclbin_file_name, 0, PATH_MAX);
173 for (
const char **dir = search_dirs; *dir != NULL; dir++) {
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");
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);
191 strncpy(xclbin_file_name, file_name, PATH_MAX);
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);
202 return (xclbin_file_name);
208 char *xcl_mode = getenv(
"XCL_EMULATION_MODE");
209 if (xcl_mode != NULL){
218 char *xcl_mode = getenv(
"XCL_EMULATION_MODE");
219 if ((xcl_mode != NULL) && !strcmp(xcl_mode,
"hw_emu")){
std::string find_binary_file(const std::string &_device_name, const std::string &xclbin_name)
std::vector< cl::Device > get_xil_devices()
std::vector< cl::Device > get_devices(const std::string &vendor_name)
cl::Program::Binaries import_binary_file(std::string xclbin_file_name)