Programming the Host - 2023.2 日本語

Vitis チュートリアル: ハードウェア アクセラレーション (XD099)

Document ID
XD099
Release Date
2023-11-13
Version
2023.2 日本語
  1. Create the entire platform and OpenCL kernels.

    cl::Kernel krnls_wa;
    cl::Kernel krnls_sssp;
    cl::Kernel krnls_search;
    auto devices = xcl::get_xil_devices();  
    std::vector<cl::Memory> init_wa,init_sssp,init_search;
    cl::Context context(device, NULL, NULL, NULL, &fail);
    cl::CommandQueue q(context, device, CL_QUEUE_PROFILING_ENABLE,  &fail);
    cl::Program::Binaries bins = xcl::import_binary_file(xclbin_path);
    cl::Program program(context, devices, bins, NULL, &fail);
    krnls_wa = cl::Kernel(program,"weight_average", &fail);
    krnls_sssp = cl::Kernel(program, "shortestPath_top", &fail);
    krnls_search = cl::Kernel(program, "search", &fail);
    ```
    * Create Buffers and transfer data to FPGA devices
    ```
    std::vector<cl_mem_ext_ptr_t> mext_o(15);
    cl::Buffer offset_buf, column_buf, weight_buf, info_buf, ddrQue_buf, result_buf, config_buf, pred_buf;
    cl::Buffer cost_buf,flow_free_time_buf,Volume_buf,capacity_buf,out_buf,longitude_buf,latitude_buf; 
    std::vector<cl::Memory> init_wa,init_sssp,init_search;
    
    init_wa.push_back(cost_buf);
    init_wa.push_back(flow_free_time_buf);
    init_wa.push_back(Volume_buf);
    init_wa.push_back(capacity_buf);
    init_wa.push_back(weight_buf);
    init_wa.push_back(result_buf);
    
    init_sssp.push_back(config_buf);
    init_sssp.push_back(offset_buf);
    init_sssp.push_back(column_buf);
    init_sssp.push_back(info_buf);
    
    init_search.push_back(longitude_buf);
    init_search.push_back(latitude_buf);
    ```
    
  2. Set arguments and run the tasks.

    krnls_wa.setArg(j++,cost_buf);
    krnls_wa.setArg(j++,flow_free_time_buf);
    krnls_wa.setArg(j++,Volume_buf);
    krnls_wa.setArg(j++,capacity_buf);
    krnls_wa.setArg(j++,weight_buf);
    krnls_wa.setArg(j++,size);
    
    q.enqueueTask(krnls_wa);
    
    ...
    
    krnls_sssp.setArg(j++, config_buf);
    krnls_sssp.setArg(j++, offset_buf);
    krnls_sssp.setArg(j++, column_buf);
    krnls_sssp.setArg(j++, weight_buf);
    krnls_sssp.setArg(j++, ddrQue_buf);
    krnls_sssp.setArg(j++, ddrQue_buf);
    krnls_sssp.setArg(j++, result_buf);
    krnls_sssp.setArg(j++, result_buf);
    krnls_sssp.setArg(j++, pred_buf);
    krnls_sssp.setArg(j++, pred_buf);
    krnls_sssp.setArg(j++, info_buf);
    
    q.enqueueTask(krnls_sssp);
    
    ...
    
    krnls_search.setArg(j++,result_buf);
    krnls_search.setArg(j++,longitude_buf);
    krnls_search.setArg(j++,latitude_buf);
    krnls_search.setArg(j++,out_buf);
    krnls_search.setArg(j++,size);
    
    q.enqueueTask(krnls_search);
    
  3. Develop the main.cpp file.

    std::cout <<"\n---------------------" << city << " City Shortest Path from source 0----------------\n";
    std::cout << "The start point is: 0 " << "longitude: " << out[0] << " latitude: " << out[1] << std::endl;
    std::cout << "Please input your choice: " << std::endl;
    std::cout << "Input 0 : show all the result and exit."<< std::endl;
    std::cout << "Input point range in ( 1 to "<< numVertices-1 << " ): show the path from start point to the enter point."<<std::endl;
    std::cout << "Input y to exit !" << std::endl;
    
    int m;
    
    while(std::cin >> m){
      if(m==0)
        {
          ...
    
          break;	
    
        }
        else if (m>numVertices-1)
        {
          ...
    
        }
        else if (std::cin.get()=='y')
        {
          break;
        }
    
        else
        {
          ...
        }
      }