Skip to content

Commit

Permalink
CMake Find - Half added (#247)
Browse files Browse the repository at this point in the history
  • Loading branch information
kiritigowda committed Oct 31, 2023
1 parent 1867b75 commit 9e857cb
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 9 deletions.
6 changes: 4 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,10 @@ if("${CMAKE_CURRENT_SOURCE_DIR}" STREQUAL "${CMAKE_BINARY_DIR}")
endif()
list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)

# Half
find_package(HALF REQUIRED)
include_directories(${HALF_INCLUDE_DIRS})

# OpenMP
find_package(OpenMP REQUIRED)
if(APPLE)
Expand All @@ -146,7 +150,6 @@ if(APPLE)
set(OpenMP_libgomp_LIBRARY ${OpenMP_CXX_LIB_NAMES})
set(OpenMP_libiomp5_LIBRARY ${OpenMP_CXX_LIB_NAMES})
endif()
include_directories(/usr/local/include)
else()
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
Expand Down Expand Up @@ -245,7 +248,6 @@ endif()
if("${BACKEND}" STREQUAL "CPU")
# Add modules
set(MODULES_LIST modules)
include_directories(${ROCM_PATH}/${CMAKE_INSTALL_INCLUDEDIR})
foreach(MOD_NAME ${MODULES_LIST})
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/src/${MOD_NAME})
endforeach(MOD_NAME)
Expand Down
25 changes: 18 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,16 +83,27 @@ doxygen .Doxyfile
* CMake Version `3.5` and above

* IEEE 754-based half-precision floating-point library - half.hpp
+ Use `half` package with ROCm

```
wget https://sourceforge.net/projects/half/files/half/1.12.0/half-1.12.0.zip
unzip half-1.12.0.zip -d half-files
sudo mkdir /usr/local/include/half
sudo cp half-files/include/half.hpp /usr/local/include/half
```
* C++ Version `17` and above
```
sudo apt-get install half
```
**NOTE:** use the right package-management utility - `zypper`/`yum`

+ Install from source

```
wget https://sourceforge.net/projects/half/files/half/1.12.0/half-1.12.0.zip
unzip half-1.12.0.zip -d half-files
sudo mkdir /usr/local/include/half
sudo cp half-files/include/half.hpp /usr/local/include/half
```

* Compiler with support for C++ Version `17` and above

* OpenMP

* Threads

## Prerequisites for Test Suite

Expand Down
60 changes: 60 additions & 0 deletions cmake/FindHALF.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
################################################################################
#
# MIT License
#
# Copyright (c) 2023 Advanced Micro Devices, Inc.
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
#
################################################################################
find_path(HALF_INCLUDE_DIRS
NAMES half/half.hpp
HINTS
$ENV{HALF_DIR}/include
$ENV{ROCM_PATH}/include
PATHS
${HALF_DIR}/include
/usr/include
/usr/local/include
${ROCM_PATH}/include
)
mark_as_advanced(HALF_INCLUDE_DIRS)

if(HALF_INCLUDE_DIRS)
set(HALF_FOUND TRUE)
endif( )

include( FindPackageHandleStandardArgs )
find_package_handle_standard_args( HALF
FOUND_VAR HALF_FOUND
REQUIRED_VARS
HALF_INCLUDE_DIRS
)

set(HALF_FOUND ${HALF_FOUND} CACHE INTERNAL "")
set(HALF_INCLUDE_DIRS ${HALF_INCLUDE_DIRS} CACHE INTERNAL "")

if(HALF_FOUND)
message("-- ${White}Using HALF -- \n\tIncludes:${HALF_INCLUDE_DIRS}${ColourReset}")
else()
if(HALF_FIND_REQUIRED)
message(FATAL_ERROR "{Red}FindHALF -- NOT FOUND${ColourReset}")
endif()
message( "-- ${Yellow}NOTE: FindHALF failed to find -- half.hpp${ColourReset}" )
endif()

0 comments on commit 9e857cb

Please sign in to comment.