From 34976e357dfcf3cd05d82f5e2bfec4fc5c998028 Mon Sep 17 00:00:00 2001 From: Ben Sander Date: Thu, 24 Mar 2016 11:53:28 -0500 Subject: [PATCH 1/4] Add --hipcc_explicit_lib option Tells hipcc not to add /opt/hip or -lhip_hcc to command-line (since it has already been done). --- hipamd/bin/hipcc | 46 +++++++++++---------------------- hipamd/tests/src/CMakeLists.txt | 3 ++- 2 files changed, 17 insertions(+), 32 deletions(-) diff --git a/hipamd/bin/hipcc b/hipamd/bin/hipcc index a3c019c91f..3172e5c7e1 100755 --- a/hipamd/bin/hipcc +++ b/hipamd/bin/hipcc @@ -124,8 +124,10 @@ if ($verbose & 0x4) { print "hipcc-args: ", join (" ", @ARGV), "\n"; } +my $toolArgs = ""; # arguments to pass to the hcc or nvcc tool foreach $arg (@ARGV) { + my $swallowArg = 0; if ($arg eq '-c') { $compileOnly = 1; $needCXXFLAGS = 1; @@ -138,7 +140,17 @@ foreach $arg (@ARGV) if ($arg =~ m/^-/) { # options start with - - push (@options, $arg); + + # Process HIPCC options here: + if ($arg =~ m/^--hipcc/) { + $swallowArg = 1; + if ($arg eq "--hipcc_explicit_lib") { + # Some environments (ie cmake tests) already link their own hip_hcc.o, so don't add here: + $needHipHcc = 0; + } + } else { + push (@options, $arg); + } #print "O: <$arg>\n"; } else { # input files and libraries @@ -151,13 +163,10 @@ foreach $arg (@ARGV) $needCXXFLAGS = 1; } - if (($arg =~ /hip_hcc\.o$/) or ($arg =~ /hip_hcc\.cpp$/)) { - $needHipHcc = 0; - } - push (@inputs, $arg); #print "I: <$arg>\n"; } + $toolArgs .= " $arg" unless $swallowArg; } if ($hasC and $HIP_PLATFORM eq 'nvcc') { @@ -172,30 +181,6 @@ if (($verbose & 0x18) and ($HIP_PLATFORM eq 'hcc')) { } if ($needHipHcc) { - # See if we need to remake the .o file: -# my $source = "$HIP_PATH/src/hip_hcc.cpp" ; -# my $object = "$HIP_PATH/src/hip_hcc.o" ; - - # remake if object does not exist, or if source is newer than object: -# if ((not -e $object) or ((stat($source))[9] > (stat($object))[9])) { -# my $CMD = "$HCC $HCCFLAGS -I$HSA_PATH/include -I$HIP_PATH/include -Wall -c $source -o $object"; -# if ($verbose & 0x10) { -# $CMD .= " -g -O0" ; -# } else { -# $CMD .= " -O3" ; -# } - -# $CMD .= " -I$marker_path/include"; - - -# if ($verbose & 0x1) { -# print "remake-deps:", $CMD, "\n"; -# } -# system ("$CMD") and die ("remake-deps failed"); - - -# } - $HIPLDFLAGS .= " -L/opt/hip/lib -lhip_hcc" ; } @@ -205,7 +190,6 @@ if ($needHipHcc) { # pass-through CPP mode. -$args = join(" ", @ARGV); my $CMD="$HIPCC"; if ($needCXXFLAGS) { @@ -214,7 +198,7 @@ if ($needCXXFLAGS) { if ($needLDFLAGS and not $compileOnly) { $CMD .= " $HIPLDFLAGS"; } -$CMD .= " $args"; +$CMD .= " $toolArgs"; if ($verbose & 0x1) { print "hipcc-cmd: ", $CMD, "\n"; diff --git a/hipamd/tests/src/CMakeLists.txt b/hipamd/tests/src/CMakeLists.txt index e9f29ca159..81e5dd7838 100644 --- a/hipamd/tests/src/CMakeLists.txt +++ b/hipamd/tests/src/CMakeLists.txt @@ -62,6 +62,8 @@ else() endif() set (HIPCC ${HIP_PATH}/bin/hipcc) +set (CMAKE_CXX_COMPILER ${HIPCC}) +set (CMAKE_CXX_FLAGS --hipcc_explicit_lib) add_library(test_common OBJECT test_common.cpp ) @@ -116,7 +118,6 @@ macro (make_test_matches exe match_string) endmacro() -set (CMAKE_CXX_COMPILER ${HIPCC}) #make_hip_executable (hipAPIStreamEnable hipAPIStreamEnable.cpp) #make_hip_executable (hipAPIStreamDisable hipAPIStreamDisable.cpp) From 84ccbcada0f1f27a8cfdef00f5b072157e2b330f Mon Sep 17 00:00:00 2001 From: Ben Sander Date: Thu, 24 Mar 2016 13:20:25 -0500 Subject: [PATCH 2/4] revert CMakelists --- hipamd/tests/src/CMakeLists.txt | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/hipamd/tests/src/CMakeLists.txt b/hipamd/tests/src/CMakeLists.txt index ce005bc386..81e5dd7838 100644 --- a/hipamd/tests/src/CMakeLists.txt +++ b/hipamd/tests/src/CMakeLists.txt @@ -40,12 +40,12 @@ if (${HIP_PLATFORM} STREQUAL "hcc") #Include HIP and HC since the tests need both of these: #Note below HSA path is surgically included only where necessary. include_directories(${HIP_PATH}/include) - include_directories(${HSA_PATH}/include) - # hip_hcc.o: - #add_library(hip_hcc STATIC ${HIP_PATH}/src/hip_hcc.cpp ) - add_library(hip_hcc STATIC ${HIP_PATH}/src/hip_hcc.cpp ${HIP_PATH}/src/hip_error.cpp ${HIP_PATH}/src/hip_device.cpp ${HIP_PATH}/src/hip_stream.cpp ${HIP_PATH}/src/hip_event.cpp ${HIP_PATH}/src/hip_memory.cpp ${HIP_PATH}/src/hip_peer.cpp ${HIP_PATH}/src/staging_buffer.cpp) - target_include_directories(hip_hcc PRIVATE ${HSA_PATH}/include ${CODEXL_SDK_ATAL_PATH}/include) + include_directories(${HSA_PATH}/include) + # This will create a subdir "hip_hcc" in the test build directory + # Any changes to hip_hcc source will be detected and force the library and then the tests to be rebuilt. + add_subdirectory(${HIP_PATH} hip_hcc) + link_directories(${CMAKE_CURRENT_BINARY_DIR}/hip_hcc) # search the local hip_hcc for libhip_hcc.a elseif (${HIP_PLATFORM} STREQUAL "nvcc") MESSAGE ("HIP_PLATFORM=nvcc") @@ -73,7 +73,7 @@ add_library(test_common OBJECT test_common.cpp ) macro (make_hip_executable exe cpp) if (${HIP_PLATFORM} STREQUAL "hcc") add_executable (${exe} ${cpp} ${ARGN} $ ) -# target_link_libraries(${exe} hip_hcc) + target_link_libraries(${exe} hip_hcc) else() add_executable (${exe} ${cpp} ${ARGN} $ ) endif() From bcba591852cd4cd385e376f09366b402c5509c23 Mon Sep 17 00:00:00 2001 From: Ben Sander Date: Thu, 24 Mar 2016 13:33:07 -0500 Subject: [PATCH 3/4] Provcide more flexiblity in using HIP_PATH to control installation. Also improve docs for developers / contributing. --- hipamd/CMakeLists.txt | 8 +++++++- hipamd/CONTRIBUTING.md | 17 +++++++++++++++-- hipamd/README.md | 5 +++-- hipamd/bin/hipcc | 9 +++------ hipamd/tests/README.md | 31 ++++++++++++++++--------------- 5 files changed, 44 insertions(+), 26 deletions(-) diff --git a/hipamd/CMakeLists.txt b/hipamd/CMakeLists.txt index 666338f500..5aedd12d77 100644 --- a/hipamd/CMakeLists.txt +++ b/hipamd/CMakeLists.txt @@ -11,8 +11,14 @@ MESSAGE ("HCC_HOME=" ${HCC_HOME}) set(HSA_PATH "/opt/hsa") + +set (HIP_INSTALL_PATH $ENV{HIP_PATH}) +if (NOT DEFINED HIP_INSTALL_PATH) + set (HIP_INSTALLPATH /opt/hip) +endif() + if (CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) - set(CMAKE_INSTALL_PREFIX "/opt/hip" CACHE PATH "Default installation path of hip" FORCE) + set(CMAKE_INSTALL_PREFIX "${HIP_INSTALL_PATH}" CACHE PATH "Default installation path of hip" FORCE) endif () include_directories(${PROJECT_SOURCE_DIR}/include) diff --git a/hipamd/CONTRIBUTING.md b/hipamd/CONTRIBUTING.md index 685683e697..b593cadd64 100644 --- a/hipamd/CONTRIBUTING.md +++ b/hipamd/CONTRIBUTING.md @@ -52,8 +52,21 @@ The unix `date` command can print the HCC-format work-week for a specific date , HIP includes unit tests in the tests/src directory. When adding a new HIP feature, add a new unit test as well. -The tests/src/hipMemtest.cpp file contains a simple unit test and is a good starting point for other tests. -Modify tests/src/CMakefiles.txt to add the test to the build environment. +See [tests/README.md](README.md) for more information. + +## Development Flow +The Unit testing environment automatically rebuilds libhip_hcc.a and the tests when a change it made to the HIP source, and this +is a great place to develop new features alongside the associated test. + +For applications and benchmarks outside the directed test environment, developments should use a two-step development flow: +- #1. Compile, link, and install HCC. See [Installation](README.md#Installation) notes. +- #2. Relink the target application to include changes in the libhip_hcc.a file. + +## Environment Variables +- **HIP_PATH** : Location of HIP include, src, bin, lib directories. +- **HCC_HOME** : Path to HCC compiler. Default /opt/hcc. +- **HSA_PATH** : Path to HSA include, lib. Default /opt/hcc. +- **CUDA_PATH* : On nvcc system, this points to root of CUDA installation. ### Contribution guidelines ### diff --git a/hipamd/README.md b/hipamd/README.md index c695a8740c..a60405053f 100644 --- a/hipamd/README.md +++ b/hipamd/README.md @@ -6,7 +6,7 @@ Key features include: * HIP is very thin and has little or no performance impact over coding directly in CUDA or hcc "HC" mode. * HIP allows coding in a single-source C++ programming language including features such as templates, C++11 lambdas, classes, namespaces, and more. * HIP allows developers to use the "best" development environment and tools on each target platform. -* The "hipify" script automatically converts source from CUDA to HIP. +* The "hipify" tool automatically converts source from CUDA to HIP. * Developers can specialize for the platform (CUDA or hcc) to tune for performance or handle tricky cases New projects can be developed directly in the portable HIP C++ language and can run on either NVIDIA or AMD platforms. Additionally, HIP provides porting tools which make it easy to port existing CUDA codes to the HIP layer, with no loss of performance as compared to the original CUDA application. HIP is not intended to be a drop-in replacement for CUDA, and developers should expect to do some manual coding and performance tuning work to complete the port. @@ -19,7 +19,7 @@ cmake .. make sudo make install ``` -Make sure HIP_PATH is pointed to `/opt/hip` and PATH to `/opt/hip/bin` +Make sure HIP_PATH is pointed to `/opt/hip` and PATH includes `$HIP_PATH/bin` ## More Info: - [HIP FAQ](docs/markdown/hip_faq.md) @@ -27,6 +27,7 @@ Make sure HIP_PATH is pointed to `/opt/hip` and PATH to `/opt/hip/bin` - [HIP Runtime API (Doxygen)](http://gpuopen-professionalcompute-tools.github.io/HIP) - [HIP Porting Guide](docs/markdown/hip_porting_guide.md) - [HIP Terminology](docs/markdown/hip_terms.md) (including Rosetta Stone of GPU computing terms across CUDA/HIP/HC/AMP/OpenL) +- [Developer/CONTRIBUTING Info](CONTRIBUTING.md) - [Release Notes](RELEASE.md) diff --git a/hipamd/bin/hipcc b/hipamd/bin/hipcc index 3172e5c7e1..44b1e85a33 100755 --- a/hipamd/bin/hipcc +++ b/hipamd/bin/hipcc @@ -26,7 +26,7 @@ exit(-1); $verbose = $ENV{'HIPCC_VERBOSE'}; $verbose = 0 unless defined $verbose; -# Verbose: 0x1=commands, 0x2=paths, 0x4=hippc args, 0x8=force remake hip_hcc.o, 16=remake hip_hcc in debug. +# Verbose: 0x1=commands, 0x2=paths, 0x4=hippc args $HIP_PATH=$ENV{'HIP_PATH'}; $HIP_PATH=dirname (dirname $0) unless defined $HIP_PATH; # use parent directory of hipcc @@ -176,12 +176,9 @@ if ($hasCU and $HIP_PLATFORM eq 'hcc') { $HIPCXXFLAGS .= " -x c++"; } -if (($verbose & 0x18) and ($HIP_PLATFORM eq 'hcc')) { - $needHipHcc = 1; -} - if ($needHipHcc) { - $HIPLDFLAGS .= " -L/opt/hip/lib -lhip_hcc" ; + #$HIPLDFLAGS .= " -L/opt/hip/lib -lhip_hcc" ; + $HIPLDFLAGS .= " -L$HIP_PATH/lib -lhip_hcc" ; } # hipcc currrently requires separate compilation of source files, ie it is not possible to pass diff --git a/hipamd/tests/README.md b/hipamd/tests/README.md index 96de22b558..d7ddf0ea68 100644 --- a/hipamd/tests/README.md +++ b/hipamd/tests/README.md @@ -1,6 +1,9 @@ -Tests uses CMAKE as teh build infrastructure. +# HIP testing environment. -Use : +This document explains how to use the HIP CMAKE testing environment. + +### Quickstart +Usage : ``` $ mkdir build $ cd build @@ -9,31 +12,29 @@ $ make $ make test ``` -#----- ### How to add a new test -edit src/CMakeFiles to add the test: +The tests/src/hipMemtest.cpp file contains a simple unit test and is a good starting point for other tests. +Copy this to a new test name and modify tests/src/CMakefiles.txt to add the test to the build environment. -### add the executable and list of required CPP files, ie: +#### Edit CMakefiles.txt: +// Example: ``` -make_test (EXE CPP_FILES) -make_hip_executable (hipMemset hipMemset.cpp) -``` - -### Add to automated Test framework: -``` -make_test (TESTNAME ARGS) +make_hip_executable (hipMemset hipMemset.cpp) make_test(hipMemset " ") ``` - ### Running tests: ``` -make test +ctest ``` -# Run a specific test: +### Run subsets of all tests: ``` +# Run one test on the commandline (obtain commandline parms from CMakefiles.tst) ./hipMemset + +# Run all the memory tests: +ctest -R Memcpy ``` From 663d1baa19069dc821ed5d32cc34802cf622c272 Mon Sep 17 00:00:00 2001 From: Ben Sander Date: Thu, 24 Mar 2016 14:08:08 -0500 Subject: [PATCH 4/4] Update release to include new make system. Remove old Makefile. --- hipamd/Makefile | 22 ---------------------- hipamd/RELEASE.md | 4 ++++ 2 files changed, 4 insertions(+), 22 deletions(-) delete mode 100644 hipamd/Makefile diff --git a/hipamd/Makefile b/hipamd/Makefile deleted file mode 100644 index 33b43f53e9..0000000000 --- a/hipamd/Makefile +++ /dev/null @@ -1,22 +0,0 @@ -#must also be specified in doxygen-input/doxy.cfg, - -HIP_PATH ?= . -HIPCC = $(HIP_PATH)/bin/hipcc -HSA_PATH ?= /opt/hsa - - -HIP_SOURCES = $(HIP_PATH)/src/hip_hcc.cpp -HIP_OBJECTS = $(HIP_SOURCES:.cpp=.o) - -$(HIP_OBJECTS): HIPCC_FLAGS += -I$(HSA_PATH)/include - -$(HIP_OBJECTS): - -%.o:: %.cpp - $(HIPCC) $(HIPCC_FLAGS) $< -c -O3 -o $@ - - -clean: - rm -f $(HIP_OBJECTS) - - diff --git a/hipamd/RELEASE.md b/hipamd/RELEASE.md index d22452b954..e5a0e61d13 100644 --- a/hipamd/RELEASE.md +++ b/hipamd/RELEASE.md @@ -14,6 +14,10 @@ We have attempted to document known bugs and limitations - in particular the [HI Stay tuned - the work for many of these features is already in-flight. Next: +- Refactor HIP make and install system: + - Move to CMake. + - Split source into multiple modular .cpp and .h files. + - Create static library and link. - Deprecate hipDeviceGetProp, replace with hipGetDeviceProp - Deprecate hipMallocHost (Replace with hipHostMalloc) - Deprecate hipFreeHost (Replace with hipHostFree).