Skip to content

Commit

Permalink
[Update] Add improved error message for buffer allocation failure in …
Browse files Browse the repository at this point in the history
…HE-MEM (#3102)

* Add message notifying user of buffer allocation failure

* Fix mistake in catch blocks

* Fix caught exceptions not being references

* Fix typo

* Move SRC try-catch to only include the allocate call

* Throw exception after outputting message to user

* Remove unnecessary copies when rethrowing
  • Loading branch information
a-thompson2 committed Feb 13, 2024
1 parent 71ac166 commit 0f91de3
Showing 1 changed file with 24 additions and 6 deletions.
30 changes: 24 additions & 6 deletions samples/host_exerciser/host_exerciser_cmd.h
Expand Up @@ -825,26 +825,44 @@ class host_exerciser_cmd : public test_command

/* Allocate Source Buffer
Write to CSR_SRC_ADDR */
std::cout << "Allocate SRC Buffer" << std::endl;
source_ = d_afu->allocate(LPBK1_BUFFER_ALLOCATION_SIZE);
try {
std::cout << "Allocate SRC Buffer" << std::endl;
source_ = d_afu->allocate(LPBK1_BUFFER_ALLOCATION_SIZE);
}
catch (opae::fpga::types::except &ex) {
std::cerr << "SRC Buffer allocation failed. Please check that hugepages are reserved." << std::endl;
throw;
}
host_exe_->logger_->debug(" VA 0x{0} IOVA 0x{1:x}",
(void*)source_->c_type(), source_->io_address());
d_afu->write64(HE_SRC_ADDR, cacheline_aligned_addr(source_->io_address()));
he_init_src_buffer(source_);

/* Allocate Destination Buffer
Write to CSR_DST_ADDR */
std::cout << "Allocate DST Buffer" << std::endl;
destination_ = d_afu->allocate(LPBK1_BUFFER_ALLOCATION_SIZE);
try {
std::cout << "Allocate DST Buffer" << std::endl;
destination_ = d_afu->allocate(LPBK1_BUFFER_ALLOCATION_SIZE);
}
catch (fpga::except &ex) {
std::cerr << "DST Buffer allocation failed. Please check that hugepages are reserved." << std::endl;
throw;
}
host_exe_->logger_->debug(" VA 0x{0} IOVA 0x{1:x}",
(void*)destination_->c_type(), destination_->io_address());
d_afu->write64(HE_DST_ADDR, cacheline_aligned_addr(destination_->io_address()));
std::fill_n(destination_->c_type(), LPBK1_BUFFER_SIZE, 0xBE);

/* Allocate DSM Buffer
Write to CSR_AFU_DSM_BASEL */
std::cout << "Allocate DSM Buffer" << std::endl;
dsm_ = d_afu->allocate(LPBK1_DSM_SIZE);
try {
std::cout << "Allocate DSM Buffer" << std::endl;
dsm_ = d_afu->allocate(LPBK1_DSM_SIZE);
}
catch (fpga::except &ex) {
std::cerr << "DSM Buffer allocation failed. Please check that hugepages are reserved." << std::endl;
throw;
}
host_exe_->logger_->debug(" VA 0x{0} IOVA 0x{1:x}",
(void*)dsm_->c_type(), dsm_->io_address());
d_afu->write32(HE_DSM_BASEL, cacheline_aligned_addr(dsm_->io_address()));
Expand Down

0 comments on commit 0f91de3

Please sign in to comment.