| 371 | } |
| 372 | |
| 373 | int main(int argc, char* argv[]) { |
| 374 | |
| 375 | cl_int err; |
| 376 | const char* xclbinFilename = "./adam.xclbin"; |
| 377 | //const char* xclbinFilename = argv[1]; |
| 378 | |
| 379 | // Creates a vector of DATA_SIZE elements with an initial value of 10 and 32 |
| 380 | // using customized allocator for getting buffer alignment to 4k boundary |
| 381 | |
| 382 | std::vector<cl::Device> devices = xcl::get_xil_devices(); |
| 383 | //print_device_bdf (devices); |
| 384 | cl::Device device = devices[0]; |
| 385 | |
| 386 | devices.resize(1); |
| 387 | |
| 388 | // Creating Context and Command Queue for selected device |
| 389 | cl::Context* ctx_ptr = new cl::Context(devices[0]); |
| 390 | cl::Context context = *ctx_ptr; |
| 391 | cl::CommandQueue q = cl::CommandQueue(context, device, CL_QUEUE_PROFILING_ENABLE); |
| 392 | |
| 393 | // Load xclbin |
| 394 | std::cout << "Loading: '" << xclbinFilename << "'\n"; |
| 395 | std::ifstream bin_file(xclbinFilename, std::ifstream::binary); |
| 396 | bin_file.seekg (0, bin_file.end); |
| 397 | unsigned nb = bin_file.tellg(); // print out #bits of file |
| 398 | bin_file.seekg (0, bin_file.beg); |
| 399 | char *buf = new char [nb]; |
| 400 | bin_file.read(buf, nb); |
| 401 | bin_file.close(); |
| 402 | |
| 403 | // Creating Program from Binary File |
| 404 | cl::Program::Binaries bins; |
| 405 | bins.push_back({buf,nb}); //Multiple bin files is possible |
| 406 | |
| 407 | cl::Program program = cl::Program(context, devices, bins); |
| 408 | |
| 409 | cl::Kernel krnl_adam(program,"krnl_vadd"); |
| 410 | delete[] buf; |
| 411 | |
| 412 | std::cout << "Loading Success!: '" << xclbinFilename << "'\n"; |
| 413 | |
| 414 | int nvmeFd = -1; |
| 415 | int ret; |
| 416 | nvmeFd = open(param_name.c_str(), O_RDWR | O_SYNC | O_CREAT | O_DIRECT, 0644); |
| 417 | if (nvmeFd < 0){ |
| 418 | std::cerr << "ERROR: open " << param_name << " failed with " << nvmeFd << std::endl; |
| 419 | return EXIT_FAILURE; |
| 420 | } |
| 421 | |
| 422 | struct stat fstat; |
| 423 | stat(param_name.c_str(), &fstat); |
| 424 | int blksize = (int) fstat.st_blksize; |
| 425 | std::cout << "blksize : " << blksize<<std::endl; |
| 426 | assert(blksize == 4096); |
| 427 | |
| 428 | size_t padded_size = ((DATA_SIZE-1)/blksize + 1 ) * blksize; |
| 429 | size_t nbytes = padded_size * sizeof(float); |
| 430 |
nothing calls this directly
no test coverage detected