update HostTranslator with debug tools

This commit is contained in:
Ruobing Han 2022-09-15 18:19:13 -04:00
parent bb3724c486
commit f2a4f7fe64
17 changed files with 37 additions and 32 deletions

14
common/debug.hpp Normal file
View File

@ -0,0 +1,14 @@
// This file is used for defining debug tools
#ifndef __DEBUG_TOOL__
#define __DEBUG_TOOL__
#include <stdio.h>
#ifdef DEBUG
#define DEBUG_INFO(...) fprintf(stderr, __VA_ARGS__)
#else
#define DEBUG_INFO(...)
#endif // DEBUG
#endif

View File

@ -13,6 +13,7 @@ set(LIB_NAME cudaRuntime2cpuRuntime)
set(CMAKE_CXX_STANDARD 14) set(CMAKE_CXX_STANDARD 14)
set(CMAKE_BUILD_TYPE Debug) set(CMAKE_BUILD_TYPE Debug)
include_directories(./include/x86) include_directories(./include/x86)
include_directories(../../common)
file(GLOB proj_HEADERS "include/x86/*.h") file(GLOB proj_HEADERS "include/x86/*.h")
file(GLOB proj_SOURCES "src/x86/*.cpp") file(GLOB proj_SOURCES "src/x86/*.cpp")

View File

@ -1,7 +0,0 @@
/**
* Generate a file for Cuda Kernel Function Attributes
*
*
*
*
*/

View File

@ -1,6 +0,0 @@
/*
Initialize the cudaDevice as first statements if not set by the User
(cudaSetDevice)
*/

View File

@ -2,6 +2,7 @@
* Remove Clang cuda builtin functions and variables * Remove Clang cuda builtin functions and variables
*/ */
#include "RemoveCudaBuiltin.h" #include "RemoveCudaBuiltin.h"
#include "debug.hpp"
#include "llvm/IR/Function.h" #include "llvm/IR/Function.h"
#include "llvm/IR/GlobalValue.h" #include "llvm/IR/GlobalValue.h"
#include "llvm/IR/IRBuilder.h" #include "llvm/IR/IRBuilder.h"
@ -46,8 +47,7 @@ void RemoveCudaBuiltin(llvm::Module *M) {
continue; continue;
if (Ctors[i]->hasName() && if (Ctors[i]->hasName() &&
Ctors[i]->getName().str().find("__cuda") == std::string::npos) { Ctors[i]->getName().str().find("__cuda") == std::string::npos) {
std::cout << "keep: " << Ctors[i]->getName().str() << std::endl DEBUG_INFO("keep: %s\n", Ctors[i]->getName().str().c_str());
<< std::flush;
CAList.push_back(OldCA->getOperand(i)); CAList.push_back(OldCA->getOperand(i));
} }
} }

View File

@ -1,4 +1,5 @@
#include "ReplaceCudaBuiltin.h" #include "ReplaceCudaBuiltin.h"
#include "debug.hpp"
#include "llvm/IR/Function.h" #include "llvm/IR/Function.h"
#include "llvm/IR/GlobalValue.h" #include "llvm/IR/GlobalValue.h"
#include "llvm/IR/IRBuilder.h" #include "llvm/IR/IRBuilder.h"
@ -123,8 +124,8 @@ void ReplaceKernelLaunch(llvm::Module *M) {
cuda_register_kernel_names.insert( cuda_register_kernel_names.insert(
functionOperand->getName().str()); functionOperand->getName().str());
std::cout << "Cuda Register Global Kernel: " DEBUG_INFO("Cuda Register Global Kernel: %s\n",
<< functionOperand->getName().str() << std::endl; functionOperand->getName().str().c_str());
} }
} }
} }
@ -161,10 +162,10 @@ void ReplaceKernelLaunch(llvm::Module *M) {
dyn_cast<Function>(callOperand->stripPointerCasts()); dyn_cast<Function>(callOperand->stripPointerCasts());
FunctionType *ft = calledFunction->getFunctionType(); FunctionType *ft = calledFunction->getFunctionType();
std::cout << " Parent (Caller) Function Name: " << func_name DEBUG_INFO("Parent (Caller) Function Name: %s, "
<< ", cudaLaunchKernel Function: " "cudaLaunchKernel Function: %s, args : %d\n",
<< functionOperand->getName().str() << ", args " func_name, functionOperand->getName().str().c_str(),
<< functionOperand->arg_size() << std::endl; functionOperand->arg_size());
auto rep = kernels.find(functionOperand->getName().str()); auto rep = kernels.find(functionOperand->getName().str());
if (rep != kernels.end()) { if (rep != kernels.end()) {
Function *FC = rep->second; Function *FC = rep->second;
@ -205,8 +206,7 @@ void ReplaceKernelLaunch(llvm::Module *M) {
newName = newName.substr(i); newName = newName.substr(i);
break; break;
} }
DEBUG_INFO("Change Kernel Name to: %s\n", newName.c_str());
std::cout << "Change Kernel Name to: " << newName << std::endl;
Function *F = Function *F =
Function::Create(FT, Function::ExternalLinkage, newName, M); Function::Create(FT, Function::ExternalLinkage, newName, M);
@ -225,9 +225,8 @@ void ReplaceKernelLaunch(llvm::Module *M) {
// for both cudaKernelLaunch calls and regular function call // for both cudaKernelLaunch calls and regular function call
host_changed = true; host_changed = true;
calledFunction->setName(calledFunction->getName() + "_host"); calledFunction->setName(calledFunction->getName() + "_host");
std::cout << std::endl; DEBUG_INFO("Change Host Function Name to: %s\n",
std::cout << "Change Host Function Name To: " calledFunction->getName().str().c_str());
<< calledFunction->getName().str() << std::endl;
} }
} }
} }

