Merge pull request #341 from emankov/hipBLAS

[HIPIFY][fix] CUDA and cuBLAS main headers correct handling
Этот коммит содержится в:
Evgeny Mankov
2018-01-24 18:09:12 +03:00
коммит произвёл GitHub
родитель 59ac25f59b 600d5d7c06
Коммит befa8dbbce
8 изменённых файлов: 71 добавлений и 21 удалений
+4 -4
Просмотреть файл
@@ -379,12 +379,12 @@ const std::map <llvm::StringRef, hipCounter> CUDA_INCLUDE_MAP{
{"vector_types.h", {"hip/hip_vector_types.h", CONV_INCLUDE, API_RUNTIME}},
// CUBLAS includes
{"cublas.h", {"hipblas.h", CONV_INCLUDE, API_BLAS}},
{"cublas_v2.h", {"hipblas.h", CONV_INCLUDE, API_BLAS}},
{"cublas.h", {"hipblas.h", CONV_INCLUDE_CUDA_MAIN_H, API_BLAS}},
{"cublas_v2.h", {"hipblas.h", CONV_INCLUDE_CUDA_MAIN_H, API_BLAS}},
// CURAND includes
{"curand.h", {"hiprand.h", CONV_INCLUDE, API_RAND}},
{"curand_kernel.h", {"hiprand_kernel.h", CONV_INCLUDE, API_RAND}},
{"curand.h", {"hiprand.h", CONV_INCLUDE, API_RAND}},
{"curand_kernel.h", {"hiprand_kernel.h", CONV_INCLUDE, API_RAND}},
// HIP includes
// TODO: uncomment this when hip/cudacommon.h will be renamed to hip/hipcommon.h
+25 -10
Просмотреть файл
@@ -149,23 +149,38 @@ void HipifyAction::InclusionDirective(clang::SourceLocation hash_loc,
if (!SM.isWrittenInMainFile(hash_loc)) {
return;
}
if (!firstHeader) {
firstHeader = true;
firstHeaderLoc = hash_loc;
}
const auto found = CUDA_INCLUDE_MAP.find(file_name);
if (found == CUDA_INCLUDE_MAP.end()) {
if (!firstNotMainHeader) {
firstNotMainHeader = true;
firstNotMainHeaderLoc = hash_loc;
}
return;
}
// Special-casing to avoid duplication of the hip_runtime include.
bool secondMainInclude = false;
if (found->second.hipName == "hip/hip_runtime.h") {
if (insertedRuntimeHeader) {
secondMainInclude = true;
if (found->second.countType == CONV_INCLUDE_CUDA_MAIN_H) {
switch (found->second.countApiType) {
case API_DRIVER:
case API_RUNTIME:
if (insertedRuntimeHeader) {
secondMainInclude = true;
break;
}
insertedRuntimeHeader = true;
break;
case API_BLAS:
if (insertedBLASHeader) {
secondMainInclude = true;
break;
}
insertedBLASHeader = true;
break;
default:
break;
}
insertedRuntimeHeader = true;
}
Statistics::current().incrementCounter(found->second, file_name.str());
@@ -356,8 +371,8 @@ void HipifyAction::EndSourceFileAction() {
clang::SourceLocation sl;
if (pragmaOnce) {
sl = pragmaOnceLoc;
} else if (firstNotMainHeader) {
sl = firstNotMainHeaderLoc;
} else if (firstHeader) {
sl = firstHeaderLoc;
} else {
sl = SM.getLocForStartOfFile(SM.getMainFileID());
}
+3 -2
Просмотреть файл
@@ -23,9 +23,10 @@ private:
// not, we insert it at the top of the file when we finish processing it.
// This approach means we do the best it's possible to do w.r.t preserving the user's include order.
bool insertedRuntimeHeader = false;
bool firstNotMainHeader = false;
bool insertedBLASHeader = false;
bool firstHeader = false;
bool pragmaOnce = false;
clang::SourceLocation firstNotMainHeaderLoc;
clang::SourceLocation firstHeaderLoc;
clang::SourceLocation pragmaOnceLoc;
/**
+3 -1
Просмотреть файл
@@ -1,6 +1,8 @@
// RUN: %run_test hipify "%s" "%t" %cuda_args
// CHECK: #include <hip/hip_runtime.h>
// CHECK-NOT: #include <cuda_runtime.h>
// CHECK: #include <stdio.h>
#include <cuda.h>
// CHECK-NOT: #include<cuda_runtime.h>
#include <cuda_runtime.h>
#include <stdio.h>
+6 -4
Просмотреть файл
@@ -1,6 +1,8 @@
// RUN: %run_test hipify "%s" "%t" %cuda_args
// CHECK: #include <hip/hip_runtime.h>
#include <cuda_runtime.h>
// CHECK-NOT: #include<cuda.h>
#include <cuda.h>
// CHECK: #include "hip/hip_runtime.h"
// CHECK-NOT: #include "cuda_runtime.h"
// CHECK: #include <stdio.h>
#include "cuda.h"
#include "cuda_runtime.h"
#include <stdio.h>
+8
Просмотреть файл
@@ -0,0 +1,8 @@
// RUN: %run_test hipify "%s" "%t" %cuda_args
// CHECK: #include <hipblas.h>
// CHECK-NOT: #include <cublas_v2.h>
// CHECK: #include <stdio.h>
#include <cublas.h>
#include <cublas_v2.h>
#include <stdio.h>
+8
Просмотреть файл
@@ -0,0 +1,8 @@
// RUN: %run_test hipify "%s" "%t" %cuda_args
// CHECK: #include "hipblas.h"
// CHECK-NOT: #include "cublas.h"
// CHECK: #include <stdio.h>
#include "cublas_v2.h"
#include "cublas.h"
#include <stdio.h>
+14
Просмотреть файл
@@ -0,0 +1,14 @@
// RUN: %run_test hipify "%s" "%t" %cuda_args
// CHECK: #include <hip/hip_runtime.h>
// CHECK-NOT: #include <cuda_runtime.h>
// CHECK: #include <iostream>
// CHECK: #include "hipblas.h"
// CHECK-NOT: #include "cublas.h"
// CHECK: #include <stdio.h>
#include <cuda.h>
#include <cuda_runtime.h>
#include <iostream>
#include "cublas_v2.h"
#include "cublas.h"
#include <stdio.h>