Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 33 additions & 8 deletions csrc/include/aiter_hip_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
#include <cstdint>
#include <hip/hip_runtime.h>
#include <iostream>
#ifdef AITER_EMBEDDED_HSA_HEADER
#include AITER_EMBEDDED_HSA_HEADER
#endif

enum class GPUArch
{
Expand Down Expand Up @@ -67,6 +70,35 @@ struct AiterAsmKernelArgs
};

static const std::string get_gpu_arch();

inline void load_asm_kernel(const char* name,
const char* hsaco,
hipModule_t& module,
hipFunction_t& kernel_func)
{
const char* AITER_ASM_DIR = std::getenv("AITER_ASM_DIR");
std::string arch_name = get_gpu_arch();
if(AITER_ASM_DIR != nullptr)
{
std::string hsa_path = std::string(AITER_ASM_DIR) + "/" + arch_name + "/" + hsaco;
std::cout << "[aiter] hipModuleLoad: " << hsa_path << " GetFunction: " << name;
HIP_CALL(hipModuleLoad(&module, hsa_path.c_str()));
}
else
{
#if defined(AITER_EMBEDDED_HSA_HEADER) && defined(AITER_EMBEDDED_HSA_MAP)
std::string fname = "hsa/" + arch_name + "/" + hsaco;
auto hasco_obj = AITER_EMBEDDED_HSA_MAP.find(fname);
CHECK_COND(hasco_obj != AITER_EMBEDDED_HSA_MAP.end());
CHECK_COND(hasco_obj->second.data() != nullptr);
std::cout << "hipModuleLoad: " << fname << " GetFunction: " << name << std::endl;
HIP_CALL(hipModuleLoadData(&module, hasco_obj->second.data()));
#endif
}
HIP_CALL(hipModuleGetFunction(&kernel_func, module, name));
std::cout << " Success" << std::endl;
}

class AiterAsmKernel
{
private:
Expand All @@ -76,14 +108,7 @@ class AiterAsmKernel
public:
AiterAsmKernel(const char* name, const char* hsaco)
{
const char* AITER_ASM_DIR = std::getenv("AITER_ASM_DIR");
std::string arch_name = get_gpu_arch();
std::string hsa_path = std::string(AITER_ASM_DIR) + "/" + arch_name + "/" + hsaco;
std::cout << "[aiter] hipModuleLoad: " << hsa_path
<< " GetFunction: " << name;
HIP_CALL(hipModuleLoad(&module, hsa_path.c_str()));
HIP_CALL(hipModuleGetFunction(&kernel_func, module, name));
std::cout << " Success" << std::endl;
load_asm_kernel(name, hsaco, module, kernel_func);
};

~AiterAsmKernel() { HIP_CALL(hipModuleUnload(module)); }
Expand Down
8 changes: 1 addition & 7 deletions csrc/py_itfs_cu/asm_fmoe.cu
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,7 @@ class FMoeKernel
uint32_t sub_GU = 512,
uint32_t num_persistent_tgs = 0)
{
const char* AITER_ASM_DIR = std::getenv("AITER_ASM_DIR");
std::string arch_name = get_gpu_arch();
std::string hsa_path = std::string(AITER_ASM_DIR) + "/" + arch_name + "/" + hsaco;
std::cout << "[aiter] hipModuleLoad: " << hsa_path.c_str() << " GetFunction: " << name;
HIP_CALL(hipModuleLoad(&module, hsa_path.c_str()));
HIP_CALL(hipModuleGetFunction(&kernel_func, module, name));
std::cout << " Success" << std::endl;
load_asm_kernel(name, hsaco, module, kernel_func);
this->sub_GU = sub_GU;
this->num_persistent_tgs = num_persistent_tgs;
this->name = name;
Expand Down
Loading