diff --git a/hipamd/CMakeLists.txt b/hipamd/CMakeLists.txt index 53f1060621..294f755906 100644 --- a/hipamd/CMakeLists.txt +++ b/hipamd/CMakeLists.txt @@ -304,7 +304,6 @@ if(HIP_PLATFORM STREQUAL "hcc") target_include_directories( hiprtc SYSTEM PRIVATE ${PROJECT_SOURCE_DIR}/include ${HSA_PATH}/include) - target_link_libraries(hiprtc PUBLIC stdc++fs) endif() set_target_properties(hip_hcc PROPERTIES CXX_VISIBILITY_PRESET hidden) set_target_properties(hip_hcc PROPERTIES VISIBILITY_INLINES_HIDDEN 1) diff --git a/hipamd/hipify-clang/src/CUDA2HIP_Runtime_API_types.cpp b/hipamd/hipify-clang/src/CUDA2HIP_Runtime_API_types.cpp index 680825524d..5993f5d770 100644 --- a/hipamd/hipify-clang/src/CUDA2HIP_Runtime_API_types.cpp +++ b/hipamd/hipify-clang/src/CUDA2HIP_Runtime_API_types.cpp @@ -694,9 +694,9 @@ const std::map CUDA_RUNTIME_TYPE_NAME_MAP { {"cudaErrorStartupFailure", {"hipErrorStartupFailure", "", CONV_NUMERIC_LITERAL, API_RUNTIME, HIP_UNSUPPORTED}}, // 127 // CUDA_ERROR_INVALID_IMAGE {"cudaErrorInvalidKernelImage", {"hipErrorInvalidImage", "", CONV_NUMERIC_LITERAL, API_RUNTIME}}, // 200 - // Typo fixed in 10.2 // CUDA_ERROR_INVALID_CONTEXT {"cudaErrorDeviceUninitialized", {"hipErrorInvalidContext", "", CONV_NUMERIC_LITERAL, API_RUNTIME}}, // 201 + // Typo fixed in 10.2 // CUDA_ERROR_INVALID_CONTEXT {"cudaErrorDeviceUninitilialized", {"hipErrorInvalidContext", "", CONV_NUMERIC_LITERAL, API_RUNTIME}}, // 201 // CUDA_ERROR_MAP_FAILED diff --git a/hipamd/include/hip/nvcc_detail/hip_runtime_api.h b/hipamd/include/hip/nvcc_detail/hip_runtime_api.h index 373fd80879..0e7c936fc7 100644 --- a/hipamd/include/hip/nvcc_detail/hip_runtime_api.h +++ b/hipamd/include/hip/nvcc_detail/hip_runtime_api.h @@ -283,8 +283,6 @@ inline static hipError_t hipCUDAErrorTohipError(cudaError_t cuError) { return hipErrorInvalidDevicePointer; case cudaErrorInvalidMemcpyDirection: return hipErrorInvalidMemcpyDirection; - case cudaErrorUnknown: - return hipErrorUnknown; case cudaErrorInvalidResourceHandle: return hipErrorInvalidHandle; case cudaErrorNotReady: @@ -305,12 +303,53 @@ inline static hipError_t hipCUDAErrorTohipError(cudaError_t cuError) { return hipErrorAssert; case cudaErrorNotSupported: return hipErrorNotSupported; + case cudaErrorCudartUnloading: + return hipErrorDeinitialized; + case cudaErrorInvalidKernelImage: + return hipErrorInvalidImage; + case cudaErrorUnmapBufferObjectFailed: + return hipErrorUnmapFailed; + case cudaErrorNoKernelImageForDevice: + return hipErrorNoBinaryForGpu; + case cudaErrorECCUncorrectable: + return hipErrorECCNotCorrectable; + case cudaErrorDeviceAlreadyInUse: + return hipErrorContextAlreadyInUse; + case cudaErrorInvalidPtx: + return hipErrorInvalidKernelFile; + case cudaErrorLaunchTimeout: + return hipErrorLaunchTimeOut; +#if CUDA_VERSION >= 10010 + case cudaErrorInvalidSource: + return hipErrorInvalidSource; + case cudaErrorFileNotFound: + return hipErrorFileNotFound; + case cudaErrorSymbolNotFound: + return hipErrorNotFound; + case cudaErrorArrayIsMapped: + return hipErrorArrayIsMapped; + case cudaErrorNotMappedAsPointer: + return hipErrorNotMappedAsPointer; + case cudaErrorNotMappedAsArray: + return hipErrorNotMappedAsArray; + case cudaErrorNotMapped: + return hipErrorNotMapped; + case cudaErrorAlreadyAcquired: + return hipErrorAlreadyAcquired; + case cudaErrorAlreadyMapped: + return hipErrorAlreadyMapped; +#endif +#if CUDA_VERSION >= 10020 + case cudaErrorDeviceUninitialized: + return hipErrorInvalidContext; +#endif + case cudaErrorUnknown: default: return hipErrorUnknown; // Note - translated error. } } -inline static hipError_t hipCUResultTohipError(CUresult cuError) { // TODO Populate further +inline static hipError_t hipCUResultTohipError(CUresult cuError) { switch (cuError) { case CUDA_SUCCESS: return hipSuccess; @@ -329,21 +368,107 @@ inline static hipError_t hipCUResultTohipError(CUresult cuError) { // TODO Popu case CUDA_ERROR_NOT_INITIALIZED: return hipErrorNotInitialized; case CUDA_ERROR_INVALID_HANDLE: - return hipErrorInvalidHandle; + return hipErrorInvalidHandle; case CUDA_ERROR_MAP_FAILED: - return hipErrorMapFailed; + return hipErrorMapFailed; + case CUDA_ERROR_PROFILER_DISABLED: + return hipErrorProfilerDisabled; + case CUDA_ERROR_PROFILER_NOT_INITIALIZED: + return hipErrorProfilerNotInitialized; + case CUDA_ERROR_PROFILER_ALREADY_STARTED: + return hipErrorProfilerAlreadyStarted; + case CUDA_ERROR_PROFILER_ALREADY_STOPPED: + return hipErrorProfilerAlreadyStopped; + case CUDA_ERROR_INVALID_IMAGE: + return hipErrorInvalidImage; + case CUDA_ERROR_CONTEXT_ALREADY_CURRENT: + return hipErrorContextAlreadyCurrent; + case CUDA_ERROR_UNMAP_FAILED: + return hipErrorUnmapFailed; + case CUDA_ERROR_ARRAY_IS_MAPPED: + return hipErrorArrayIsMapped; + case CUDA_ERROR_ALREADY_MAPPED: + return hipErrorAlreadyMapped; + case CUDA_ERROR_NO_BINARY_FOR_GPU: + return hipErrorNoBinaryForGpu; + case CUDA_ERROR_ALREADY_ACQUIRED: + return hipErrorAlreadyAcquired; + case CUDA_ERROR_NOT_MAPPED: + return hipErrorNotMapped; + case CUDA_ERROR_NOT_MAPPED_AS_ARRAY: + return hipErrorNotMappedAsArray; + case CUDA_ERROR_NOT_MAPPED_AS_POINTER: + return hipErrorNotMappedAsPointer; + case CUDA_ERROR_ECC_UNCORRECTABLE: + return hipErrorECCNotCorrectable; + case CUDA_ERROR_UNSUPPORTED_LIMIT: + return hipErrorUnsupportedLimit; + case CUDA_ERROR_CONTEXT_ALREADY_IN_USE: + return hipErrorContextAlreadyInUse; + case CUDA_ERROR_PEER_ACCESS_UNSUPPORTED: + return hipErrorPeerAccessUnsupported; + case CUDA_ERROR_INVALID_PTX: + return hipErrorInvalidKernelFile; + case CUDA_ERROR_INVALID_GRAPHICS_CONTEXT: + return hipErrorInvalidGraphicsContext; + case CUDA_ERROR_INVALID_SOURCE: + return hipErrorInvalidSource; + case CUDA_ERROR_FILE_NOT_FOUND: + return hipErrorFileNotFound; + case CUDA_ERROR_SHARED_OBJECT_SYMBOL_NOT_FOUND: + return hipErrorSharedObjectSymbolNotFound; + case CUDA_ERROR_SHARED_OBJECT_INIT_FAILED: + return hipErrorSharedObjectInitFailed; + case CUDA_ERROR_OPERATING_SYSTEM: + return hipErrorOperatingSystem; + case CUDA_ERROR_NOT_FOUND: + return hipErrorNotFound; + case CUDA_ERROR_NOT_READY: + return hipErrorNotReady; + case CUDA_ERROR_ILLEGAL_ADDRESS: + return hipErrorIllegalAddress; + case CUDA_ERROR_LAUNCH_OUT_OF_RESOURCES: + return hipErrorLaunchOutOfResources; + case CUDA_ERROR_LAUNCH_TIMEOUT: + return hipErrorLaunchTimeOut; + case CUDA_ERROR_PEER_ACCESS_ALREADY_ENABLED: + return hipErrorPeerAccessAlreadyEnabled; + case CUDA_ERROR_PEER_ACCESS_NOT_ENABLED: + return hipErrorPeerAccessNotEnabled; + case CUDA_ERROR_PRIMARY_CONTEXT_ACTIVE: + return hipErrorSetOnActiveProcess; + case CUDA_ERROR_ASSERT: + return hipErrorAssert; + case CUDA_ERROR_HOST_MEMORY_ALREADY_REGISTERED: + return hipErrorHostMemoryAlreadyRegistered; + case CUDA_ERROR_HOST_MEMORY_NOT_REGISTERED: + return hipErrorHostMemoryNotRegistered; + case CUDA_ERROR_LAUNCH_FAILED: + return hipErrorLaunchFailure; + case CUDA_ERROR_NOT_SUPPORTED: + return hipErrorNotSupported; + case CUDA_ERROR_UNKNOWN: default: return hipErrorUnknown; // Note - translated error. } } -// TODO match the error enum names of hip and cuda inline static cudaError_t hipErrorToCudaError(hipError_t hError) { switch (hError) { case hipSuccess: return cudaSuccess; case hipErrorOutOfMemory: return cudaErrorMemoryAllocation; + case hipErrorProfilerDisabled: + return cudaErrorProfilerDisabled; + case hipErrorProfilerNotInitialized: + return cudaErrorProfilerNotInitialized; + case hipErrorProfilerAlreadyStarted: + return cudaErrorProfilerAlreadyStarted; + case hipErrorProfilerAlreadyStopped: + return cudaErrorProfilerAlreadyStopped; + case hipErrorInvalidConfiguration: + return cudaErrorInvalidConfiguration; case hipErrorLaunchOutOfResources: return cudaErrorLaunchOutOfResources; case hipErrorInvalidValue: @@ -362,22 +487,128 @@ inline static cudaError_t hipErrorToCudaError(hipError_t hError) { return cudaErrorNoDevice; case hipErrorNotReady: return cudaErrorNotReady; - case hipErrorUnknown: - return cudaErrorUnknown; case hipErrorPeerAccessNotEnabled: return cudaErrorPeerAccessNotEnabled; case hipErrorPeerAccessAlreadyEnabled: return cudaErrorPeerAccessAlreadyEnabled; - case hipErrorRuntimeMemory: - return cudaErrorUnknown; // Does not exist in CUDA - case hipErrorRuntimeOther: - return cudaErrorUnknown; // Does not exist in CUDA case hipErrorHostMemoryAlreadyRegistered: return cudaErrorHostMemoryAlreadyRegistered; case hipErrorHostMemoryNotRegistered: return cudaErrorHostMemoryNotRegistered; + case hipErrorDeinitialized: + return cudaErrorCudartUnloading; + case hipErrorInvalidSymbol: + return cudaErrorInvalidSymbol; + case hipErrorInsufficientDriver: + return cudaErrorInsufficientDriver; + case hipErrorMissingConfiguration: + return cudaErrorMissingConfiguration; + case hipErrorPriorLaunchFailure: + return cudaErrorPriorLaunchFailure; + case hipErrorInvalidDeviceFunction: + return cudaErrorInvalidDeviceFunction; + case hipErrorInvalidImage: + return cudaErrorInvalidKernelImage; + case hipErrorInvalidContext: +#if CUDA_VERSION >= 10020 + return cudaErrorDeviceUninitialized; +#else + return cudaErrorUnknown; +#endif + case hipErrorMapFailed: + return cudaErrorMapBufferObjectFailed; + case hipErrorUnmapFailed: + return cudaErrorUnmapBufferObjectFailed; + case hipErrorArrayIsMapped: +#if CUDA_VERSION >= 10010 + return cudaErrorArrayIsMapped; +#else + return cudaErrorUnknown; +#endif + case hipErrorAlreadyMapped: +#if CUDA_VERSION >= 10010 + return cudaErrorAlreadyMapped; +#else + return cudaErrorUnknown; +#endif + case hipErrorNoBinaryForGpu: + return cudaErrorNoKernelImageForDevice; + case hipErrorAlreadyAcquired: +#if CUDA_VERSION >= 10010 + return cudaErrorAlreadyAcquired; +#else + return cudaErrorUnknown; +#endif + case hipErrorNotMapped: +#if CUDA_VERSION >= 10010 + return cudaErrorNotMapped; +#else + return cudaErrorUnknown; +#endif + case hipErrorNotMappedAsArray: +#if CUDA_VERSION >= 10010 + return cudaErrorNotMappedAsArray; +#else + return cudaErrorUnknown; +#endif + case hipErrorNotMappedAsPointer: +#if CUDA_VERSION >= 10010 + return cudaErrorNotMappedAsPointer; +#else + return cudaErrorUnknown; +#endif + case hipErrorECCNotCorrectable: + return cudaErrorECCUncorrectable; + case hipErrorUnsupportedLimit: + return cudaErrorUnsupportedLimit; + case hipErrorContextAlreadyInUse: + return cudaErrorDeviceAlreadyInUse; + case hipErrorPeerAccessUnsupported: + return cudaErrorPeerAccessUnsupported; + case hipErrorInvalidKernelFile: + return cudaErrorInvalidPtx; + case hipErrorInvalidGraphicsContext: + return cudaErrorInvalidGraphicsContext; + case hipErrorInvalidSource: +#if CUDA_VERSION >= 10010 + return cudaErrorInvalidSource; +#else + return cudaErrorUnknown; +#endif + case hipErrorFileNotFound: +#if CUDA_VERSION >= 10010 + return cudaErrorFileNotFound; +#else + return cudaErrorUnknown; +#endif + case hipErrorSharedObjectSymbolNotFound: + return cudaErrorSharedObjectSymbolNotFound; + case hipErrorSharedObjectInitFailed: + return cudaErrorSharedObjectInitFailed; + case hipErrorOperatingSystem: + return cudaErrorOperatingSystem; + case hipErrorNotFound: +#if CUDA_VERSION >= 10010 + return cudaErrorSymbolNotFound; +#else + return cudaErrorUnknown; +#endif + case hipErrorIllegalAddress: + return cudaErrorIllegalAddress; + case hipErrorLaunchTimeOut: + return cudaErrorLaunchTimeout; + case hipErrorSetOnActiveProcess: + return cudaErrorSetOnActiveProcess; + case hipErrorLaunchFailure: + return cudaErrorLaunchFailure; + case hipErrorNotSupported: + return cudaErrorNotSupported; + // HSA: does not exist in CUDA + case hipErrorRuntimeMemory: + // HSA: does not exist in CUDA + case hipErrorRuntimeOther: + case hipErrorUnknown: case hipErrorTbd: - return cudaErrorUnknown; // Note - translated error. default: return cudaErrorUnknown; // Note - translated error. } diff --git a/hipamd/src/hiprtc.cpp b/hipamd/src/hiprtc.cpp index f3288a3bcb..5198bf0cbb 100644 --- a/hipamd/src/hiprtc.cpp +++ b/hipamd/src/hiprtc.cpp @@ -35,7 +35,6 @@ THE SOFTWARE. #include #include #include -#include #include #include #include @@ -43,11 +42,13 @@ THE SOFTWARE. #include #include #include +#include #include #include #include #include +#include const char* hiprtcGetErrorString(hiprtcResult x) { @@ -80,6 +81,20 @@ const char* hiprtcGetErrorString(hiprtcResult x) }; } +namespace hip_impl { +inline bool create_directory(const std::string& path) { + mode_t mode = 0755; + int ret = mkdir(path.c_str(), mode); + if (ret == 0) return true; + return false; +} + +inline bool fileExists (const std::string& name) { + struct stat buffer; + return (stat (name.c_str(), &buffer) == 0); +} +} // namespace hip_impl + namespace { struct Symbol { @@ -196,8 +211,7 @@ struct _hiprtcProgram { } // MANIPULATORS - bool compile(const std::vector& args, - const std::experimental::filesystem::path& program_folder) + bool compile(const std::vector& args) { using namespace ELFIO; using namespace redi; @@ -288,9 +302,19 @@ struct _hiprtcProgram { return true; } + void replaceExtension(std::string& fileName, const std::string &ext) const { + auto res = fileName.rfind('.'); + auto sloc = fileName.rfind('/'); // slash location + if (res != std::string::npos && (res > sloc || sloc == std::string::npos)) { + fileName.replace(fileName.begin() + res, fileName.end(), ext); + } else { + fileName += ext; + } + } + // ACCESSORS - std::experimental::filesystem::path writeTemporaryFiles( - const std::experimental::filesystem::path& programFolder) const + std::string writeTemporaryFiles( + const std::string& programFolder) const { using namespace std; @@ -298,12 +322,13 @@ struct _hiprtcProgram { transform(headers.cbegin(), headers.cend(), begin(fut), [&](const pair& x) { return async([&]() { - ofstream h{programFolder / x.first}; + ofstream h{programFolder + '/' + x.first}; h.write(x.second.data(), x.second.size()); }); }); - auto tmp{(programFolder / name).replace_extension(".cpp")}; + auto tmp{(programFolder + '/' + name)}; + replaceExtension(tmp, ".cpp"); ofstream{tmp}.write(source.data(), source.size()); return tmp; @@ -356,27 +381,23 @@ namespace { class Unique_temporary_path { // DATA - std::experimental::filesystem::path path_{}; + std::string path_{}; public: // CREATORS Unique_temporary_path() : path_{std::tmpnam(nullptr)} { - while (std::experimental::filesystem::exists(path_)) { + while (hip_impl::fileExists(path_)) { path_ = std::tmpnam(nullptr); } } - Unique_temporary_path(const std::string& extension) - : Unique_temporary_path{} - { - path_.replace_extension(extension); - } Unique_temporary_path(const Unique_temporary_path&) = default; Unique_temporary_path(Unique_temporary_path&&) = default; ~Unique_temporary_path() noexcept { - std::experimental::filesystem::remove_all(path_); + std::string s("rm -r " + path_); + system(s.c_str()); } // MANIPULATORS @@ -385,7 +406,7 @@ namespace Unique_temporary_path& operator=(Unique_temporary_path&&) = default; // ACCESSORS - const std::experimental::filesystem::path& path() const noexcept + const std::string& path() const noexcept { return path_; } @@ -483,12 +504,12 @@ hiprtcResult hiprtcCompileProgram(hiprtcProgram p, int n, const char** o) getenv("HIP_PATH") ? (getenv("HIP_PATH") + string{"/bin/hipcc"}) : "/opt/rocm/bin/hipcc"}; - if (!experimental::filesystem::exists(hipcc)) { + if (!hip_impl::fileExists(hipcc)) { return HIPRTC_ERROR_INTERNAL_ERROR; } Unique_temporary_path tmp{}; - experimental::filesystem::create_directory(tmp.path()); + hip_impl::create_directory(tmp.path()); const auto src{p->writeTemporaryFiles(tmp.path())}; @@ -499,9 +520,9 @@ hiprtcResult hiprtcCompileProgram(hiprtcProgram p, int n, const char** o) args.emplace_back(src); args.emplace_back("-o"); - args.emplace_back(tmp.path() / "hiprtc.out"); + args.emplace_back(tmp.path() + '/' + "hiprtc.out"); - if (!p->compile(args, tmp.path())) return HIPRTC_ERROR_INTERNAL_ERROR; + if (!p->compile(args)) return HIPRTC_ERROR_INTERNAL_ERROR; if (!p->readLoweredNames()) return HIPRTC_ERROR_INTERNAL_ERROR; p->compiled = true; diff --git a/hipamd/tests/src/deviceLib/hip_bitextract.cpp b/hipamd/tests/src/deviceLib/hip_bitextract.cpp index 5ee3974107..5c686f5705 100644 --- a/hipamd/tests/src/deviceLib/hip_bitextract.cpp +++ b/hipamd/tests/src/deviceLib/hip_bitextract.cpp @@ -123,6 +123,8 @@ int main() { hostSrc032[i] = uint32_src0_dist(rd); hostSrc132[i] = uint32_src12_dist(rd); hostSrc232[i] = uint32_src12_dist(rd); + if (hostSrc132[i] + hostSrc232[i] > 32) + hostSrc232[i] = 32 - hostSrc132[i]; hostOut64[i] = 0; hostSrc064[i] = uint64_src0_dist(rd); hostSrc164[i] = uint64_src12_dist(rd);