This switches HIP from its currently convoluted macro + pfe based dispatch mechanism to a more natural one partially based on the existing module API. The basic idea is that HCC will always correctly emit __global__ functions: as empty-bodied stubs, on host, and as kernels, on device. It then becomes trivial to obtain the mangled name on host, at dispatch, from the function's address, and then to use the mangled name to retrieve the kernel. This should address all problems stemming from serialisation, dubious mismatches due to the manufactured functor, macro-isms et al. It also immediately enables support for generalised globals as a consequence of that being available in the module API. Finally, it will make debug much easier, since the actual names of the __global__ functions will automatically be used in traces etc. One detail is that due to how dispatch works now (hipLaunchKernel and hipLaunchKernelGGL are themselves variadic function templates which deduce the function type of the callee), in certain cases it may be necesssary to insert explicit casts to ensure that the variadic argument list selects a viable overload - this can be observed in some unit tests. Eventually we may be able to remove this limitation, but for now it does not appear terribly onerous. The code is not extremely HIPpie, nor is it fully optimised, but rather is intended as a starting point for the HIP team to make its own.
2017-11-01 15:09:59 +00:00
|
|
|
#include "../include/hip/hcc_detail/code_object_bundle.hpp"
|
|
|
|
|
|
|
|
|
|
#include <hsa/hsa.h>
|
|
|
|
|
|
2017-12-08 04:22:57 +00:00
|
|
|
#include <algorithm>
|
|
|
|
|
#include <cstddef>
|
This switches HIP from its currently convoluted macro + pfe based dispatch mechanism to a more natural one partially based on the existing module API. The basic idea is that HCC will always correctly emit __global__ functions: as empty-bodied stubs, on host, and as kernels, on device. It then becomes trivial to obtain the mangled name on host, at dispatch, from the function's address, and then to use the mangled name to retrieve the kernel. This should address all problems stemming from serialisation, dubious mismatches due to the manufactured functor, macro-isms et al. It also immediately enables support for generalised globals as a consequence of that being available in the module API. Finally, it will make debug much easier, since the actual names of the __global__ functions will automatically be used in traces etc. One detail is that due to how dispatch works now (hipLaunchKernel and hipLaunchKernelGGL are themselves variadic function templates which deduce the function type of the callee), in certain cases it may be necesssary to insert explicit casts to ensure that the variadic argument list selects a viable overload - this can be observed in some unit tests. Eventually we may be able to remove this limitation, but for now it does not appear terribly onerous. The code is not extremely HIPpie, nor is it fully optimised, but rather is intended as a starting point for the HIP team to make its own.
2017-11-01 15:09:59 +00:00
|
|
|
#include <cstdint>
|
|
|
|
|
#include <string>
|
|
|
|
|
#include <vector>
|
|
|
|
|
|
2017-12-08 04:22:57 +00:00
|
|
|
using namespace std;
|
|
|
|
|
|
This switches HIP from its currently convoluted macro + pfe based dispatch mechanism to a more natural one partially based on the existing module API. The basic idea is that HCC will always correctly emit __global__ functions: as empty-bodied stubs, on host, and as kernels, on device. It then becomes trivial to obtain the mangled name on host, at dispatch, from the function's address, and then to use the mangled name to retrieve the kernel. This should address all problems stemming from serialisation, dubious mismatches due to the manufactured functor, macro-isms et al. It also immediately enables support for generalised globals as a consequence of that being available in the module API. Finally, it will make debug much easier, since the actual names of the __global__ functions will automatically be used in traces etc. One detail is that due to how dispatch works now (hipLaunchKernel and hipLaunchKernelGGL are themselves variadic function templates which deduce the function type of the callee), in certain cases it may be necesssary to insert explicit casts to ensure that the variadic argument list selects a viable overload - this can be observed in some unit tests. Eventually we may be able to remove this limitation, but for now it does not appear terribly onerous. The code is not extremely HIPpie, nor is it fully optimised, but rather is intended as a starting point for the HIP team to make its own.
2017-11-01 15:09:59 +00:00
|
|
|
// DATA - STATICS
|
|
|
|
|
constexpr const char hip_impl::Bundled_code_header::magic_string_[];
|
|
|
|
|
|
|
|
|
|
// CREATORS
|
2017-12-08 04:22:57 +00:00
|
|
|
hip_impl::Bundled_code_header::Bundled_code_header(const vector<char>& x)
|
2018-03-12 11:29:03 +05:30
|
|
|
: Bundled_code_header{x.cbegin(), x.cend()} {}
|
2017-12-08 04:22:57 +00:00
|
|
|
|
2018-03-12 11:29:03 +05:30
|
|
|
hip_impl::Bundled_code_header::Bundled_code_header(
|
|
|
|
|
const void* p) { // This is a pretty terrible interface, useful only because
|
2017-12-08 04:22:57 +00:00
|
|
|
// hipLoadModuleData is so poorly specified (for no fault of its own).
|
|
|
|
|
if (!p) return;
|
|
|
|
|
|
|
|
|
|
auto ph = static_cast<const Header_*>(p);
|
|
|
|
|
|
2018-03-12 11:29:03 +05:30
|
|
|
if (!equal(magic_string_, magic_string_ + magic_string_sz_, ph->bundler_magic_string_)) {
|
2017-12-08 04:22:57 +00:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
size_t sz = sizeof(Header_) + ph->bundle_cnt_ * sizeof(Bundled_code::Header);
|
|
|
|
|
auto pb = static_cast<const char*>(p) + sizeof(Header_);
|
|
|
|
|
auto n = ph->bundle_cnt_;
|
|
|
|
|
while (n--) {
|
|
|
|
|
sz += reinterpret_cast<const Bundled_code::Header*>(pb)->bundle_sz;
|
|
|
|
|
pb += sizeof(Bundled_code::Header);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
read(static_cast<const char*>(p), static_cast<const char*>(p) + sz, *this);
|
2018-04-13 06:54:39 -04:00
|
|
|
}
|