Xilinx / Vitis-Tutorials

Vitis In-Depth Tutorials
https://Xilinx.github.io/Vitis-Tutorials/
MIT License
1.22k stars 553 forks source link

A question about std::memcmp function call in the source code for the host program of Vitis getting started tutorial #389

Closed Heng-Zhou closed 1 year ago

Heng-Zhou commented 1 year ago

The source code host.cpp for the host program of Vitis getting started tutorial calls std::memcmp on line 74:

if (std::memcmp(bo2_map, bufReference, DATA_SIZE))

Here the third argument is DATA_SIZE which is the number of data items. But the C++ standard specifies that this argument should be the number of bytes to be compared (here):

image

If we conform to the C++ standard, the third argument should be variable vector_size_bytes which is the number of bytes of the memory. So I was wondering whether it is a bug, or Xilinx redefined the meaning of the third parameter of std::memcmp function.

randyh62 commented 1 year ago

Hi, Have you run it with vector_size_bytes? It seems that the test is only getting about a quarter of the way through the results before returning test passed. I don't think we redefined memcmp.

Heng-Zhou commented 1 year ago

@randyh62 I run the vadd sample code with vector_size_bytes under three configurations: software emulation, hardware emulation and hardware, and the code all returns successfully with TEST PASSED output. My hardware is Alveo U280 and I adapted the given tutorial to it, which is still based on XRT runtime, not OpenCL runtime. So, if there is no other problem, I think DATA_SIZE is incorrect on line 74 of host.cpp which only performs 1/4 of the comparison. So, we should replace it with vector_size_bytes.

imrickysu commented 1 year ago

Hi @randyh62 , I think @Heng-Zhou is correct.

DATA_SIZE is per int. vector_size_bytes is per byte.

When doing memcmp, we can use vector_size_bytes or sizeof(bufReference).

imrickysu commented 1 year ago

fixed by 22a3dcc