Skip to content

Commit c7ee3a4

Browse files
Virat Agarwalheeran-xilinx
authored andcommitted
Cmdlineparser added (#411)
1 parent 4283bb7 commit c7ee3a4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+466
-293
lines changed

common/utility/makefile_gen/makegen.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -525,8 +525,9 @@ def mk_check(target, data):
525525
target.write(con["name"])
526526
target.write(".xclbin --package.out_dir $(PACKAGE_OUT) --package.rootfs $(EDGE_COMMON_SW)/rootfs.ext4 --package.sd_file $(SD_IMAGE_FILE) --package.sd_file xrt.ini --package.sd_file $(RUN_APP_SCRIPT) --package.sd_file $(EXECUTABLE)")
527527
for extra_filename in extra_file_list:
528-
target.write(" --package.sd_file ")
529-
target.write(extra_filename)
528+
if ('-' not in extra_filename):
529+
target.write(" --package.sd_file ")
530+
target.write(extra_filename)
530531
target.write(" -o ")
531532
target.write(con["name"])
532533
target.write(".xclbin\n")

cpp_kernels/critical_path/Makefile

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,12 @@ 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+
include $(ABS_COMMON_REPO)/common/includes/cmdparser/cmdparser.mk
62+
include $(ABS_COMMON_REPO)/common/includes/logger/logger.mk
6163
include $(ABS_COMMON_REPO)/common/includes/bitmap/bitmap.mk
62-
CXXFLAGS += $(xcl2_CXXFLAGS) $(bitmap_CXXFLAGS)
63-
LDFLAGS += $(xcl2_LDFLAGS) $(bitmap_LDFLAGS)
64-
HOST_SRCS += $(xcl2_SRCS) $(bitmap_SRCS)
64+
CXXFLAGS += $(xcl2_CXXFLAGS) $(cmdparser_CXXFLAGS) $(logger_CXXFLAGS) $(bitmap_CXXFLAGS)
65+
LDFLAGS += $(xcl2_LDFLAGS) $(cmdparser_LDFLAGS) $(logger_LDFLAGS) $(bitmap_LDFLAGS)
66+
HOST_SRCS += $(xcl2_SRCS) $(cmdparser_SRCS) $(logger_SRCS) $(bitmap_SRCS)
6567
CXXFLAGS += $(opencl_CXXFLAGS) -Wall -O0 -g -std=c++11
6668
LDFLAGS += $(opencl_LDFLAGS)
6769

@@ -88,7 +90,7 @@ CLFLAGS_apply_watermark += -DBAD_DESIGN=0
8890

8991

9092
EXECUTABLE = host
91-
CMD_ARGS = $(BUILD_DIR)/apply_watermark_GOOD.xclbin ./data/input.bmp ./data/golden.bmp
93+
CMD_ARGS = -x $(BUILD_DIR)/apply_watermark_GOOD.xclbin -i ./data/input.bmp -c ./data/golden.bmp
9294
EMCONFIG_DIR = $(TEMP_DIR)
9395
EMU_DIR = $(SDCARD)/data/emulation
9496

@@ -130,27 +132,27 @@ check: all
130132
ifeq ($(TARGET),$(filter $(TARGET),sw_emu hw_emu))
131133
ifeq ($(HOST_ARCH), x86)
132134
$(CP) $(EMCONFIG_DIR)/emconfig.json .
133-
XCL_EMULATION_MODE=$(TARGET) ./$(EXECUTABLE) $(BUILD_DIR)/apply_watermark_GOOD.xclbin ./data/input.bmp ./data/golden.bmp
135+
XCL_EMULATION_MODE=$(TARGET) ./$(EXECUTABLE) -x $(BUILD_DIR)/apply_watermark_GOOD.xclbin -i ./data/input.bmp -c ./data/golden.bmp
134136
else
135137
$(ABS_COMMON_REPO)/common/utility/run_emulation.pl "./${LAUNCH_EMULATOR} | tee run_app.log" "./${RUN_APP_SCRIPT} $(TARGET)" "${RESULT_STRING}" "7"
136138
endif
137139
else
138140
ifeq ($(HOST_ARCH), x86)
139-
./$(EXECUTABLE) $(BUILD_DIR)/apply_watermark_GOOD.xclbin ./data/input.bmp ./data/golden.bmp
141+
./$(EXECUTABLE) -x $(BUILD_DIR)/apply_watermark_GOOD.xclbin -i ./data/input.bmp -c ./data/golden.bmp
140142
endif
141143
endif
142144

143145
.PHONY: test
144146
test: $(EXECUTABLE)
145147
ifeq ($(TARGET),$(filter $(TARGET),sw_emu hw_emu))
146148
ifeq ($(HOST_ARCH), x86)
147-
XCL_EMULATION_MODE=$(TARGET) ./$(EXECUTABLE) $(BUILD_DIR)/apply_watermark_GOOD.xclbin ./data/input.bmp ./data/golden.bmp
149+
XCL_EMULATION_MODE=$(TARGET) ./$(EXECUTABLE) -x $(BUILD_DIR)/apply_watermark_GOOD.xclbin -i ./data/input.bmp -c ./data/golden.bmp
148150
else
149151
$(ABS_COMMON_REPO)/common/utility/run_emulation.pl "./${LAUNCH_EMULATOR} | tee embedded_run.log" "./${RUN_APP_SCRIPT} $(TARGET)" "${RESULT_STRING}" "7"
150152
endif
151153
else
152154
ifeq ($(HOST_ARCH), x86)
153-
./$(EXECUTABLE) $(BUILD_DIR)/apply_watermark_GOOD.xclbin ./data/input.bmp ./data/golden.bmp
155+
./$(EXECUTABLE) -x $(BUILD_DIR)/apply_watermark_GOOD.xclbin -i ./data/input.bmp -c ./data/golden.bmp
154156
else
155157
$(ECHO) "Please copy the content of sd_card folder and data to an SD Card and run on the board"
156158
endif

cpp_kernels/critical_path/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ src/host.cpp
1818
## COMMAND LINE ARGUMENTS
1919
Once the environment has been configured, the application can be executed by
2020
```
21-
./host <apply_watermark_GOOD XCLBIN> ./data/input.bmp ./data/golden.bmp
21+
./host -x <apply_watermark_GOOD XCLBIN> -i ./data/input.bmp -c ./data/golden.bmp
2222
```
2323

2424
## COMMANDS FOR WINDOWS FLOW

cpp_kernels/critical_path/description.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,15 @@
1717
"host_exe": "host",
1818
"compiler": {
1919
"sources": [
20-
"REPO_DIR/common/includes/xcl2",
20+
"REPO_DIR/common/includes/xcl2",
21+
"REPO_DIR/common/includes/cmdparser",
22+
"REPO_DIR/common/includes/logger",
2123
"REPO_DIR/common/includes/bitmap"
2224
],
2325
"includepaths": [
2426
"REPO_DIR/common/includes/xcl2",
27+
"REPO_DIR/common/includes/cmdparser",
28+
"REPO_DIR/common/includes/logger",
2529
"REPO_DIR/common/includes/bitmap"
2630
]
2731
}
@@ -40,7 +44,7 @@
4044
],
4145
"launch": [
4246
{
43-
"cmd_args": "BUILD/apply_watermark_GOOD.xclbin PROJECT/data/input.bmp PROJECT/data/golden.bmp",
47+
"cmd_args": "-x BUILD/apply_watermark_GOOD.xclbin -i PROJECT/data/input.bmp -c PROJECT/data/golden.bmp",
4448
"name": "generic launch for all flows"
4549
}
4650
],

