mirror of
https://github.com/ROCm/composable_kernel.git
synced 2026-05-15 10:37:44 +00:00
* updating codegen build for MIOpen access: adding .cmake for codegen component
* updating CMake
* adding in header guards for some headers due to issues with hiprtc compilation in MIOpen
* some more header guards
* putting env file in header guard
* cleaning up some includes
* updated types file for hiprtc purposes
* fixed types file: bit-wise/memcpy issue
* updating multiple utility files to deal with standard header inclusion for hiprtc
* added some more header guards in the utility files, replacing some standard header functionality
* added some more header guards
* fixing some conflicts in utility files, another round of header guards
* fixing errors in data type file
* resolved conflict errors in a few utility files
* added header guards/replicated functionality in device files
* resolved issues with standard headers in device files: device_base and device_grouped_conv_fwd_multiple_abd
* resolved issues with standard headers in device files: device_base.hpp, device_grouped_conv_fwd_multiple_abd.hpp, device_grouped_conv_fwd_multiple_abd_xdl_cshuffle.hpp
* added header guards for gridwise gemm files: gridwise_gemm_multiple_abd_xdl_cshuffle.hpp and gridwise_gemm_multiple_d_xdl_cshuffle.hpp
* fixed issue with numerics header, removed from transform_conv_fwd_to_gemm and added to device_column_to_image_impl, device_grouped_conv_fwd_multiple_abd_xdl_cshuffle, device_grouped_conv_fwd_multiple_abd_xdl_cshuffle_v3, device_image_to_column_impl
* replaced standard header usage and added header guards in block to ctile map and gridwise_gemm_pipeline_selector
* resolved errors in device_gemm_xdl_splitk_c_shuffle files in regards to replacement of standard headers in previous commit
* added replicated functionality for standard header methods in utility files
* replaced standard header functionality in threadwise tensor slice transfer files and added header guards in element_wise_operation.hpp
* temp fix for namespace error in MIOpen
* remove standard header usage in codegen device op
* removed standard header usage in elementwise files, resolved namespace errors
* formatting fix
* changed codegen argument to ON for testing
* temporarily removing codegen compiler flag for testing purposes
* added codegen flag again, set default to ON
* set codegen flag default back to OFF
* replaced enable_if_t standard header usage in data_type.hpp
* added some debug prints to pinpoint issues in MIOpen
* added print outs to debug in MIOpen
* removed debug print outs from device op
* resolved stdexcept include error
* formatting fix
* adding includes to new fp8 file to resolve ck::enable_if_t errors
* made changes to amd_wave_read_first_lane
* updated functionality in type utility file
* fixed end of file issue
* resovled errors in type utility file, added functionality to array utility file
* fixed standard header usage replication in data_type file, resolves error with failing examples on navi3x
* formatting fix
* replaced standard header usage in amd_ck_fp8 file
* added include to random_gen file
* removed and replicated standard header usage from data_type and type_convert files for fp8 changes
* replicated standard unsigned integer types in random_gen
* resolved comments from review: put calls to reinterpret_cast for size_t in header guards
* updated/added copyright headers
* removed duplicate header
* fixed typo in header guard
* updated copyright headers
---------
Co-authored-by: Illia Silin <98187287+illsilin@users.noreply.github.com>
[ROCm/composable_kernel commit: 2e3183af4f]
126 lines
4.3 KiB
C++
126 lines
4.3 KiB
C++
// SPDX-License-Identifier: MIT
|
|
// Copyright (c) 2024-2025, Advanced Micro Devices, Inc. All rights reserved.
|
|
|
|
#include <rtc/kernel.hpp>
|
|
#include <rtc/manage_ptr.hpp>
|
|
#include <rtc/hip.hpp>
|
|
#include <stdexcept>
|
|
#include <cassert>
|
|
|
|
// extern declare the function since hip/hip_ext.h header is broken
|
|
extern hipError_t hipExtModuleLaunchKernel(hipFunction_t, // NOLINT
|
|
uint32_t,
|
|
uint32_t,
|
|
uint32_t,
|
|
uint32_t,
|
|
uint32_t,
|
|
uint32_t,
|
|
size_t,
|
|
hipStream_t,
|
|
void**,
|
|
void**,
|
|
hipEvent_t = nullptr,
|
|
hipEvent_t = nullptr,
|
|
uint32_t = 0);
|
|
|
|
namespace rtc {
|
|
|
|
std::vector<char> pack_args(const std::vector<kernel_argument>& args)
|
|
{
|
|
std::vector<char> kernargs;
|
|
for(auto&& arg : args)
|
|
{
|
|
std::size_t n = arg.size;
|
|
const auto* p = static_cast<const char*>(arg.data);
|
|
// Insert padding
|
|
std::size_t padding = (arg.align - (kernargs.size() % arg.align)) % arg.align;
|
|
kernargs.insert(kernargs.end(), padding, 0);
|
|
kernargs.insert(kernargs.end(), p, p + n);
|
|
}
|
|
return kernargs;
|
|
}
|
|
|
|
using hip_module_ptr = RTC_MANAGE_PTR(hipModule_t, hipModuleUnload);
|
|
|
|
struct kernel_impl
|
|
{
|
|
hip_module_ptr module = nullptr;
|
|
hipFunction_t fun = nullptr;
|
|
};
|
|
|
|
hip_module_ptr load_module(const char* image)
|
|
{
|
|
hipModule_t raw_m;
|
|
auto status = hipModuleLoadData(&raw_m, image);
|
|
hip_module_ptr m{raw_m};
|
|
if(status != hipSuccess)
|
|
throw std::runtime_error("Failed to load module: " + hip_error(status));
|
|
return m;
|
|
}
|
|
|
|
kernel::kernel(const char* image, const std::string& name) : impl(std::make_shared<kernel_impl>())
|
|
{
|
|
impl->module = load_module(image);
|
|
auto status = hipModuleGetFunction(&impl->fun, impl->module.get(), name.c_str());
|
|
if(hipSuccess != status)
|
|
throw std::runtime_error("Failed to get function: " + name + ": " + hip_error(status));
|
|
}
|
|
|
|
void launch_kernel(hipFunction_t fun,
|
|
hipStream_t stream,
|
|
std::size_t global,
|
|
std::size_t local,
|
|
void* kernargs,
|
|
std::size_t size)
|
|
{
|
|
assert(global > 0);
|
|
assert(local > 0);
|
|
void* config[] = {HIP_LAUNCH_PARAM_BUFFER_POINTER,
|
|
kernargs,
|
|
HIP_LAUNCH_PARAM_BUFFER_SIZE,
|
|
&size,
|
|
HIP_LAUNCH_PARAM_END};
|
|
|
|
auto status = hipExtModuleLaunchKernel(fun,
|
|
global,
|
|
1,
|
|
1,
|
|
local,
|
|
1,
|
|
1,
|
|
0,
|
|
stream,
|
|
nullptr,
|
|
reinterpret_cast<void**>(&config),
|
|
nullptr,
|
|
nullptr);
|
|
if(status != hipSuccess)
|
|
throw std::runtime_error("Failed to launch kernel: " + hip_error(status));
|
|
}
|
|
|
|
void kernel::launch(hipStream_t stream,
|
|
std::size_t global,
|
|
std::size_t local,
|
|
std::vector<void*> args) const
|
|
{
|
|
assert(impl != nullptr);
|
|
void* kernargs = args.data();
|
|
std::size_t size = args.size() * sizeof(void*);
|
|
|
|
launch_kernel(impl->fun, stream, global, local, kernargs, size);
|
|
}
|
|
|
|
void kernel::launch(hipStream_t stream,
|
|
std::size_t global,
|
|
std::size_t local,
|
|
const std::vector<kernel_argument>& args) const
|
|
{
|
|
assert(impl != nullptr);
|
|
std::vector<char> kernargs = pack_args(args);
|
|
std::size_t size = kernargs.size();
|
|
|
|
launch_kernel(impl->fun, stream, global, local, kernargs.data(), size);
|
|
}
|
|
|
|
} // namespace rtc
|