MCPcopy Create free account
hub / github.com/boostorg/compute / build_with_source

Method build_with_source

include/boost/compute/program.hpp:528–582  ·  view source on GitHub ↗

Create a new program with \p source in \p context and builds it with \p options. * In case BOOST_COMPUTE_USE_OFFLINE_CACHE macro is defined, * the compiled binary is stored for reuse in the offline cache located in * $HOME/.boost_compute on UNIX-like systems and in %APPDATA%/boost_compute * on Windows. */

Source from the content-addressed store, hash-verified

526 * on Windows.
527 */
528 static program build_with_source(
529 const std::string &source,
530 const context &context,
531 const std::string &options = std::string()
532 )
533 {
534#ifdef BOOST_COMPUTE_USE_OFFLINE_CACHE
535 // Get hash string for the kernel.
536 device d = context.get_device();
537 platform p = d.platform();
538
539 detail::sha1 hash;
540 hash.process( p.name() )
541 .process( p.version() )
542 .process( d.name() )
543 .process( options )
544 .process( source )
545 ;
546
547 // Try to get cached program binaries:
548 try {
549 boost::optional<program> prog = load_program_binary(hash, context);
550
551 if (prog) {
552 prog->build(options);
553 return *prog;
554 }
555 } catch (...) {
556 // Something bad happened. Fallback to normal compilation.
557 }
558
559 // Cache is apparently not available. Just compile the sources.
560#endif
561 const char *source_string = source.c_str();
562
563 cl_int error = 0;
564 cl_program program_ = clCreateProgramWithSource(context,
565 uint_(1),
566 &source_string,
567 0,
568 &error);
569 if(!program_){
570 BOOST_THROW_EXCEPTION(opencl_error(error));
571 }
572
573 program prog(program_, false);
574 prog.build(options);
575
576#ifdef BOOST_COMPUTE_USE_OFFLINE_CACHE
577 // Save program binaries for future reuse.
578 save_program_binary(hash, prog);
579#endif
580
581 return prog;
582 }
583
584private:
585#ifdef BOOST_COMPUTE_USE_OFFLINE_CACHE

Callers

nothing calls this directly

Calls 6

opencl_errorClass · 0.85
buildMethod · 0.80
get_deviceMethod · 0.45
platformMethod · 0.45
nameMethod · 0.45
versionMethod · 0.45

Tested by

no test coverage detected