Commit Graph

147 Commits

Author SHA1 Message Date
Maneesh Gupta 1ba06f63c4 Apply .clangformat to all repo source files
Change-Id: I7e79c6058f0303f9a98911e3b7dd2e8596079344
2018-03-12 11:29:03 +05:30
Evgeny Mankov 7f3e89bbb0 [HIPIFY][fix] Build against llvm 3.8.0 fixed - missing include
/srv/HIP/hipify-clang/src/main.cpp:134:19: error: no member named 'dbgs' in namespace 'llvm'
      DEBUG(llvm::dbgs() << "Skipped some replacements.\n");
            ~~~~~~^
2018-02-08 00:08:47 +03:00
Evgeny Mankov 26095fe7c1 [HIPIFY][tests] add poisson-api-example test
+ add missing types
+ doc update
2018-01-30 19:50:18 +03:00
Evgeny Mankov 9d814bef31 [HIPIFY][tests] fix typo 2018-01-30 18:55:09 +03:00
Evgeny Mankov 02e23c4d87 [HIPIFY] InclusionDirective refactoring
Due to support of cuRAND headers.

+ compound test on all headers is added;
+ missing entities are added with updating the doc;
+ a couple cuRAND tests are added (https://github.com/ROCmSoftwarePlatform/rocRAND/tree/master/benchmark):
  - the following CUDA entities are still unsupported by hipRAND:
      curandMakeMTGP32Constants
      curandMakeMTGP32KernelState
      curandGetDirectionVectors32
      curandDirectionVectorSet_t
      CURAND_DIRECTION_VECTORS_32_JOEKUO6
      curandStateSobol64_t
      curandStateScrambledSobol64_t
      curandGenerateLongLong
  - and the following - by HIP:
      cudaRuntimeGetVersion
  - those entities are handled by CHECK-NOT directive for now.
2018-01-29 18:33:47 +03:00
Evgeny Mankov fb1012a4b8 Merge pull request #340 from emankov/master
[HIPIFY][fix] Fix PragmaDirective
2018-01-24 18:09:54 +03:00
Evgeny Mankov 600d5d7c06 [HIPIFY][fix] CUDA and cuBLAS main headers correct handling 2018-01-23 23:43:36 +03:00
Evgeny Mankov 77f807b597 [HIPIFY][fix] Fix PragmaDirective
File location have to be verified, otherwise location of the first found '#pragma once' in any included header even system will be erroneously handled, which might lead to attempt to including hip_runtime.h in it.
2018-01-23 23:06:55 +03:00
Evgeny Mankov ddfb110080 [HIPIFY] Sync with hipBLAS ToT and CUDA cuBLAS 9.1 2018-01-22 17:12:02 +03:00
Evgeny Mankov 6e000adde4 [HIPIFY] cuRAND lib support (Device) 2018-01-19 21:29:05 +03:00
Evgeny Mankov 8ff99eeadc [HIPIFY] cuRAND lib support (partial - only Host) 2018-01-19 17:38:51 +03:00
Evgeny Mankov 0f7d687271 Merge pull request #332 from emankov/cudaMap_2
[HIPIFY] Add cudaMalloc3D support
2018-01-18 13:05:57 +03:00
Evgeny Mankov ff5f964c07 [HIPIFY] Add cudaMalloc3D support 2018-01-18 12:28:56 +03:00
Evgeny Mankov 5788ac5d37 [HIPIFY] Add CUDA Driver API Texture Ref support (partial) 2018-01-18 12:03:03 +03:00
Evgeny Mankov 478fed74fe [HIPIFY] Add more supported by HIP CUDA Driver API Arrays data types and functions 2018-01-16 21:07:50 +03:00
Evgeny Mankov 88c5ffee3a Merge pull request #319 from emankov/issue_211
[HIPIFY][fix][#211] Algorithm for explicit insert of hip include directive
2018-01-16 19:47:15 +03:00
Evgeny Mankov eb61038736 [HIPIFY] Add more supported by HIP CUDA RT API Textures and Arrays data types 2018-01-16 17:21:19 +03:00
Evgeny Mankov e54d9f3df0 Update HipifyAction.cpp
dead code eliminate
2018-01-16 15:08:08 +03:00
Evgeny Mankov 09655a0853 [HIPIFY][fix][#211] Algorithm for explicit insert of hip include directive
If in source CUDA file main header (cuda_runtime.h or cuda.h) is not presented, corresponding HIP main header (hip_runtime.h) should be explicitly included in output hipified file.

[Algorithm]
1. If #pragma once is presented, HIP main header should be placed just after it;
2. Otherwise if any other (not CUDA main) header is presented, HIP main header should be placed just before it;
3. Otherwise HIP main header should be placed in the beginning of output file.

P.S.
There might be one more situation when #ifndef #define ... #endif guard for the entire file is presented (make sense for *.h, *.hpp, *.cuh files). In this case HIP main include should be placed just after such #ifdef, or after #pragma once, if it is also presented. This situation will be handled in a separate change.
2018-01-15 21:05:05 +03:00
Evgeny Mankov f19cb9995e Merge pull request #307 from emankov/issue_306
[HIPIFY][FIX][#306] Eliminate second cuda main include directive
2018-01-10 22:50:44 +03:00
Evgeny Mankov 08662fba73 [HIPIFY][fix][#306] Code improve 2018-01-10 21:26:05 +03:00
Evgeny Mankov 3f6de8bb10 [HIPIFY][#308][fix] Consume error returned by Replacements::add(...) 2018-01-09 20:03:53 +03:00
Evgeny Mankov 7e7cfa10cc [HIPIFY][FIX][#306] Eliminate second cuda main include directive
// hipified to #include<hip/hip_runtime.h>
#include<cuda.h> // 1st cuda main include (Driver API)
// to eliminate
#include<cuda_runtime.h> // 2nd cuda main include (Runtime API)

HIP has one header hip_runtime.h for both CUDA APIs, thus second cuda main include directive is eliminated entirely.
2017-12-26 20:54:54 +03:00
Evgeny Mankov 5d92a6c252 [HIPIFY] Remove cudaBuiltin matcher 2017-12-06 20:22:14 +03:00
Evgeny Mankov 71d2fb20c8 [HIPIFY] Disable cudaBuiltin matcher.
As HIP has started to support vanilla CUDA syntax for threadIdx, blockIdx, blockDim and gridDim.
Other CUDA builtins are not tracked for now.
2017-12-05 20:28:51 +03:00
Evgeny Mankov f24dfc6f36 [HIPIFY] remove duplicates from CUDA_IDENTIFIER_MAP 2017-12-05 19:46:53 +03:00
Evgeny Mankov aa05b3d84e Merge pull request #262 from ChrisKitching/frontendaction
[HIPIFY] Mostly fix preprocessor-or-template induced issues
2017-11-27 17:30:11 +03:00
Chris Kitching 6b767a59ba Use proper clang diagnostics for printing warnings
Much pretty. Very wow

This gives users all the usual power when it comes to manipulating
clang diagnostics. People can pass -Werror can have hipify fail if
it doesn't completely translate a file, for example. Much nicer
than reinventing the wheel.
2017-11-13 20:58:55 +00:00
Chris Kitching 24cdc5e1d3 Use a custom FrontendAction to simplify identifier translation
Most of what hipify does is really just replacing CUDA idenitifers
with HIP ones. CUDA function calls, preprocessor macro calls,
enum references, types, etc.

This is problematic: calls/types/enum-refs require name resolution
for the AST matcher to work. This fails in the presence of code
deleted by the preprocessor, and in two-pass template compilation.

Instead, we can simply hook the lexer and have it rewrite the
identifiers for us.

This approach means identifier transformations will work correctly
regardless of where they appear (and we get to delete lots of code)

- Fixes #260
- Helps a bit with #207 - it will still fail to translate kernel
calls in preprocessor-ignored code, but everything except kerel
launches should translate correctly now, even in
preprocessor-deleted code.
2017-11-13 20:58:54 +00:00
Chris Kitching 23b5d26582 Add hipify mappings for all CUDA headers that have HIP equivalents
I'm particularly running into issues with `device_types.h` in real
CUDA code...
2017-11-13 17:20:07 +00:00
Evgeny Mankov 44c74b6511 [HIPIFY] fix typo - missing ) 2017-10-27 23:31:43 +03:00
Chris Kitching 20871a3a07 Remove commented else-block
A warning statement for _string literals_ seems a bit unhelpful.
There's no value in this being here.
2017-10-27 20:12:33 +01:00
Chris Kitching b303ffe53e Decouple the statistics system from the code translation
The original implementation had the statistics system woken very
tightly into things like PPCallbacks, with counters duplicated
in two places, and all the output code duplicated. This made it
very difficult to alter the structure of the program without
breaking the statistics system.

Since the planned approach for solving the remaining preprocessor
bugs needs the introduction of a custom FrontendAction, and such
a restructure was incompatible with the way the statistics system
was set up, this rewrite was required.

'tis rather simpler now, mind you :D

This commit also fixes an issue where some stats were counted
twice, and allows `-print-stats` to operate independently of
`-stat-output`, allowing you to print stats to a file without
printing them to a terminal (or vice-versa).
2017-10-27 20:12:33 +01:00
Chris Kitching 5699c18adc Copy-paste less in the statistics printing code 2017-10-27 20:12:33 +01:00
Chris Kitching 50448aec3b Inline updateCountersExt 2017-10-27 20:12:32 +01:00
Chris Kitching d8beee8918 Update counter maps sanely
operator[] default-constructs the map value if no value exists
for that key. Default-construction of int yields a zero. So all
the manual faffing around is just unnecessary.
2017-10-27 20:12:32 +01:00
Chris Kitching 00bb447e55 Prefer references to pointers in updateCountersExt() 2017-10-27 20:12:32 +01:00
Chris Kitching ee8e11a720 Move string utility functions into their own translation unit 2017-10-27 20:12:32 +01:00
Chris Kitching 1bd837b4b1 Extract LLVM compatibility code into its own translation unit 2017-10-27 20:12:32 +01:00
Chris Kitching 0c09bdf523 Remove unused field 2017-10-27 20:12:32 +01:00
Chris Kitching c6707ef33c Remove CUDA_EXCLUDES
An artefact from a now-defunct hack to avoid corrupting programs
2017-10-27 20:12:32 +01:00
Chris Kitching 2f376c9b25 Make unsupported actually be a bool... 2017-10-27 20:12:31 +01:00
Evgeny Mankov 9151a355c6 Merge pull request #234 from ChrisKitching/warningSpam
[HIPIFY] Do not process __fetch_builtin_* in cudaCall()
2017-10-27 21:30:42 +03:00
Chris Kitching 094b2b9b05 Greatly enhance handling of macros in kernel launches
All but the most contrived use of macros is now properly handled -
have a look at the new testcases this commit adds. You can have
macros in kernel calls, macros spanning chunks of your arguments,
the call, call parameters, or callee can all be macros or
partially macros.
2017-10-26 17:28:46 +01:00
Chris Kitching eff86d975b Simplify how kernel launch expressions get translated
It seems like there was a lot of machinery here that is no longer
needed now we have hipLaunchKernelGGL (which doesn't require us
to insert an extra argument into kernel functions). We no longer
need to waste cycles scanning the AST for callees.

We can literally just do "Take the callee expression, and dump
it into the first argument of hipLaunchKernelGGL()".
2017-10-26 17:28:30 +01:00
Chris Kitching fd911e1839 Deduplicate preprocessor code
There's three functions here that all do the same thing...

There was also logic that looks for numeric literals and works
backwards to find the macro name from which they are expanded.
I previously introduced code that rewrites macro references at
expand-time in the `MacroExpands` callback, so that code is no
longer doing anything useful.
2017-10-26 17:28:30 +01:00
Chris Kitching d1e26b2e7e Rewrite _all_ CUDA macro identifiers in the preprocessor
Calls to macros that were themselves CUDA API calls were often
being missed - this applies the identifier transform to macro
names at the callsites, too.
2017-10-26 17:27:56 +01:00
Chris Kitching 4a794ed8c0 Don't special-case source locations for calls in macros
The source location for a call that's inside a macro body will,
by default, point into the macro definition itself. The original
logic was causing macro invocations to be overwritten, as I
explain here:
https://github.com/ROCm-Developer-Tools/HIP/issues/207#issuecomment-337521851

The existing PPCallbacks code is correctly rewriting macro
definitions, so the practical effect of this change is that AST
rewrites on code that's expanded from macros are no-ops.

It might be a performance optimisation to put a short-circiut at
the top of the AST callbacks to abort when faced with code that
was expanded from macros.

It might yet prove wise to do absolutely everything at lex-time...
2017-10-26 17:26:37 +01:00
Chris Kitching 35a892bc77 Prefer early-return to deep nesting
A chain of 7 closing braces is never a great sign :D

In the process it became apparant that the unsupported flag
was being silently ignored, causing users to be left with cuda
API calls in their programs with no warning given. This has been
rectified for consistency.
2017-10-26 17:26:37 +01:00
Chris Kitching 2a5acac80e Do not process __fetch_builtin_* in cudaCall()
Fixes #205
2017-10-26 17:23:55 +01:00