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
|
|
|
/*
|
|
|
|
|
Copyright (c) 2015 - present Advanced Micro Devices, Inc. All rights reserved.
|
|
|
|
|
|
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
|
of this software and associated documentation files (the "Software"), to deal
|
|
|
|
|
in the Software without restriction, including without limitation the rights
|
|
|
|
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
|
copies of the Software, and to permit persons to whom the Software is
|
|
|
|
|
furnished to do so, subject to the following conditions:
|
|
|
|
|
|
|
|
|
|
The above copyright notice and this permission notice shall be included in
|
|
|
|
|
all copies or substantial portions of the Software.
|
|
|
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
|
THE SOFTWARE.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
2018-05-11 03:35:10 +01:00
|
|
|
#include <hsa/amd_hsa_kernel_code.h>
|
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 <hsa/hsa.h>
|
2017-11-28 19:15:29 +00:00
|
|
|
#include <hsa/hsa_ext_amd.h>
|
2018-05-11 03:35:10 +01:00
|
|
|
#include <hsa/hsa_ven_amd_loader.h>
|
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 <cstddef>
|
2019-03-06 14:01:44 +02:00
|
|
|
#include <cstdint>
|
|
|
|
|
#include <cstdlib>
|
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
|
|
|
|
2019-08-08 04:33:04 -04:00
|
|
|
#include <hip/hip_common.h>
|
|
|
|
|
|
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
|
|
|
struct ihipModuleSymbol_t;
|
|
|
|
|
using hipFunction_t = ihipModuleSymbol_t*;
|
|
|
|
|
|
2018-03-12 11:29:03 +05:30
|
|
|
namespace hip_impl {
|
2019-03-27 18:19:10 +00:00
|
|
|
|
2019-08-08 04:33:04 -04:00
|
|
|
// This section contains internal APIs that
|
|
|
|
|
// needs to be exported
|
|
|
|
|
#ifdef __GNUC__
|
|
|
|
|
#pragma GCC visibility push (default)
|
|
|
|
|
#endif
|
|
|
|
|
|
2019-05-04 17:51:13 -04:00
|
|
|
struct kernarg_impl;
|
|
|
|
|
class kernarg {
|
|
|
|
|
public:
|
|
|
|
|
kernarg();
|
|
|
|
|
kernarg(kernarg&&);
|
|
|
|
|
~kernarg();
|
|
|
|
|
std::uint8_t* data();
|
|
|
|
|
std::size_t size();
|
|
|
|
|
void reserve(std::size_t);
|
|
|
|
|
void resize(std::size_t);
|
|
|
|
|
private:
|
|
|
|
|
kernarg_impl* impl;
|
|
|
|
|
};
|
|
|
|
|
|
2019-05-12 09:54:03 -04:00
|
|
|
class kernargs_size_align;
|
|
|
|
|
class program_state_impl;
|
|
|
|
|
class program_state {
|
2018-05-11 03:35:10 +01:00
|
|
|
public:
|
2019-05-12 09:54:03 -04:00
|
|
|
program_state();
|
|
|
|
|
~program_state();
|
2019-05-04 14:35:27 -04:00
|
|
|
program_state(const program_state&) = delete;
|
2018-05-11 03:35:10 +01:00
|
|
|
|
2019-05-12 09:54:03 -04:00
|
|
|
hipFunction_t kernel_descriptor(std::uintptr_t,
|
|
|
|
|
hsa_agent_t);
|
2019-05-16 15:58:54 +03:00
|
|
|
|
2019-05-12 09:54:03 -04:00
|
|
|
kernargs_size_align get_kernargs_size_align(std::uintptr_t);
|
|
|
|
|
hsa_executable_t load_executable(const char*, const size_t,
|
|
|
|
|
hsa_executable_t,
|
|
|
|
|
hsa_agent_t);
|
2018-05-11 03:35:10 +01:00
|
|
|
|
2019-05-12 09:54:03 -04:00
|
|
|
void* global_addr_by_name(const char* name);
|
2018-05-11 03:35:10 +01:00
|
|
|
|
2019-05-12 09:54:03 -04:00
|
|
|
private:
|
2019-05-04 14:35:27 -04:00
|
|
|
friend class agent_globals_impl;
|
2019-05-12 09:54:03 -04:00
|
|
|
program_state_impl* impl;
|
2018-03-12 11:29:03 +05:30
|
|
|
};
|
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
|
|
|
|
2019-05-12 09:54:03 -04:00
|
|
|
class kernargs_size_align {
|
|
|
|
|
public:
|
|
|
|
|
std::size_t size(std::size_t n) const;
|
|
|
|
|
std::size_t alignment(std::size_t n) const;
|
2019-06-19 20:29:05 -04:00
|
|
|
const void* getHandle() const {return handle;};
|
2019-05-12 09:54:03 -04:00
|
|
|
private:
|
|
|
|
|
const void* handle;
|
|
|
|
|
friend kernargs_size_align program_state::get_kernargs_size_align(std::uintptr_t);
|
2019-03-06 14:01:44 +02:00
|
|
|
};
|
|
|
|
|
|
2019-08-08 04:33:04 -04:00
|
|
|
#ifdef __GNUC__
|
|
|
|
|
#pragma GCC visibility pop
|
|
|
|
|
#endif
|
|
|
|
|
|
2019-03-06 14:01:44 +02:00
|
|
|
inline
|
|
|
|
|
__attribute__((visibility("hidden")))
|
2019-05-12 09:54:03 -04:00
|
|
|
program_state& get_program_state() {
|
|
|
|
|
static program_state ps;
|
|
|
|
|
return ps;
|
2019-03-06 14:01:44 +02:00
|
|
|
}
|
2018-03-12 11:29:03 +05:30
|
|
|
} // Namespace hip_impl.
|