Skip to content

Commit 4283bb7

Browse files
Virat Agarwalheeran-xilinx
authored andcommitted
Adding cmdlineparser h2k (#412)
1 parent 2e42f00 commit 4283bb7

File tree

4 files changed

+43
-24
lines changed

4 files changed

+43
-24
lines changed

host/streaming_free_running_h2k/Makefile

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,11 @@ SDCARD := sd_card
5858
#Include Libraries
5959
include $(ABS_COMMON_REPO)/common/includes/opencl/opencl.mk
6060
include $(ABS_COMMON_REPO)/common/includes/xcl2/xcl2.mk
61-
CXXFLAGS += $(xcl2_CXXFLAGS)
62-
LDFLAGS += $(xcl2_LDFLAGS)
63-
HOST_SRCS += $(xcl2_SRCS)
61+
include $(ABS_COMMON_REPO)/common/includes/cmdparser/cmdparser.mk
62+
include $(ABS_COMMON_REPO)/common/includes/logger/logger.mk
63+
CXXFLAGS += $(xcl2_CXXFLAGS) $(cmdparser_CXXFLAGS) $(logger_CXXFLAGS)
64+
LDFLAGS += $(xcl2_LDFLAGS) $(cmdparser_LDFLAGS) $(logger_LDFLAGS)
65+
HOST_SRCS += $(xcl2_SRCS) $(cmdparser_SRCS) $(logger_SRCS)
6466
CXXFLAGS += $(opencl_CXXFLAGS) -Wall -O0 -g -std=c++11
6567
LDFLAGS += $(opencl_LDFLAGS)
6668

@@ -86,7 +88,7 @@ endif
8688

8789

8890
EXECUTABLE = host
89-
CMD_ARGS = $(BUILD_DIR)/increment.xclbin
91+
CMD_ARGS = -x $(BUILD_DIR)/increment.xclbin
9092
EMCONFIG_DIR = $(TEMP_DIR)
9193
EMU_DIR = $(SDCARD)/data/emulation
9294

@@ -146,27 +148,27 @@ endif
146148
ifeq ($(TARGET),$(filter $(TARGET),sw_emu hw_emu))
147149
ifeq ($(HOST_ARCH), x86)
148150
$(CP) $(EMCONFIG_DIR)/emconfig.json .
149-
XCL_EMULATION_MODE=$(TARGET) ./$(EXECUTABLE) $(BUILD_DIR)/increment.xclbin
151+
XCL_EMULATION_MODE=$(TARGET) ./$(EXECUTABLE) -x $(BUILD_DIR)/increment.xclbin
150152
else
151153
$(ABS_COMMON_REPO)/common/utility/run_emulation.pl "./${LAUNCH_EMULATOR} | tee run_app.log" "./${RUN_APP_SCRIPT} $(TARGET)" "${RESULT_STRING}" "7"
152154
endif
153155
else
154156
ifeq ($(HOST_ARCH), x86)
155-
./$(EXECUTABLE) $(BUILD_DIR)/increment.xclbin
157+
./$(EXECUTABLE) -x $(BUILD_DIR)/increment.xclbin
156158
endif
157159
endif
158160

159161
.PHONY: test
160162
test: $(EXECUTABLE)
161163
ifeq ($(TARGET),$(filter $(TARGET),sw_emu hw_emu))
162164
ifeq ($(HOST_ARCH), x86)
163-
XCL_EMULATION_MODE=$(TARGET) ./$(EXECUTABLE) $(BUILD_DIR)/increment.xclbin
165+
XCL_EMULATION_MODE=$(TARGET) ./$(EXECUTABLE) -x $(BUILD_DIR)/increment.xclbin
164166
else
165167
$(ABS_COMMON_REPO)/common/utility/run_emulation.pl "./${LAUNCH_EMULATOR} | tee embedded_run.log" "./${RUN_APP_SCRIPT} $(TARGET)" "${RESULT_STRING}" "7"
166168
endif
167169
else
168170
ifeq ($(HOST_ARCH), x86)
169-
./$(EXECUTABLE) $(BUILD_DIR)/increment.xclbin
171+
./$(EXECUTABLE) -x $(BUILD_DIR)/increment.xclbin
170172
else
171173
$(ECHO) "Please copy the content of sd_card folder and data to an SD Card and run on the board"
172174
endif

host/streaming_free_running_h2k/description.json

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,14 @@
2929
"host_exe": "host",
3030
"compiler": {
3131
"sources": [
32-
"REPO_DIR/common/includes/xcl2"
32+
"REPO_DIR/common/includes/xcl2",
33+
"REPO_DIR/common/includes/cmdparser",
34+
"REPO_DIR/common/includes/logger"
3335
],
3436
"includepaths": [
35-
"REPO_DIR/common/includes/xcl2"
37+
"REPO_DIR/common/includes/xcl2",
38+
"REPO_DIR/common/includes/cmdparser",
39+
"REPO_DIR/common/includes/logger"
3640
]
3741
}
3842
},
@@ -49,7 +53,7 @@
4953
],
5054
"launch": [
5155
{
52-
"cmd_args": "BUILD/increment.xclbin",
56+
"cmd_args": "-x BUILD/increment.xclbin",
5357
"name": "generic launch for all flows"
5458
}
5559
],

