示例#1
0
文件: Sobel.cpp 项目: jrprice/improsa
bool Sobel::runHalideGPU(Image input, Image output, const Params& params)
{
#if ENABLE_HALIDE
    // Create halide buffers
    buffer_t inputBuffer = createHalideBuffer(input);
    buffer_t outputBuffer = createHalideBuffer(output);

    reportStatus("Running Halide GPU filter");

    // Warm-up run
    inputBuffer.host_dirty = true;
    halide_sobel_gpu(&inputBuffer, &outputBuffer);
    halide_dev_sync(NULL);

    // Timed runs
    startTiming();
    for (int i = 0; i < params.iterations; i++)
    {
        halide_sobel_gpu(&inputBuffer, &outputBuffer);
    }
    halide_dev_sync(NULL);
    stopTiming();

    halide_copy_to_host(NULL, &outputBuffer);
    halide_release(NULL);

    return outputResults(input, output, params);
#else
    reportStatus("Halide not enabled during build.");
    return false;
#endif
}
示例#2
0
文件: opencl.cpp 项目: jacobke/Halide
WEAK void halide_release() {
    // TODO: this is for timing; bad for release-mode performance
    #ifdef DEBUG
    halide_printf("dev_sync on exit" );
    #endif
    halide_dev_sync();

    // Unload the module
    if (__mod) {
        CHECK_CALL( clReleaseProgram(__mod), "clReleaseProgram" );
        __mod = 0;
    }

    // Unload context (ref counted).
    CHECK_CALL( clReleaseCommandQueue(cl_q), "clReleaseCommandQueue" );
    CHECK_CALL( clReleaseContext(cl_ctx), "clReleaseContext" );
}
示例#3
0
WEAK void halide_release(void *user_context) {
    // TODO: this is for timing; bad for release-mode performance
    #ifdef DEBUG
    halide_printf(user_context, "dev_sync on exit\n" );
    #endif
    halide_dev_sync(user_context);

    // Unload the module
    if (__mod) {
        #ifdef DEBUG
        halide_printf(user_context, "clReleaseProgram %p\n", __mod);
        #endif

        CHECK_CALL( clReleaseProgram(__mod), "clReleaseProgram" );
        __mod = 0;
    }

    // TODO: This is not a good solution to deal with this problem (finding out if the
    // cl_ctx/cl_q are going to be freed). I think a larger redesign of the global
    // context scheme might be necessary.
    cl_uint refs = 0;
    clGetContextInfo(*cl_ctx, CL_CONTEXT_REFERENCE_COUNT, sizeof(refs), &refs, NULL);

    // Unload context (ref counted).
    CHECK_CALL( clReleaseCommandQueue(*cl_q), "clReleaseCommandQueue" );
    #ifdef DEBUG
    halide_printf(user_context, "clReleaseContext %p\n", *cl_ctx);
    #endif
    CHECK_CALL( clReleaseContext(*cl_ctx), "clReleaseContext" );

    // See TODO above...
    if (--refs == 0) {
        *cl_ctx = NULL;
        *cl_q = NULL;
    }
}