Пример #1
0
// returns the program cache for the context
inline boost::shared_ptr<program_cache> get_program_cache(const context &context)
{
    typedef lru_cache<cl_context, boost::shared_ptr<program_cache> > cache_map;

    static cache_map caches(8);

    boost::shared_ptr<program_cache> cache = caches.get(context.get());
    if(!cache){
        cache = boost::make_shared<program_cache>(64);

        caches.insert(context.get(), cache);
    }

    return cache;
}
Пример #2
0
    /// Returns the global program cache for \p context.
    ///
    /// This global cache is used internally by Boost.Compute to store compiled
    /// program objects used by its algorithms. All Boost.Compute programs are
    /// stored with a cache key beginning with \c "__boost". User programs
    /// should avoid using the same prefix in order to prevent collisions.
    static boost::shared_ptr<program_cache> get_global_cache(const context &context)
    {
        typedef detail::lru_cache<cl_context, boost::shared_ptr<program_cache> > cache_map;

        BOOST_COMPUTE_DETAIL_GLOBAL_STATIC(cache_map, caches, (8));

        boost::optional<boost::shared_ptr<program_cache> > cache = caches.get(context.get());
        if(!cache){
            cache = boost::make_shared<program_cache>(64);

            caches.insert(context.get(), *cache);
        }

        return *cache;
    }
Пример #3
0
    /// Links the programs in \p programs with \p options in \p context.
    ///
    /// \opencl_version_warning{1,2}
    ///
    /// \see_opencl_ref{clLinkProgram}
    static program link(const std::vector<program> &programs,
                        const context &context,
                        const std::string &options = std::string())
    {
        const char *options_string = 0;

        if(!options.empty()){
            options_string = options.c_str();
        }

        cl_int ret;
        cl_program program_ = clLinkProgram(
            context.get(),
            0,
            0,
            options_string,
            static_cast<uint_>(programs.size()),
            reinterpret_cast<const cl_program*>(&programs[0]),
            0,
            0,
            &ret
        );

        if(!program_){
            BOOST_THROW_EXCEPTION(opencl_error(ret));
        }

        return program(program_, false);
    }
Пример #4
0
		shared_buffer::shared_buffer(context& compute_context, cl_mem_flags flags, size_t size, const void* data, GLenum usage) : buffer{size, data, usage} {
			try {
				shared_buffer_ = std::make_unique<cl::BufferGL>(compute_context.get(), flags, id_, nullptr);
			} catch (const cl::Error& error) {
				utils::log(utils::log_level::fatal) << error.what() << "(" << error.err() << ")" << std::endl;
			}
		}
Пример #5
0
/** Chooses a device based on the provided device selector in the given context.
 */
queue::queue(const context& syclContext, const device& syclDevice,
             info::queue_profiling profilingFlag,
             const async_handler& asyncHandler)
    : ctx(syclContext.get(), asyncHandler),
      dev(syclDevice),
      command_q(create_queue(profilingFlag)),
      command_group(this) {
  command_q.release_one();
}
Пример #6
0
queue::queue(const context& syclContext, const device_selector& deviceSelector,
             const async_handler& asyncHandler)
    // TODO(progtx): Specification requires const selector in queue and
    // non-const in
    // device
    : ctx(syclContext.get(), asyncHandler),
      dev(deviceSelector.select_device(ctx.get_devices())),
      command_q(create_queue()),
      command_group(this) {
  command_q.release_one();
}
Пример #7
0
inline svm_ptr<T> svm_alloc(const context &context,
                            size_t size,
                            cl_svm_mem_flags flags = CL_MEM_READ_WRITE,
                            unsigned int alignment = 0)
{
    svm_ptr<T> ptr(clSVMAlloc(context.get(), flags, size * sizeof(T), alignment));
    if(!ptr.get()){
        BOOST_THROW_EXCEPTION(opencl_error(CL_MEM_OBJECT_ALLOCATION_FAILURE));
    }
    return ptr;
}
Пример #8
0
std::vector<msg_on_chan> get_all_msg_on_chan(context const&pb)
{
    std::vector<msg_on_chan> result;
    for (;;) {
        msg_on_chan got(pb.get(), pb.get_channel());
        if (got.message().empty() && got.channel().empty()) {
            break;
        }
        result.emplace_back(got);
    }
    return result;
}
Пример #9
0
    /// Creates a new program with \p il_binary (SPIR-V binary)
    /// of \p il_size size in \p context.
    ///
    /// \opencl_version_warning{2,1}
    ///
    /// \see_opencl21_ref{clCreateProgramWithIL}
    static program create_with_il(const void * il_binary,
                                  const size_t il_size,
                                  const context &context)
    {
        cl_int error = 0;

        cl_program program_ = clCreateProgramWithIL(
            context.get(), il_binary, il_size, &error
        );

        if(!program_){
            BOOST_THROW_EXCEPTION(opencl_error(error));
        }

        return program(program_, false);
    }
Пример #10
0
    /// Creates a new program with the built-in kernels listed in
    /// \p kernel_names for \p devices in \p context.
    ///
    /// \opencl_version_warning{1,2}
    ///
    /// \see_opencl_ref{clCreateProgramWithBuiltInKernels}
    static program create_with_builtin_kernels(const context &context,
                                               const std::vector<device> &devices,
                                               const std::string &kernel_names)
    {
        cl_int error = 0;

        cl_program program_ = clCreateProgramWithBuiltInKernels(
            context.get(),
            static_cast<uint_>(devices.size()),
            reinterpret_cast<const cl_device_id *>(&devices[0]),
            kernel_names.c_str(),
            &error
        );

        if(!program_){
            BOOST_THROW_EXCEPTION(opencl_error(error));
        }

        return program(program_, false);
    }
Пример #11
0
 bool operator()(const context &a, const context &b) const {
     return a.get() < b.get();
 }
Пример #12
0
inline void svm_free(const context &context, svm_ptr<T> ptr)
{
    clSVMFree(context.get(), ptr.get());
}
Пример #13
0
 /// Returns whether the given message was received on the given
 /// channel on the context
 inline bool got_message_on_channel(context const &pb, msg_on_chan expected) {
     pubnub::msg_on_chan got(pb.get(), pb.get_channel());
     return got == expected;
 }