Skip to content

Commit

Permalink
Fixes #622: link::option_t and link::marshalled_options_t are now…
Browse files Browse the repository at this point in the history
… relegated to the `detail_` namespace
  • Loading branch information
eyalroz committed Apr 29, 2024
1 parent 9a8c4f9 commit 0761273
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/cuda/api/library.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -264,15 +264,15 @@ library_t create(
bool code_is_preserved = false)
{
handle_t new_lib_handle;
auto raw_link_opts = marshal(link_options);
auto raw_link_opts = link::detail_::marshal(link_options);
struct {
detail_::option_t options[1];
void* values[1];
unsigned count;
} raw_opts = { { CU_LIBRARY_BINARY_IS_PRESERVED }, { &code_is_preserved }, 1 };
auto status = creator(
&new_lib_handle, data_source,
const_cast<link::option_t*>(raw_link_opts.options()),
const_cast<link::detail_::option_t*>(raw_link_opts.options()),
const_cast<void**>(raw_link_opts.values()), raw_link_opts.count(),
raw_opts.options, raw_opts.values, raw_opts.count
);
Expand Down
12 changes: 6 additions & 6 deletions src/cuda/api/link.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,15 +118,15 @@ class link_t {
// TODO: Replace this with methods which take wrapper classes.
void add(link::input::image_t image, const link::options_t &ptx_compilation_options = {}) const
{
auto marshalled_options = marshal(ptx_compilation_options);
auto marshalled_options = link::detail_::marshal(ptx_compilation_options);
auto status = cuLinkAddData(
handle_,
static_cast<CUjitInputType>(image.type),
image.data(), // TODO: Is this really safe?
image.size(),
image.name,
marshalled_options.count(),
const_cast<link::option_t *>(marshalled_options.options()),
const_cast<link::detail_::option_t *>(marshalled_options.options()),
const_cast<void **>(marshalled_options.values())
);
throw_if_error_lazy(status,
Expand All @@ -136,13 +136,13 @@ class link_t {

void add_file(link::input::file_t file_input, const link::options_t &options) const
{
auto marshalled_options = marshal(options);
auto marshalled_options = link::detail_::marshal(options);
auto status = cuLinkAddFile(
handle_,
static_cast<CUjitInputType_enum>(file_input.type),
file_input.path,
marshalled_options.count(),
const_cast<link::option_t *>(marshalled_options.options()),
const_cast<link::detail_::option_t *>(marshalled_options.options()),
const_cast<void **>(marshalled_options.values())
);
throw_if_error_lazy(status,
Expand Down Expand Up @@ -222,10 +222,10 @@ namespace link {
inline link_t create(const link::options_t &options = link::options_t{})
{
handle_t new_link_handle;
auto marshalled_options = marshal(options);
auto marshalled_options = link::detail_::marshal(options);
auto status = cuLinkCreate(
marshalled_options.count(),
const_cast<link::option_t *>(marshalled_options.options()),
const_cast<link::detail_::option_t *>(marshalled_options.options()),
const_cast<void **>(marshalled_options.values()),
&new_link_handle
);
Expand Down
8 changes: 8 additions & 0 deletions src/cuda/api/link_options.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ enum fallback_strategy_for_binary_code_t {
prefer_using_compatible_binary = 1,
};

namespace detail_ {

using option_t = CUjit_option;

struct marshalled_options_t {
Expand Down Expand Up @@ -87,6 +89,8 @@ struct marshalled_options_t {
const void * const * values() const { return value_buffer.data(); }
};

} // namespace detail_

struct options_t final : public rtc::common_ptx_compilation_options_t {

// Note: The sizes are used as parameters too.
Expand Down Expand Up @@ -116,6 +120,8 @@ struct options_t final : public rtc::common_ptx_compilation_options_t {

};

namespace detail_ {

inline marshalled_options_t marshal(const options_t& link_options)
{
marshalled_options_t marshalled{};
Expand Down Expand Up @@ -177,6 +183,8 @@ inline marshalled_options_t marshal(const options_t& link_options)
return marshalled;
}

} // namespace detail_

// TODO: Compiler "output options":
//
// threads per block targeted
Expand Down
4 changes: 2 additions & 2 deletions src/cuda/api/multi_wrapper_impls/module.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,12 @@ inline module_t create(const context_t& context, const void* module_data, const
{
auto creator_function =
[&link_options](handle_t& new_module_handle, const void* module_data_) {
auto marshalled_options = marshal(link_options);
auto marshalled_options = link::detail_::marshal(link_options);
return cuModuleLoadDataEx(
&new_module_handle,
module_data_,
marshalled_options.count(),
const_cast<link::option_t *>(marshalled_options.options()),
const_cast<link::detail_::option_t *>(marshalled_options.options()),
const_cast<void **>(marshalled_options.values())
);
};
Expand Down

0 comments on commit 0761273

Please sign in to comment.