Skip to content

Commit 0f91de3

Browse files
authored
[Update] Add improved error message for buffer allocation failure in 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
1 parent 71ac166 commit 0f91de3

File tree

1 file changed

+24
-6
lines changed

1 file changed

+24
-6
lines changed

samples/host_exerciser/host_exerciser_cmd.h

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -825,26 +825,44 @@ class host_exerciser_cmd : public test_command
825825

826826
/* Allocate Source Buffer
827827
Write to CSR_SRC_ADDR */
828-
std::cout << "Allocate SRC Buffer" << std::endl;
829-
source_ = d_afu->allocate(LPBK1_BUFFER_ALLOCATION_SIZE);
828+
try {
829+
std::cout << "Allocate SRC Buffer" << std::endl;
830+
source_ = d_afu->allocate(LPBK1_BUFFER_ALLOCATION_SIZE);
831+
}
832+
catch (opae::fpga::types::except &ex) {
833+
std::cerr << "SRC Buffer allocation failed. Please check that hugepages are reserved." << std::endl;
834+
throw;
835+
}
830836
host_exe_->logger_->debug(" VA 0x{0} IOVA 0x{1:x}",
831837
(void*)source_->c_type(), source_->io_address());
832838
d_afu->write64(HE_SRC_ADDR, cacheline_aligned_addr(source_->io_address()));
833839
he_init_src_buffer(source_);
834840

835841
/* Allocate Destination Buffer
836842
Write to CSR_DST_ADDR */
837-
std::cout << "Allocate DST Buffer" << std::endl;
838-
destination_ = d_afu->allocate(LPBK1_BUFFER_ALLOCATION_SIZE);
843+
try {
844+
std::cout << "Allocate DST Buffer" << std::endl;
845+
destination_ = d_afu->allocate(LPBK1_BUFFER_ALLOCATION_SIZE);
846+
}
847+
catch (fpga::except &ex) {
848+
std::cerr << "DST Buffer allocation failed. Please check that hugepages are reserved." << std::endl;
849+
throw;
850+
}
839851
host_exe_->logger_->debug(" VA 0x{0} IOVA 0x{1:x}",
840852
(void*)destination_->c_type(), destination_->io_address());
841853
d_afu->write64(HE_DST_ADDR, cacheline_aligned_addr(destination_->io_address()));
842854
std::fill_n(destination_->c_type(), LPBK1_BUFFER_SIZE, 0xBE);
843855

844856
/* Allocate DSM Buffer
845857
Write to CSR_AFU_DSM_BASEL */
846-
std::cout << "Allocate DSM Buffer" << std::endl;
847-
dsm_ = d_afu->allocate(LPBK1_DSM_SIZE);
858+
try {
859+
std::cout << "Allocate DSM Buffer" << std::endl;
860+
dsm_ = d_afu->allocate(LPBK1_DSM_SIZE);
861+
}
862+
catch (fpga::except &ex) {
863+
std::cerr << "DSM Buffer allocation failed. Please check that hugepages are reserved." << std::endl;
864+
throw;
865+
}
848866
host_exe_->logger_->debug(" VA 0x{0} IOVA 0x{1:x}",
849867
(void*)dsm_->c_type(), dsm_->io_address());
850868
d_afu->write32(HE_DSM_BASEL, cacheline_aligned_addr(dsm_->io_address()));

0 commit comments

Comments
 (0)