host/streaming_free_running_h2k/src/host.cpp

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
3232
THIS SOFTWARE,
3333
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3434
**********/
35+
#include "cmdlineparser.h"
3536
#include <algorithm>
3637
#include <cstdlib>
3738
#include <iostream>
@@ -50,9 +51,6 @@ decltype(&clReadStream) xcl::Stream::readStream = nullptr;
5051
decltype(&clWriteStream) xcl::Stream::writeStream = nullptr;
5152
decltype(&clPollStreams) xcl::Stream::pollStreams = nullptr;
5253

53-
auto constexpr Block_Size = 256 * 1024; // 256 K integer per block
54-
auto constexpr num_of_Blocks = 1024;
55-
5654
////////////////////RESET FUNCTION//////////////////////////////////
5755
int reset(int *a, int *sw_results, int *hw_results, unsigned int size) {
5856
// Fill the input vectors with data
@@ -78,12 +76,33 @@ bool verify(int *sw_results, int *hw_results, int size) {
7876
////////MAIN FUNCTION//////////
7977
int main(int argc, char **argv) {
8078

81-
unsigned int num_Blocks = num_of_Blocks;
82-
79+
std::string Block_Count = "1024";
8380
if (xcl::is_emulation()) {
84-
num_Blocks = 2;
81+
Block_Count = "2";
8582
}
8683

84+
// Command Line Parser
85+
sda::utils::CmdLineParser parser;
86+
87+
// Switches
88+
//**************//"<Full Arg>", "<Short Arg>", "<Description>", "<Default>"
89+
parser.addSwitch("--xclbin_file", "-x", "input binary file string", "");
90+
parser.addSwitch("--block_count", "-nb", "number of blocks", Block_Count);
91+
parser.addSwitch("--block_size", "-bs", "Size of each block in KB", "256");
92+
parser.parse(argc, argv);
93+
94+
// Read settings
95+
std::string binaryFile = parser.value("xclbin_file");
96+
unsigned int num_Blocks = stoi(parser.value("block_count"));
97+
unsigned int Block_Size = stoi(parser.value("block_size"));
98+
99+
if (binaryFile.empty()) {
100+
parser.printHelp();
101+
exit(EXIT_FAILURE);
102+
}
103+
104+
Block_Size *= 1000;
105+
87106
unsigned int size = num_Blocks * Block_Size;
88107

89108
// I/O Data Vectors
@@ -93,12 +112,6 @@ int main(int argc, char **argv) {
93112

94113
reset(h_a.data(), sw_results.data(), hw_results.data(), size);
95114

96-
if (argc != 2) {
97-
std::cout << "Usage: " << argv[0] << " <XCLBIN File>" << std::endl;
98-
return EXIT_FAILURE;
99-
}
100-
101-
auto binaryFile = argv[1];
102115
std::cout << "\n Vector Addition of elements " << size << std::endl;
103116

104117
// Bytes per Block

host/streaming_free_running_h2k/utils.mk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ ifeq ($(TARGET),$(filter $(TARGET),sw_emu hw_emu))
8080
$(ECHO) 'export XILINX_VITIS=/mnt' >> run_app.sh
8181
$(ECHO) 'export XCL_EMULATION_MODE=$(TARGET)' >> run_app.sh
8282
endif
83-
$(ECHO) './$(EXECUTABLE) increment.xclbin' >> run_app.sh
83+
$(ECHO) './$(EXECUTABLE) -x increment.xclbin' >> run_app.sh
8484
$(ECHO) 'return_code=$$?' >> run_app.sh
8585
$(ECHO) 'if [ $$return_code -ne 0 ]; then' >> run_app.sh
8686
$(ECHO) 'echo "ERROR: host run failed, RC=$$return_code"' >> run_app.sh

0 commit comments

Comments
 (0)