Skip to content

Commit 7fabde9

Browse files
tweejXingyu Zhou
authored andcommitted
Add check to ensure input file was successfully opened in NNVM deploy code demo (apache#4315)
1 parent fcd881f commit 7fabde9

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

docs/deploy/nnvm.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,11 @@ An example in c++.
5959
#include <tvm/runtime/registry.h>
6060
#include <tvm/runtime/packed_func.h>
6161

62+
#include <algorithm>
6263
#include <fstream>
6364
#include <iterator>
64-
#include <algorithm>
65+
#include <stdexcept>
66+
#include <string>
6567

6668
int main()
6769
{
@@ -97,7 +99,9 @@ int main()
9799
int64_t in_shape[4] = {1, 3, 224, 224};
98100
TVMArrayAlloc(in_shape, in_ndim, dtype_code, dtype_bits, dtype_lanes, device_type, device_id, &x);
99101
// load image data saved in binary
100-
std::ifstream data_fin("cat.bin", std::ios::binary);
102+
const std::string data_filename = "cat.bin";
103+
std::ifstream data_fin(data_filename, std::ios::binary);
104+
if(!data_fin) throw std::runtime_error("Could not open: " + data_filename);
101105
data_fin.read(static_cast<char*>(x->data), 3 * 224 * 224 * 4);
102106

103107
// get the function from the module(set input data)

0 commit comments

Comments
 (0)