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"); }
int main(int argc, char** argv) { LOGI("\nvvvv vvvv vvvv"); int width = 128; int height = 128; int channels = 4; int32_t *input = (int32_t*)malloc(width * height * channels * sizeof(int32_t)); int32_t *output = (int32_t*)malloc(width * height * channels * sizeof(int32_t)); LOGI("Allocated memory for %dx%dx%d image", width, height, channels); buffer_t bt_input = make_interleaved_image(width, height, channels, input); for (int i = 0; i < std::min(bt_input.extent[0], width); i++) { for (int j = 0; j < std::min(bt_input.extent[1], height); j++) { for (int k = 0; k < bt_input.extent[2]; k++) { input[i * bt_input.stride[0] + j * bt_input.stride[1] + k * bt_input.stride[2]] = ((i + j) % 2) * 6; } } } LOGI("Input :\n"); print(bt_input); bt_input.host_dirty = true; buffer_t bt_output = make_interleaved_image(width, height, channels, output); two_kernels_filter(&bt_input, &bt_output); LOGI("Filter is done."); halide_device_sync(NULL, &bt_output); LOGI("Sync is done"); halide_copy_to_host(NULL, &bt_output); LOGI("Output :\n"); print(bt_output); int count_mismatches = 0; for (int i = 0; i < bt_output.extent[0]; i++) { for (int j = 0; j < bt_output.extent[1]; j++) { for (int k = 0; k < bt_output.extent[2]; k++) { int32_t output_value = ((int32_t*)bt_output.host)[i * bt_output.stride[0] + j * bt_output.stride[1] + k * bt_output.stride[2]]; int32_t input_value = ((int32_t*)bt_input.host)[i * bt_input.stride[0] + j * bt_input.stride[1] + k * bt_input.stride[2]]; if (output_value != input_value) { if (count_mismatches < 100) { std::ostringstream str; str << "bt_output and bt_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_free(NULL, &bt_input); halide_device_free(NULL, &bt_output); halide_device_release(NULL, halide_openglcompute_device_interface()); LOGI("^^^^ ^^^^ ^^^^\n"); }