Skip to content

Commit

Permalink
Merge branch 'amd-develop' into amd-master
Browse files Browse the repository at this point in the history
  • Loading branch information
mangupta committed Dec 13, 2016
2 parents 21a0460 + 22bce40 commit f520160
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 71 deletions.
145 changes: 77 additions & 68 deletions hipify-clang/src/Cuda2Hip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2019,7 +2019,7 @@ static cl::opt<bool> PrintStats("print-stats",
cl::value_desc("print-stats"),
cl::cat(ToolTemplateCategory));

static cl::opt<bool> N("n",
static cl::opt<bool> Examine("examine",
cl::desc("Combines -no-output and -print-stats options"),
cl::value_desc("n"),
cl::cat(ToolTemplateCategory));
Expand Down Expand Up @@ -2106,11 +2106,12 @@ void printStats(std::string fileSource, HipifyPPCallbacks &PPCallbacks, Cuda2Hip

int main(int argc, const char **argv) {
llvm::sys::PrintStackTraceOnErrorSignal();
CommonOptionsParser OptionsParser(argc, argv, ToolTemplateCategory, llvm::cl::Required);
CommonOptionsParser OptionsParser(argc, argv, ToolTemplateCategory, llvm::cl::OneOrMore);
std::vector<std::string> fileSources = OptionsParser.getSourcePathList();
std::string dst = OutputFilename;
if (N) {
NoOutput = PrintStats = true;
if (!dst.empty() && fileSources.size() > 1) {
llvm::errs() << "Conflict: -o and multiple source files are specified.\n";
return 1;
}
if (NoOutput) {
if (Inplace) {
Expand All @@ -2122,84 +2123,92 @@ int main(int argc, const char **argv) {
return 1;
}
}
if (dst.empty()) {
dst = fileSources[0];
if (!Inplace) {
size_t pos = dst.rfind(".");
if (pos != std::string::npos && pos+1 < dst.size()) {
dst = dst.substr(0, pos) + ".hip." + dst.substr(pos+1, dst.size()-pos-1);
} else {
dst += ".hip.cu";
if (Examine) {
NoOutput = PrintStats = true;
}
int Result = 0;
for (const auto & src : fileSources) {
if (dst.empty()) {
dst = src;
if (!Inplace) {
size_t pos = dst.rfind(".");
if (pos != std::string::npos && pos + 1 < dst.size()) {
dst = dst.substr(0, pos) + ".hip." + dst.substr(pos + 1, dst.size() - pos - 1);
}
else {
dst += ".hip.cu";
}
}
}
} else {
if (Inplace) {
llvm::errs() << "Conflict: both -o and -inplace options are specified.\n";
return 1;
else {
if (Inplace) {
llvm::errs() << "Conflict: both -o and -inplace options are specified.\n";
return 1;
}
dst += ".hip";
}
// backup source file since tooling may change "inplace"
if (!NoBackup || !Inplace) {
std::ifstream source(src, std::ios::binary);
std::ofstream dest(Inplace ? dst + ".prehip" : dst, std::ios::binary);
dest << source.rdbuf();
source.close();
dest.close();
}
dst += ".hip";
}
// backup source file since tooling may change "inplace"
if (!NoBackup || !Inplace) {
std::ifstream source(fileSources[0], std::ios::binary);
std::ofstream dest(Inplace ? dst + ".prehip" : dst, std::ios::binary);
dest << source.rdbuf();
source.close();
dest.close();
}

RefactoringTool Tool(OptionsParser.getCompilations(), dst);
ast_matchers::MatchFinder Finder;
HipifyPPCallbacks PPCallbacks(&Tool.getReplacements());
Cuda2HipCallback Callback(&Tool.getReplacements(), &Finder, &PPCallbacks);
RefactoringTool Tool(OptionsParser.getCompilations(), dst);
ast_matchers::MatchFinder Finder;
HipifyPPCallbacks PPCallbacks(&Tool.getReplacements());
Cuda2HipCallback Callback(&Tool.getReplacements(), &Finder, &PPCallbacks);

addAllMatchers(Finder, &Callback);
addAllMatchers(Finder, &Callback);

auto action = newFrontendActionFactory(&Finder, &PPCallbacks);
std::vector<const char*> compilationStages;
compilationStages.push_back("--cuda-host-only");
Tool.appendArgumentsAdjuster(getInsertArgumentAdjuster(compilationStages[0], ArgumentInsertPosition::BEGIN));
Tool.appendArgumentsAdjuster(getInsertArgumentAdjuster("-std=c++11"));
auto action = newFrontendActionFactory(&Finder, &PPCallbacks);
std::vector<const char*> compilationStages;
compilationStages.push_back("--cuda-host-only");
Tool.appendArgumentsAdjuster(getInsertArgumentAdjuster(compilationStages[0], ArgumentInsertPosition::BEGIN));
Tool.appendArgumentsAdjuster(getInsertArgumentAdjuster("-std=c++11"));
#if defined(HIPIFY_CLANG_RES)
Tool.appendArgumentsAdjuster(getInsertArgumentAdjuster("-resource-dir=" HIPIFY_CLANG_RES));
Tool.appendArgumentsAdjuster(getInsertArgumentAdjuster("-resource-dir=" HIPIFY_CLANG_RES));
#endif
Tool.appendArgumentsAdjuster(getClangSyntaxOnlyAdjuster());
int Result = Tool.run(action.get());
Tool.clearArgumentsAdjusters();

LangOptions DefaultLangOptions;
IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts = new DiagnosticOptions();
TextDiagnosticPrinter DiagnosticPrinter(llvm::errs(), &*DiagOpts);
DiagnosticsEngine Diagnostics(
Tool.appendArgumentsAdjuster(getClangSyntaxOnlyAdjuster());
Result += Tool.run(action.get());
Tool.clearArgumentsAdjusters();

LangOptions DefaultLangOptions;
IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts = new DiagnosticOptions();
TextDiagnosticPrinter DiagnosticPrinter(llvm::errs(), &*DiagOpts);
DiagnosticsEngine Diagnostics(
IntrusiveRefCntPtr<DiagnosticIDs>(new DiagnosticIDs()), &*DiagOpts,
&DiagnosticPrinter, false);

DEBUG(dbgs() << "Replacements collected by the tool:\n");
for (const auto &r : Tool.getReplacements()) {
DEBUG(dbgs() << r.toString() << "\n");
}
DEBUG(dbgs() << "Replacements collected by the tool:\n");
for (const auto &r : Tool.getReplacements()) {
DEBUG(dbgs() << r.toString() << "\n");
}

SourceManager Sources(Diagnostics, Tool.getFiles());
Rewriter Rewrite(Sources, DefaultLangOptions);
SourceManager Sources(Diagnostics, Tool.getFiles());
Rewriter Rewrite(Sources, DefaultLangOptions);

if (!Tool.applyAllReplacements(Rewrite)) {
DEBUG(dbgs() << "Skipped some replacements.\n");
}
if (!NoOutput) {
Result = Rewrite.overwriteChangedFiles();
}
if (!Inplace && !NoOutput) {
size_t pos = dst.rfind(".");
if (pos != std::string::npos) {
rename(dst.c_str(), dst.substr(0, pos).c_str());
if (!Tool.applyAllReplacements(Rewrite)) {
DEBUG(dbgs() << "Skipped some replacements.\n");
}
if (!NoOutput) {
Result += Rewrite.overwriteChangedFiles();
}
if (!Inplace && !NoOutput) {
size_t pos = dst.rfind(".");
if (pos != std::string::npos) {
rename(dst.c_str(), dst.substr(0, pos).c_str());
}
}
if (NoOutput) {
remove(dst.c_str());
}
dst.clear();
if (PrintStats) {
printStats(src, PPCallbacks, Callback);
}
}
if (NoOutput) {
remove(dst.c_str());
}
if (PrintStats) {
printStats(fileSources[0], PPCallbacks, Callback);
}

return Result;
}
2 changes: 2 additions & 0 deletions src/hip_hcc.h
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,9 @@ struct LockedBase {
class ihipIpcMemHandle_t
{
public:
#ifdef ENABLE_HIP_IPC
hsa_amd_ipc_memory_t ipc_handle; ///< ipc memory handle on ROCr
#endif
char reserved[HIP_IPC_HANDLE_SIZE];
size_t psize;
};
Expand Down
4 changes: 2 additions & 2 deletions src/hip_ir.ll
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ target datalayout = "e-p:32:32-p1:64:64-p2:64:64-p3:32:32-p4:64:64-p5:32:32-i64:
target triple = "amdgcn--amdhsa"


define void @__threadfence() #1 {
define linkonce_odr spir_func void @__threadfence() #1 {
fence syncscope(2) seq_cst
ret void
}

define void @__threadfence_block() #1 {
define linkonce_odr spir_func void @__threadfence_block() #1 {
fence syncscope(3) seq_cst
ret void
}
Expand Down
3 changes: 2 additions & 1 deletion src/hip_memory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1038,7 +1038,7 @@ hipError_t hipMemGetAddressRange ( hipDeviceptr_t* pbase, size_t* psize, hipDevi


//TODO: IPC implementaiton:

#ifdef ENABLE_HIP_IPC
hipError_t hipIpcGetMemHandle(hipIpcMemHandle_t* handle, void* devPtr){
HIP_INIT_API ( handle, devPtr);
hipError_t hipStatus = hipSuccess;
Expand Down Expand Up @@ -1098,3 +1098,4 @@ hipError_t hipIpcCloseMemHandle(void *devPtr){
// hipError_t hipIpcOpenEventHandle(hipEvent_t* event, hipIpcEventHandle_t handle){
// return hipSuccess;
// }
#endif

0 comments on commit f520160

Please sign in to comment.