cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
nirdhish
Contributor
Contributor
387 Views
Registered: ‎08-26-2018

[OpenCL][Vitis] Initialising memory from different banks

For my project, I have a Kernel using two ports A,B both mapped to HBM[0:1]. My kernel performs a read, adds one to the read value and writes it back to the same location using both the ports in parallel. I want the base address of the buffer corresponding to A to be 0x0 and the base address of the buffer corresponding to B to be 0x10000000. I also want to initialise the first 256 location of both the banks with i. 

So, I used OpenCL to initialise the memory to check if my kernel works as intended. Using the example program as a reference, 

1) I create the input data pattern

 h_data = (cl_uint*)aligned_alloc(MEM_ALIGNMENT,MAX_LENGTH * sizeof(cl_uint*));
    for(cl_uint i = 0; i < MAX_LENGTH; i++) {
        h_data[i]  = i;
}

 

2) Create buffers in the target banks

    cl_mem_ext_ptr_t mem_ext;
    mem_ext.obj = NULL;
    mem_ext.param = 0;
    
    mem_ext.flags = 0|XCL_MEM_TOPOLOGY;
    d_A = clCreateBuffer(context,  CL_MEM_READ_WRITE | CL_MEM_EXT_PTR_XILINX,  sizeof(cl_uint) * number_of_words, &mem_ext, &err);
    if (err != CL_SUCCESS) {
      std::cout << "Return code for clCreateBuffer flags=" << mem_ext.flags << ": " << err << std::endl;
    }


    mem_ext.flags = 1|XCL_MEM_TOPOLOGY;
    d_B = clCreateBuffer(context,  CL_MEM_READ_WRITE | CL_MEM_EXT_PTR_XILINX,  sizeof(cl_uint) * number_of_words, &mem_ext, &err);
    if (err != CL_SUCCESS) {
      std::cout << "Return code for clCreateBuffer flags=" << mem_ext.flags << ": " << err << std::endl;
    }

 

3) And write to it 

    err = clEnqueueWriteBuffer(commands, d_A, CL_TRUE, 0, sizeof(cl_uint) * number_of_words, h_data, 0, NULL, NULL);
    if (err != CL_SUCCESS) {
        printf("Error: Failed to write to source array h_data: d_A: %d!\n", err);
        printf("Test failed\n");
        return EXIT_FAILURE;
    }


    err = clEnqueueWriteBuffer(commands, d_B, CL_TRUE, 0, sizeof(cl_uint) * number_of_words, h_data, 0, NULL, NULL);
    if (err != CL_SUCCESS) {
        printf("Error: Failed to write to source array h_data: d_B: %d!\n", err);
        printf("Test failed\n");
        return EXIT_FAILURE;
    }

The program works fine. But, the memory is initialised to 0 rather than i. Where am I going wrong?

 

Tags (3)
0 Kudos
0 Replies