2 // Copyright 2012 Francisco Jerez
4 // Permission is hereby granted, free of charge, to any person obtaining a
5 // copy of this software and associated documentation files (the "Software"),
6 // to deal in the Software without restriction, including without limitation
7 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 // and/or sell copies of the Software, and to permit persons to whom the
9 // Software is furnished to do so, subject to the following conditions:
11 // The above copyright notice and this permission notice shall be included in
12 // all copies or substantial portions of the Software.
14 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 // THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
18 // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
19 // OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23 #include "core/program.hpp"
24 #include "core/compiler.hpp"
26 using namespace clover
;
28 _cl_program::_cl_program(clover::context
&ctx
,
29 const std::string
&source
) :
30 ctx(ctx
), __source(source
) {
33 _cl_program::_cl_program(clover::context
&ctx
,
34 const std::vector
<clover::device
*> &devs
,
35 const std::vector
<clover::module
> &binaries
) :
37 for_each([&](clover::device
*dev
, const clover::module
&bin
) {
38 __binaries
.insert({ dev
, bin
});
40 devs
.begin(), devs
.end(), binaries
.begin());
44 _cl_program::build(const std::vector
<clover::device
*> &devs
,
47 for (auto dev
: devs
) {
48 __binaries
.erase(dev
);
52 __opts
.insert({ dev
, opts
});
54 auto module
= (dev
->ir_format() == PIPE_SHADER_IR_TGSI
?
55 compile_program_tgsi(__source
) :
56 compile_program_llvm(__source
, dev
->ir_format(),
57 dev
->ir_target(), build_opts(dev
)));
58 __binaries
.insert({ dev
, module
});
60 } catch (build_error
&e
) {
61 __logs
.insert({ dev
, e
.what() });
62 throw error(CL_BUILD_PROGRAM_FAILURE
);
63 } catch (invalid_option_error
&e
) {
64 throw error(CL_INVALID_BUILD_OPTIONS
);
70 _cl_program::source() const {
74 const std::map
<clover::device
*, clover::module
> &
75 _cl_program::binaries() const {
80 _cl_program::build_status(clover::device
*dev
) const {
81 return __binaries
.count(dev
) ? CL_BUILD_SUCCESS
: CL_BUILD_NONE
;
85 _cl_program::build_opts(clover::device
*dev
) const {
86 return __opts
.count(dev
) ? __opts
.find(dev
)->second
: "";
90 _cl_program::build_log(clover::device
*dev
) const {
91 return __logs
.count(dev
) ? __logs
.find(dev
)->second
: "";