36 #pragma GCC diagnostic push
37 #pragma GCC diagnostic ignored "-Wswitch-default"
38 #pragma GCC diagnostic ignored "-Wunused-parameter"
39 #pragma GCC diagnostic ignored "-Wstrict-overflow"
40 #if (defined(__GNUC__) && (__GNUC__ >= 7))
41 #pragma GCC diagnostic ignored "-Wimplicit-fallthrough"
42 #endif // (defined(__GNUC__) && (__GNUC__ >= 7))
43 #if defined(__clang__)
44 #pragma GCC diagnostic ignored "-Wparentheses-equality"
45 #endif // defined(__clang__)
46 #define STB_IMAGE_IMPLEMENTATION
47 #include "stb/stb_image.h"
48 #pragma GCC diagnostic pop
60 void discard_comments(std::ifstream &fs)
62 while (fs.peek() ==
'#')
64 fs.ignore(std::numeric_limits<std::streamsize>::max(),
'\n');
72 void discard_comments_and_spaces(std::ifstream &fs)
78 if (isspace(fs.peek()) == 0)
88 #ifndef BENCHMARK_EXAMPLES
89 int run_example(
int argc,
char **argv, std::unique_ptr<Example> example)
91 std::cout <<
"\n" << argv[0] <<
"\n\n";
95 bool status = example->do_setup(argc, argv);
101 example->do_teardown();
103 std::cout <<
"\nTest passed\n";
106 #ifdef ARM_COMPUTE_CL
107 catch (cl::Error &err)
109 std::cerr <<
"!!!!!!!!!!!!!!!!!!!!!!!!!!!" << std::endl;
110 std::cerr << std::endl <<
"ERROR " << err.what() <<
"(" << err.err() <<
")" << std::endl;
111 std::cerr <<
"!!!!!!!!!!!!!!!!!!!!!!!!!!!" << std::endl;
114 catch (std::runtime_error &err)
116 std::cerr <<
"!!!!!!!!!!!!!!!!!!!!!!!!!!!" << std::endl;
117 std::cerr << std::endl <<
"ERROR " << err.what() <<
" " << (errno ? strerror(errno) :
"") << std::endl;
118 std::cerr <<
"!!!!!!!!!!!!!!!!!!!!!!!!!!!" << std::endl;
121 std::cout <<
"\nTest FAILED\n";
139 for (
size_t x = 0; x < rect.
width; ++x)
152 for (
size_t y = 0; y < rect.
height; ++y)
174 fs.exceptions(std::ifstream::failbit | std::ifstream::badbit);
175 fs.open(filename, std::ios::in | std::ios::binary);
178 std::array<unsigned char, 2> magic_number{{0}};
179 fs >> magic_number[0] >> magic_number[1];
182 if (
static_cast<char>(magic_number[0]) ==
'P' &&
static_cast<char>(magic_number[1]) ==
'6')
186 else if (magic_number[0] == 0xFF && magic_number[1] == 0xD8)
193 catch (std::runtime_error &e)
204 std::array<char, 2> magic_number{{0}};
205 fs >> magic_number[0] >> magic_number[1];
209 discard_comments_and_spaces(fs);
211 unsigned int width = 0;
214 discard_comments_and_spaces(fs);
216 unsigned int height = 0;
219 discard_comments_and_spaces(fs);
224 discard_comments(fs);
229 return std::make_tuple(width, height, max_val);
235 std::string header_s = npy::read_header(fs);
238 npy::header_t
header = npy::parse_header(header_s);
240 bool fortran_order =
false;
245 return npy::header_t{
header.dtype, fortran_order,
shape};
254 std::string line_attribute;
255 std::ifstream file_meminfo(
"/proc/meminfo");
257 if (file_meminfo.is_open())
259 while (!(file_meminfo >> line_attribute).fail())
262 if (line_attribute ==
"MemFree:")
264 uint64_t mem_available;
265 if (!(file_meminfo >> mem_available).fail())
267 return mem_available;
275 file_meminfo.ignore(std::numeric_limits<std::streamsize>::max(),
'\n');