cuda-api-wrappers
Thin C++-flavored wrappers for the CUDA Runtime API
builder_options.hpp
Go to the documentation of this file.
1 
6 #pragma once
7 #ifndef CUDA_API_WRAPPERS_FATBIN_BUILDER_OPTIONS_HPP_
8 #define CUDA_API_WRAPPERS_FATBIN_BUILDER_OPTIONS_HPP_
9 
10 #include "../api/device_properties.hpp"
11 #include "../api/detail/option_marshalling.hpp"
12 #include "../api/types.hpp"
13 
14 #include <array>
15 #include <sstream>
16 
17 namespace cuda {
18 
20 class module_t;
22 
23 namespace fatbin_builder {
24 
25 
26 /*
27 
28 Fatbin options (not including deprecated ones):
29 
30  -compress=<bool> Enable (true) / disable (false) compression (default: true).
31 
32  -compress-all Compress everything in the fatbin, even if it’s small.
33 
34  -cuda Specify CUDA (rather than OpenCL).
35  -opencl Specify OpenCL (rather than CUDA).
36  -host=<name> Specify host operating system. Valid options are “linux”, “windows” (“mac” is deprecated)
37 
38  -g Generate debug information.
39 
40 */
41 
42 struct options_t final {
43 
44  enum : bool {
45  width_32_bits = false, width_64_bits = true
46  };
47  optional<bool> use_64_bit_entry_width{width_64_bits};
48 
49  enum : bool {
50  dont_compress = false, do_compress = true
51  };
52  optional<bool> compress{do_compress};
53 
54  enum : bool {
55  only_compress_large_objects = false, compression_for_everything = true
56  };
57  optional<bool> apply_compression_to_small_objects{only_compress_large_objects};
58 
59  enum ecosystem_t {
60  cuda, opencl
61  };
62  optional<ecosystem_t> ecosystem;
63 
64  enum host_os_t {
65  windows, linux
66  };
67  optional<host_os_t> targeted_host_os;
68 };
69 
70 namespace detail_ {
71 
72 struct marshalled_options_t {
73  ::std::size_t num_options;
74  ::std::string option_str;
75 };
76 
77 } // namespace detail
78 
79 } // namespace fatbin_builder
80 
81 namespace marshalling {
82 
83 namespace detail_ {
84 
85 template <typename MarshalTarget, typename Delimiter>
86 struct gadget<fatbin_builder::options_t, MarshalTarget, Delimiter> {
87  static void process(
88  const fatbin_builder::options_t &opts,
89  MarshalTarget &marshalled, Delimiter delimiter,
90  bool need_delimiter_after_last_option)
91  {
93  opt_start_t<Delimiter> opt_start { delimiter };
94  if (opts.use_64_bit_entry_width) {
95  marshalled << opt_start << '-' << (opts.use_64_bit_entry_width.value() ? "64" : "32");
96  }
97  if (opts.compress) {
98  marshalled << opt_start << "-compress=" << (opts.compress.value() ? "true" : "false");
99  }
100  if (opts.apply_compression_to_small_objects.value_or(false)) {
101  marshalled << opt_start << "-compress-all";
102  }
103  if (opts.ecosystem) {
104  marshalled << opt_start << '-' << ((opts.ecosystem.value() == options_t::opencl) ? "opencl" : "cuda");
105  }
106  if (opts.targeted_host_os) {
107  marshalled << opt_start << "-host=" << ((opts.targeted_host_os.value() == options_t::windows) ? "windows" : "linux");
108  }
109  if (need_delimiter_after_last_option) {
110  marshalled << opt_start;
111  }
112  }
113 };
114 
115 } // namespace detail_
116 
117 } // namespace marshalling
118 
119 } // namespace cuda
120 
121 #endif // CUDA_API_WRAPPERS_FATBIN_BUILDER_OPTIONS_HPP_
Definitions and functionality wrapping CUDA APIs.
Definition: array.hpp:22
::std::size_t size_t
A size type for use throughout the wrappers library (except when specific API functions limit the siz...
Definition: types.hpp:81
Definition: builder_options.hpp:42