View File

@ -13,6 +13,7 @@ set(LIB_NAME spmd2mpmd)
set(CMAKE_CXX_STANDARD 14) set(CMAKE_CXX_STANDARD 14)
set(CMAKE_BUILD_TYPE Debug) set(CMAKE_BUILD_TYPE Debug)
include_directories(./include/x86) include_directories(./include/x86)
include_directories(../../common)
file(GLOB proj_HEADERS "include/x86/*.h") file(GLOB proj_HEADERS "include/x86/*.h")
file(GLOB proj_SOURCES "src/x86/*.cpp") file(GLOB proj_SOURCES "src/x86/*.cpp")

View File

@ -5,12 +5,6 @@
#include "llvm/IR/Instructions.h" #include "llvm/IR/Instructions.h"
#include "llvm/IR/Module.h" #include "llvm/IR/Module.h"
#ifdef DEBUG
#define DEBUG_INFO(...) fprintf(stderr, __VA_ARGS__)
#else
#define DEBUG_INFO(...)
#endif // DEBUG
llvm::Module *LoadModuleFromFilr(char *file_name); llvm::Module *LoadModuleFromFilr(char *file_name);
void DumpModule(llvm::Module *M, char *file_name); void DumpModule(llvm::Module *M, char *file_name);
bool isKernelFunction(llvm::Module *M, llvm::Function *F); bool isKernelFunction(llvm::Module *M, llvm::Function *F);

View File

@ -1,4 +1,5 @@
#include "generate_x86_format.h" #include "generate_x86_format.h"
#include "debug.hpp"
#include "tool.h" #include "tool.h"
#include "llvm/Analysis/TargetLibraryInfo.h" #include "llvm/Analysis/TargetLibraryInfo.h"
#include "llvm/Analysis/TargetTransformInfo.h" #include "llvm/Analysis/TargetTransformInfo.h"

View File

@ -1,4 +1,5 @@
#include "handle_sync.h" #include "handle_sync.h"
#include "debug.hpp"
#include "tool.h" #include "tool.h"
#include "llvm/IR/Function.h" #include "llvm/IR/Function.h"
#include "llvm/IR/GlobalValue.h" #include "llvm/IR/GlobalValue.h"

View File

@ -1,4 +1,5 @@
#include "init.h" #include "init.h"
#include "debug.hpp"
#include "memory_hierarchy.h" #include "memory_hierarchy.h"
#include "tool.h" #include "tool.h"
#include <fstream> #include <fstream>

View File

@ -1,5 +1,6 @@
#include "insert_sync.h" #include "insert_sync.h"
#include "assert.h" #include "assert.h"
#include "debug.hpp"
#include "handle_sync.h" #include "handle_sync.h"
#include "tool.h" #include "tool.h"
#include "llvm/ADT/SmallVector.h" #include "llvm/ADT/SmallVector.h"

View File

@ -1,5 +1,6 @@
#include "insert_warp_loop.h" #include "insert_warp_loop.h"
#include "debug.hpp"
#include "handle_sync.h" #include "handle_sync.h"
#include "tool.h" #include "tool.h"
#include <assert.h> #include <assert.h>

View File

@ -1,4 +1,5 @@
#include "memory_hierarchy.h" #include "memory_hierarchy.h"
#include "debug.hpp"
#include "llvm/IR/CFG.h" #include "llvm/IR/CFG.h"
#include "llvm/IR/Function.h" #include "llvm/IR/Function.h"
#include "llvm/IR/GlobalValue.h" #include "llvm/IR/GlobalValue.h"

View File

@ -1,4 +1,5 @@
#include "performance.h" #include "performance.h"
#include "debug.hpp"
#include "tool.h" #include "tool.h"
#include "llvm/ADT/Statistic.h" #include "llvm/ADT/Statistic.h"
#include "llvm/ADT/StringRef.h" #include "llvm/ADT/StringRef.h"

View File

@ -1,4 +1,5 @@
#include "tool.h" #include "tool.h"
#include "debug.hpp"
#include "llvm/Bitcode/BitcodeWriter.h" #include "llvm/Bitcode/BitcodeWriter.h"
#include "llvm/Config/llvm-config.h" #include "llvm/Config/llvm-config.h"
#include "llvm/IR/Constants.h" #include "llvm/IR/Constants.h"

View File

@ -1,5 +1,6 @@
#include "warp_func.h" #include "warp_func.h"
#include "debug.hpp"
#include "tool.h" #include "tool.h"
#include "llvm/IR/Function.h" #include "llvm/IR/Function.h"
#include "llvm/IR/GlobalValue.h" #include "llvm/IR/GlobalValue.h"