int main(int argc, char** argv) { LOGI("\nvvvv vvvv vvvv"); int width = 128; int height = 128; int channels = 4; auto input = Halide::Buffer<int>::make_interleaved(width, height, channels); LOGI("Allocated memory for %dx%dx%d image", width, height, channels); input.for_each_element([&](int i, int j, int k) { input(i, j, k) = ((i + j) % 2) * 6; }); LOGI("Input :\n"); print(input); auto output = Halide::Buffer<int>::make_interleaved(width, height, channels); two_kernels_filter(input, output); LOGI("Filter is done."); output.device_sync(); LOGI("Sync is done"); output.copy_to_host(); LOGI("Output :\n"); print(output); int count_mismatches = 0; output.for_each_element([&](int i, int j, int k) { int32_t output_value = output(i, j, k); int32_t input_value = input(i, j, k); if (output_value != input_value) { if (count_mismatches < 100) { std::ostringstream str; str << "output and input results differ at " << "(" << i << ", " << j << ", " << k << "):" << output_value << " != " << input_value << "\n"; LOGI("%s", str.str().c_str()); } count_mismatches++; } }); LOGI(count_mismatches == 0 ? "Test passed.\n": "Test failed.\n"); halide_device_release(NULL, halide_openglcompute_device_interface()); LOGI("^^^^ ^^^^ ^^^^\n"); }
void check (std::string const& value, std::vector <std::string> const& expected) { std::vector <std::string> parsed; for_each_element (value.begin(), value.end(), [&](std::string const& element) { parsed.push_back (element); }); expect (parsed == expected); }