#define CL_HPP_CL_1_2_DEFAULT_BUILD #define CL_HPP_TARGET_OPENCL_VERSION 120 #define CL_HPP_MINIMUM_OPENCL_VERSION 120 #define CL_HPP_ENABLE_PROGRAM_CONSTRUCTION_FROM_ARRAY_COMPATIBILITY 1 #define CL_USE_DEPRECATED_OPENCL_1_2_APIS //OCL_CHECK doesn't work if call has templatized function call #define OCL_CHECK(error,call) \ call; \ if (error != CL_SUCCESS) { \ printf("%s:%d Error calling " #call ", error code is: %d\n", \ __FILE__,__LINE__, error); \ exit(EXIT_FAILURE); \ } #define DATA_SIZE 4096 #include #include #include #include #include template struct aligned_allocator { using value_type = T; T* allocate(std::size_t num) { void* ptr = nullptr; if (posix_memalign(&ptr,4096,num*sizeof(T))) throw std::bad_alloc(); return reinterpret_cast(ptr); } void deallocate(T* p, std::size_t num) { free(p); } }; std::vector get_devices(const std::string& vendor_name) { size_t i; cl_int err; std::vector platforms; OCL_CHECK(err, err = cl::Platform::get(&platforms)); cl::Platform platform; for (i = 0 ; i < platforms.size(); i++){ platform = platforms[i]; OCL_CHECK(err, std::string platformName = platform.getInfo(&err)); if (platformName == vendor_name){ std::cout << "Found Platform" << std::endl; std::cout << "Platform Name: " << platformName.c_str() << std::endl; break; } } if (i == platforms.size()) { std::cout << "Error: Failed to find Xilinx platform" << std::endl; exit(EXIT_FAILURE); } //Getting ACCELERATOR Devices and selecting 1st such device std::vector devices; OCL_CHECK(err, err = platform.getDevices(CL_DEVICE_TYPE_ACCELERATOR, &devices)); return devices; } char* read_binary_file(const std::string &xclbin_file_name, unsigned &nb) { std::cout << "INFO: Reading " << xclbin_file_name << std::endl; if(access(xclbin_file_name.c_str(), R_OK) != 0) { printf("ERROR: %s xclbin not available please build\n", xclbin_file_name.c_str()); exit(EXIT_FAILURE); } //Loading XCL Bin into char buffer std::cout << "Loading: '" << xclbin_file_name.c_str() << "'\n"; std::ifstream bin_file(xclbin_file_name.c_str(), std::ifstream::binary); bin_file.seekg (0, bin_file.end); nb = bin_file.tellg(); bin_file.seekg (0, bin_file.beg); char *buf = new char [nb]; bin_file.read(buf, nb); return buf; }