static int run_test(void *uc, int channels, Implementation imp, Layout layout) { std::string name = "Example_"; name += std::to_string(channels); name += (imp == kGLSL) ? "_GLSL" : "_CPU"; name += (layout == kChunky) ? "_Chunky" : "_Planar"; halide_printf(uc, "\n---------------------------\n%s\n", name.c_str()); Image<uint8_t> input(kWidth, kHeight, channels, 0, (layout == kChunky)); Image<uint8_t> output(kWidth, kHeight, channels, 0, (layout == kChunky)); (void) halide_smooth_buffer_host<uint8_t>(uc, kSeed, input); if (imp == kGLSL) { // Call once to ensure OpenGL is inited (we want to time the // cost of copy-to-device alone) halide_copy_to_device(uc, input, halide_opengl_device_interface()); // Mark as dirty so the next call won't be a no-op input.set_host_dirty(); { ScopedTimer timer(uc, name + " halide_copy_to_device input"); halide_copy_to_device(uc, input, halide_opengl_device_interface()); } { ScopedTimer timer(uc, name + " halide_copy_to_device output"); halide_copy_to_device(uc, output, halide_opengl_device_interface()); } } // Call once to compile shader, warm up, etc. ExampleFunc example = exampleFuncs[channels-1][imp]; (void) example(input, output); { ScopedTimer timer(uc, name, kIter); for (int i = 0; i < kIter; ++i) { (void) example(input, output); } } if (imp == kGLSL) { ScopedTimer timer(uc, name + " halide_copy_to_host"); halide_copy_to_host(uc, output); } // halide_buffer_display(input); // halide_buffer_print(input); // halide_buffer_display(output); // halide_buffer_print(output); int errors = check<uint8_t>(input, output); if (errors) { halide_errorf(uc, "Test %s had %d errors!\n\n", name.c_str(), errors); } else { halide_printf(uc, "Test %s had no errors.\n\n", name.c_str()); } return errors; }
void test_device_sync() { const int W = 12, H = 32, C = 3; Image temp(W, H, C, sizeof(uint8_t), Image::Planar); int result = halide_device_malloc(nullptr, &temp.buf, halide_opengl_device_interface()); if (result != 0) { fprintf(stderr, "halide_device_malloc failed with return %d.\n", result); } else { result = halide_device_sync(nullptr, &temp.buf); if (result != 0) { fprintf(stderr, "halide_device_sync failed with return %d.\n", result); } else { fprintf(stderr, "Test device sync complete.\n"); } } }