MCPcopy Create free account
hub / github.com/AIS-SNU/Smart-Infinity / main

Function main

hls_smartInfinity/src/host/host_step_adagrad.cpp:332–518  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

330}
331
332int main(int argc, char* argv[]) {
333
334 cl_int err;
335 const char* xclbinFilename = "adagrad.xclbin";
336
337 // Creates a vector of DATA_SIZE elements with an initial value of 10 and 32
338 // using customized allocator for getting buffer alignment to 4k boundary
339
340 std::vector<cl::Device> devices = xcl::get_xil_devices();
341 //print_device_bdf (devices);
342 cl::Device device = devices[0];
343
344 devices.resize(1);
345
346 // Creating Context and Command Queue for selected device
347 cl::Context* ctx_ptr = new cl::Context(devices[0]);
348 cl::Context context = *ctx_ptr;
349 cl::CommandQueue q = cl::CommandQueue(context, device, CL_QUEUE_PROFILING_ENABLE);
350
351 // Load xclbin
352 std::cout << "Loading: '" << xclbinFilename << "'\n";
353 std::ifstream bin_file(xclbinFilename, std::ifstream::binary);
354 bin_file.seekg (0, bin_file.end);
355 unsigned nb = bin_file.tellg(); // print out #bits of file
356 bin_file.seekg (0, bin_file.beg);
357 char *buf = new char [nb];
358 bin_file.read(buf, nb);
359 bin_file.close();
360
361 // Creating Program from Binary File
362 cl::Program::Binaries bins;
363 bins.push_back({buf,nb}); //Multiple bin files is possible
364
365 cl::Program program = cl::Program(context, devices, bins);
366
367 cl::Kernel krnl_adagrad(program,"krnl_vadd");
368 delete[] buf;
369
370 std::cout << "Loading Success!: '" << xclbinFilename << "'\n";
371
372 int nvmeFd = -1;
373 int ret;
374 nvmeFd = open(param_name.c_str(), O_RDWR | O_SYNC | O_CREAT | O_DIRECT, 0644);
375 if (nvmeFd < 0){
376 std::cerr << "ERROR: open " << param_name << " failed with " << nvmeFd << std::endl;
377 return EXIT_FAILURE;
378 }
379
380 struct stat fstat;
381 stat(param_name.c_str(), &fstat);
382 int blksize = 128;
383 std::cout << "blksize : " << blksize<<std::endl;
384 assert(blksize == 128);
385
386 size_t padded_size = ((DATA_SIZE-1)/blksize + 1 ) * blksize;
387 size_t nbytes = padded_size * sizeof(float);
388
389 std::vector<float, aligned_allocator<float>> param_src(padded_size);

Callers

nothing calls this directly

Calls 5

readMethod · 0.80
get_xil_devicesFunction · 0.70
statClass · 0.70
adagrad_fpgaFunction · 0.70
AdagradCPUFunction · 0.70

Tested by

no test coverage detected