Skip to content

Commit

Permalink
Move copy stream test to XRT test suite
Browse files Browse the repository at this point in the history
  • Loading branch information
Mellich committed Oct 26, 2022
1 parent 5ec61cb commit 2e10526
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 49 deletions.
48 changes: 0 additions & 48 deletions test/host/hls/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,52 +143,6 @@ std::unique_ptr<ACCL::ACCL> test_vadd_put(options_t options) {
return accl;
}

void test_copy(ACCL::ACCL& accl, options_t options) {
//run test here:
//initialize a CCLO BFM and streams as needed
hlslib::Stream<command_word> callreq, callack;
hlslib::Stream<stream_word, 512> data_cclo2krnl("cclo2krnl"), data_krnl2cclo("krnl2cclo");

std::vector<unsigned int> dest = {0};
std::unique_ptr<CCLO_BFM> cclo;

if (!options.hardware) {
cclo = std::make_unique<CCLO_BFM>(options.start_port, rank, size, dest, callreq, callack, data_cclo2krnl, data_krnl2cclo);
cclo->run();
std::cout << "CCLO BFM started" << std::endl;
}
MPI_Barrier(MPI_COMM_WORLD);

//allocate float arrays for the HLS function to use
auto src_buffer = accl.create_buffer<int>(options.count, ACCL::dataType::int32, 0);
auto dst_buffer = accl.create_buffer<int>(options.count, ACCL::dataType::int32, 0);
for(int i=0; i<options.count; i++){
src_buffer->buffer()[i] = rank;
dst_buffer->buffer()[i] = 0;
}

accl.copy_to_stream(*src_buffer, options.count, false);

//loop back data (divide count by 16 and round up to get number of stream words)
for (int i=0; i < (options.count+15)/16; i++) {
data_krnl2cclo.write(data_cclo2krnl.read());
}

accl.copy_from_stream(*dst_buffer, options.count, false);

//check HLS function outputs
unsigned int err_count = 0;
for(int i=0; i<options.count; i++){
err_count += (dst_buffer->buffer()[i] != rank);
}

std::cout << "Test finished with " << err_count << " errors" << std::endl;
if (!options.hardware) {
//clean up
cclo->stop();
}
}

void test_loopback_local_res(ACCL::ACCL& accl, options_t options) {

//run test here:
Expand Down Expand Up @@ -344,8 +298,6 @@ int main(int argc, char *argv[]) {

auto accl = test_vadd_put(options);
MPI_Barrier(MPI_COMM_WORLD);
test_copy(*accl, options);
MPI_Barrier(MPI_COMM_WORLD);
if(!options.hardware){
std::srand(42);
for(int i=0; i<options.nruns; i++){
Expand Down
35 changes: 34 additions & 1 deletion test/host/xrt/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,37 @@ void test_copy(ACCL::ACCL &accl, options_t &options) {
}
}

void test_copy_stream(ACCL::ACCL &accl, options_t &options) {
std::cout << "Start copy stream test..." << std::endl;
unsigned int count = options.count;
auto op_buf = accl.create_buffer<float>(count, dataType::float32);
auto res_buf = accl.create_buffer<float>(count, dataType::float32);
random_array(op_buf->buffer(), count);

test_debug("Copy data from buffer to stream", options);
accl.copy_to_stream(*op_buf, count, false);
test_debug("Copy data from stream to buffer", options);
accl.copy_from_stream(*res_buf, count, false);
int errors = 0;
for (unsigned int i = 0; i < count; ++i) {
float ref = (*op_buf)[i];
float res = (*res_buf)[i];
if (res != ref) {
std::cout << i + 1
<< "th item is incorrect! (" + std::to_string(res) +
" != " + std::to_string(ref) + ")"
<< std::endl;
errors += 1;
}
}

if (errors > 0) {
std::cout << errors << " errors!" << std::endl;
} else {
std::cout << "Test succesfull!" << std::endl;
}
}

void test_copy_p2p(ACCL::ACCL &accl, options_t &options) {
std::cout << "Start copy p2p test..." << std::endl;
unsigned int count = options.count;
Expand Down Expand Up @@ -1304,7 +1335,7 @@ int start_test(options_t options) {
auto cclo_ip = xrt::ip(device, xclbin_uuid,
"ccl_offload:{ccl_offload_" + cclo_id + "}");
auto hostctrl_ip = xrt::kernel(device, xclbin_uuid,
"hostctrl:{hostctrl_" + cclo_id + "_0}",
"hostctrl:{hostctrl_" + cclo_id + "}",
xrt::kernel::cu_access_mode::exclusive);

int devicemem;
Expand Down Expand Up @@ -1350,6 +1381,8 @@ int start_test(options_t options) {
MPI_Barrier(MPI_COMM_WORLD);
test_copy(*accl, options);
MPI_Barrier(MPI_COMM_WORLD);
test_copy_stream(*accl, options);
MPI_Barrier(MPI_COMM_WORLD);
test_copy_p2p(*accl, options);
MPI_Barrier(MPI_COMM_WORLD);
test_combine_sum(*accl, options);
Expand Down

0 comments on commit 2e10526

Please sign in to comment.