cpp_kernels/critical_path/src/host.cpp

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,24 +33,37 @@ THIS SOFTWARE,
3333
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3434
**********/
3535
#include "bitmap.h"
36+
#include "cmdlineparser.h"
3637
#include "xcl2.hpp"
3738
#include <vector>
3839

39-
int main(int argc, char *argv[]) {
40-
if (argc != 4) {
41-
std::cout << "Usage: " << argv[0] << " <XCLBIN File>"
42-
<< " <input bitmap> <golden bitmap>" << std::endl;
40+
int main(int argc, char **argv) {
41+
// Command Line Parser
42+
sda::utils::CmdLineParser parser;
43+
44+
// Switches
45+
//**************//"<Full Arg>", "<Short Arg>", "<Description>", "<Default>"
46+
parser.addSwitch("--xclbin_file", "-x", "input binary file string", "");
47+
parser.addSwitch("--input_file", "-i", "input test data flie", "");
48+
parser.addSwitch("--compare_file", "-c", "Compare File to compare result",
49+
"");
50+
parser.parse(argc, argv);
51+
52+
// Read settings
53+
auto binaryFile = parser.value("xclbin_file");
54+
std::string bitmapFilename = parser.value("input_file");
55+
std::string goldenFilename = parser.value("compare_file");
56+
57+
if (argc != 7) {
58+
parser.printHelp();
4359
return EXIT_FAILURE;
4460
}
45-
auto binaryFile = argv[1];
46-
std::string bitmapFilename = argv[2];
47-
std::string goldenFilename = argv[3];
4861

4962
// Read the input bit map file into memory
5063
BitmapInterface image(bitmapFilename.data());
5164
bool result = image.readBitmapFile();
5265
if (!result) {
53-
std::cout << "ERROR:Unable to Read Input Bitmap File "
66+
std::cerr << "ERROR:Unable to Read Input Bitmap File "
5467
<< bitmapFilename.data() << std::endl;
5568
return EXIT_FAILURE;
5669
}
@@ -59,7 +72,7 @@ int main(int argc, char *argv[]) {
5972
BitmapInterface goldenImage(goldenFilename.data());
6073
result = goldenImage.readBitmapFile();
6174
if (!result) {
62-
std::cout << "ERROR:Unable to Read Golden Bitmap File "
75+
std::cerr << "ERROR:Unable to Read Golden Bitmap File "
6376
<< goldenFilename.data() << std::endl;
6477
return EXIT_FAILURE;
6578
}
@@ -105,7 +118,7 @@ int main(int argc, char *argv[]) {
105118
}
106119
}
107120
if (valid_device == 0) {
108-
std::cout << "Failed to program any device found, exit!\n";
121+
std::cerr << "Failed to program any device found, exit!\n";
109122
exit(EXIT_FAILURE);
110123
}
111124

cpp_kernels/critical_path/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) apply_watermark_GOOD.xclbin input.bmp golden.bmp' >> run_app.sh
83+
$(ECHO) './$(EXECUTABLE) -x apply_watermark_GOOD.xclbin -i input.bmp -c golden.bmp' >> 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

cpp_kernels/custom_datatype/Makefile

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,12 @@ 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+
include $(ABS_COMMON_REPO)/common/includes/cmdparser/cmdparser.mk
62+
include $(ABS_COMMON_REPO)/common/includes/logger/logger.mk
6163
include $(ABS_COMMON_REPO)/common/includes/bitmap/bitmap.mk
62-
CXXFLAGS += $(xcl2_CXXFLAGS) $(bitmap_CXXFLAGS)
63-
LDFLAGS += $(xcl2_LDFLAGS) $(bitmap_LDFLAGS)
64-
HOST_SRCS += $(xcl2_SRCS) $(bitmap_SRCS)
64+
CXXFLAGS += $(xcl2_CXXFLAGS) $(cmdparser_CXXFLAGS) $(logger_CXXFLAGS) $(bitmap_CXXFLAGS)
65+
LDFLAGS += $(xcl2_LDFLAGS) $(cmdparser_LDFLAGS) $(logger_LDFLAGS) $(bitmap_LDFLAGS)
66+
HOST_SRCS += $(xcl2_SRCS) $(cmdparser_SRCS) $(logger_SRCS) $(bitmap_SRCS)
6567
CXXFLAGS += $(opencl_CXXFLAGS) -Wall -O0 -g -std=c++11
6668
LDFLAGS += $(opencl_LDFLAGS)
6769

@@ -87,7 +89,7 @@ endif
8789

8890

8991
EXECUTABLE = host
90-
CMD_ARGS = $(BUILD_DIR)/rgb_to_hsv.xclbin ./data/input.bmp
92+
CMD_ARGS = -x $(BUILD_DIR)/rgb_to_hsv.xclbin -i ./data/input.bmp
9193
EMCONFIG_DIR = $(TEMP_DIR)
9294
EMU_DIR = $(SDCARD)/data/emulation
9395

@@ -129,27 +131,27 @@ check: all
129131
ifeq ($(TARGET),$(filter $(TARGET),sw_emu hw_emu))
130132
ifeq ($(HOST_ARCH), x86)
131133
$(CP) $(EMCONFIG_DIR)/emconfig.json .
132-
XCL_EMULATION_MODE=$(TARGET) ./$(EXECUTABLE) $(BUILD_DIR)/rgb_to_hsv.xclbin ./data/input.bmp
134+
XCL_EMULATION_MODE=$(TARGET) ./$(EXECUTABLE) -x $(BUILD_DIR)/rgb_to_hsv.xclbin -i ./data/input.bmp
133135
else
134136
$(ABS_COMMON_REPO)/common/utility/run_emulation.pl "./${LAUNCH_EMULATOR} | tee run_app.log" "./${RUN_APP_SCRIPT} $(TARGET)" "${RESULT_STRING}" "7"
135137
endif
136138
else
137139
ifeq ($(HOST_ARCH), x86)
138-
./$(EXECUTABLE) $(BUILD_DIR)/rgb_to_hsv.xclbin ./data/input.bmp
140+
./$(EXECUTABLE) -x $(BUILD_DIR)/rgb_to_hsv.xclbin -i ./data/input.bmp
139141
endif
140142
endif
141143

142144
.PHONY: test
143145
test: $(EXECUTABLE)
144146
ifeq ($(TARGET),$(filter $(TARGET),sw_emu hw_emu))
145147
ifeq ($(HOST_ARCH), x86)
146-
XCL_EMULATION_MODE=$(TARGET) ./$(EXECUTABLE) $(BUILD_DIR)/rgb_to_hsv.xclbin ./data/input.bmp
148+
XCL_EMULATION_MODE=$(TARGET) ./$(EXECUTABLE) -x $(BUILD_DIR)/rgb_to_hsv.xclbin -i ./data/input.bmp
147149
else
148150
$(ABS_COMMON_REPO)/common/utility/run_emulation.pl "./${LAUNCH_EMULATOR} | tee embedded_run.log" "./${RUN_APP_SCRIPT} $(TARGET)" "${RESULT_STRING}" "7"
149151
endif
150152
else
151153
ifeq ($(HOST_ARCH), x86)
152-
./$(EXECUTABLE) $(BUILD_DIR)/rgb_to_hsv.xclbin ./data/input.bmp
154+
./$(EXECUTABLE) -x $(BUILD_DIR)/rgb_to_hsv.xclbin -i ./data/input.bmp
153155
else
154156
$(ECHO) "Please copy the content of sd_card folder and data to an SD Card and run on the board"
155157
endif

cpp_kernels/custom_datatype/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ src/rgb_to_hsv.h
2020
## COMMAND LINE ARGUMENTS
2121
Once the environment has been configured, the application can be executed by
2222
```
23-
./host <rgb_to_hsv XCLBIN> ./data/input.bmp
23+
./host -x <rgb_to_hsv XCLBIN> -i ./data/input.bmp
2424
```
2525

2626
## COMMANDS FOR WINDOWS FLOW

cpp_kernels/custom_datatype/description.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,14 @@
2121
"compiler": {
2222
"sources": [
2323
"REPO_DIR/common/includes/xcl2",
24+
"REPO_DIR/common/includes/cmdparser",
25+
"REPO_DIR/common/includes/logger",
2426
"REPO_DIR/common/includes/bitmap"
2527
],
2628
"includepaths": [
2729
"REPO_DIR/common/includes/xcl2",
30+
"REPO_DIR/common/includes/cmdparser",
31+
"REPO_DIR/common/includes/logger",
2832
"REPO_DIR/common/includes/bitmap"
2933
]
3034
}
@@ -42,7 +46,7 @@
4246
],
4347
"launch": [
4448
{
45-
"cmd_args": "BUILD/rgb_to_hsv.xclbin PROJECT/data/input.bmp",
49+
"cmd_args": "-x BUILD/rgb_to_hsv.xclbin -i PROJECT/data/input.bmp",
4650
"name": "generic launch for all flows"
4751
}
4852
],

cpp_kernels/custom_datatype/src/host.cpp

Lines changed: 22 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 "xcl2.hpp"
3637
#include <vector>
3738
#define USE_IN_HOST
@@ -43,16 +44,25 @@ void sw_RgbToHsv(int *in, int *out, size_t image_size);
4344
void sw_HsvToRgb(int *in, int *out, size_t image_size);
4445
int compareImages(int *in, int *out, size_t image_size);
4546

46-
int main(int argc, char *argv[]) {
47-
if (argc != 3) {
48-
std::cout << "Usage: " << argv[0] << " <XCLBIN File>"
49-
<< " <input bitmap>" << std::endl;
47+
int main(int argc, char **argv) {
48+
// Command Line Parser
49+
sda::utils::CmdLineParser parser;
50+
51+
// Switches
52+
//**************//"<Full Arg>", "<Short Arg>", "<Description>", "<Default>"
53+
parser.addSwitch("--xclbin_file", "-x", "input binary file string", "");
54+
parser.addSwitch("--input_file", "-i", "input test data flie", "");
55+
parser.parse(argc, argv);
56+
57+
// Read settings
58+
std::string binaryFile = parser.value("xclbin_file");
59+
std::string bitmapFilename = parser.value("input_file");
60+
61+
if (argc != 5) {
62+
parser.printHelp();
5063
return EXIT_FAILURE;
5164
}
5265

53-
std::string binaryFile = argv[1];
54-
std::string bitmapFilename = argv[2];
55-
5666
cl_int err;
5767
cl::CommandQueue q;
5868
cl::Context context;
@@ -61,7 +71,7 @@ int main(int argc, char *argv[]) {
6171
BitmapInterface image(bitmapFilename.data());
6272
bool result = image.readBitmapFile();
6373
if (!result) {
64-
std::cout << "ERROR:Unable to Read Bitmap File " << bitmapFilename.data()
74+
std::cerr << "ERROR:Unable to Read Bitmap File " << bitmapFilename.data()
6575
<< std::endl;
6676
return EXIT_FAILURE;
6777
}
@@ -88,8 +98,8 @@ int main(int argc, char *argv[]) {
8898
for (unsigned int i = 0; i < devices.size(); i++) {
8999
auto device = devices[i];
90100
// Creating Context and Command Queue for selected Device
91-
OCL_CHECK(err, context = cl::Context({device}, NULL, NULL, NULL, &err));
92-
OCL_CHECK(err, q = cl::CommandQueue(context, {device},
101+
OCL_CHECK(err, context = cl::Context(device, NULL, NULL, NULL, &err));
102+
OCL_CHECK(err, q = cl::CommandQueue(context, device,
93103
CL_QUEUE_PROFILING_ENABLE, &err));
94104

95105
std::cout << "Trying to program device[" << i
@@ -105,7 +115,7 @@ int main(int argc, char *argv[]) {
105115
}
106116
}
107117
if (valid_device == 0) {
108-
std::cout << "Failed to program any device found, exit!\n";
118+
std::cerr << "Failed to program any device found, exit!\n";
109119
exit(EXIT_FAILURE);
110120
}
111121

@@ -263,7 +273,7 @@ int compareImages(int *_in, int *_out, size_t image_size) {
263273
out = out & 0xffffff;
264274
if (in != out) {
265275
cnt++;
266-
std::cout << "ERROR: Pixel=" << i << " mismatch Expected=" << in
276+
std::cerr << "ERROR: Pixel=" << i << " mismatch Expected=" << in
267277
<< " and Got=" << out << std::endl;
268278
return EXIT_FAILURE;
269279
}

0 commit comments

Comments
 (0)