Skip to content

Commit

Permalink
Merge pull request #265 from hvdijk/hardware-sqrt
Browse files Browse the repository at this point in the history
Use @llvm.sqrt.* intrincs rather than rolling our own.
  • Loading branch information
hvdijk authored Dec 18, 2023
2 parents 58eeee1 + 81157ba commit 51b4ae8
Show file tree
Hide file tree
Showing 15 changed files with 455 additions and 469 deletions.

This file was deleted.

29 changes: 29 additions & 0 deletions modules/compiler/builtins/abacus/include/abacus/internal/sqrt.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright (C) Codeplay Software Limited
//
// Licensed under the Apache License, Version 2.0 (the "License") with LLVM
// Exceptions; you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://github.com/codeplaysoftware/oneapi-construction-kit/blob/main/LICENSE.txt
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
// License for the specific language governing permissions and limitations
// under the License.
//
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

#ifndef __ABACUS_INTERNAL_SQRT_H__
#define __ABACUS_INTERNAL_SQRT_H__

#include <abacus/abacus_config.h>

namespace abacus {
namespace internal {
template <typename T>
T sqrt(T);
} // namespace internal
} // namespace abacus

#endif //__ABACUS_INTERNAL_SQRT_H__
156 changes: 0 additions & 156 deletions modules/compiler/builtins/abacus/include/abacus/internal/sqrt_unsafe.h

This file was deleted.

87 changes: 63 additions & 24 deletions modules/compiler/builtins/abacus/source/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,24 @@ add_subdirectory(abacus_memory)
add_subdirectory(abacus_misc)
add_subdirectory(abacus_relational)

set(abacus_sources
set(abacus_sources_host
${abacus_cast_sources} ${abacus_common_sources} ${abacus_extra_sources}
${abacus_geometric_sources} ${abacus_integer_sources} ${abacus_math_sources}
${abacus_geometric_sources} ${abacus_integer_sources} ${abacus_math_sources_host}
${abacus_memory_sources} ${abacus_misc_sources} ${abacus_relational_sources})
set(abacus_sources_device
${abacus_cast_sources} ${abacus_common_sources} ${abacus_extra_sources}
${abacus_geometric_sources} ${abacus_integer_sources} ${abacus_math_sources_device}
${abacus_memory_sources} ${abacus_misc_sources} ${abacus_relational_sources})

add_library(abacus_static STATIC ${abacus_sources})
add_library(abacus_static STATIC ${abacus_sources_host})
add_dependencies(abacus_static abacus_generate)
target_compile_definitions(abacus_static PRIVATE
"ABACUS_ENABLE_OPENCL_1_2_BUILTINS"
"ABACUS_ENABLE_OPENCL_3_0_BUILTINS")

# If extra ComputeAorta commands exist, use them.
if(COMMAND add_ca_tidy)
add_ca_tidy(abacus_static ${abacus_sources})
add_ca_tidy(abacus_static ${abacus_sources_host})
if(TARGET tidy-abacus_static)
add_dependencies(tidy-abacus_static abacus_generate)
endif()
Expand Down Expand Up @@ -157,15 +161,32 @@ if(${ABACUS_BUILD_WITH_RUNTIME_TOOLS})
set(cap_suf "${cap_suf}_fp16")
endif()

foreach(SOURCE IN LISTS abacus_sources)
string(LENGTH "${CMAKE_CURRENT_SOURCE_DIR}/" LENGTH)
string(SUBSTRING "${SOURCE}" ${LENGTH} -1 SUB_SOURCE)
string(REGEX REPLACE "^.*\\.\(c[lp]*\)$" "\\1" SOURCE_TYPE "${SOURCE}")
foreach(SOURCE IN LISTS abacus_sources_device)
file(RELATIVE_PATH RELSOURCE "${CMAKE_CURRENT_SOURCE_DIR}" "${SOURCE}")
get_filename_component(SOURCE_DIR "${RELSOURCE}" DIRECTORY)
get_filename_component(SOURCE_NAME "${SOURCE}" NAME)
get_filename_component(SOURCE_TYPE "${SOURCE}" LAST_EXT)
if(SOURCE_TYPE STREQUAL ".in")
if("${triple}" STREQUAL spir64-unknown-unknown)
set(target "\
target triple = \"spir64-unknown-unknown\"\n\
target datalayout = \"e-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024\"")
elseif("${triple}" STREQUAL spir-unknown-unknown)
set(target "\
target triple = \"spir-unknown-unknown\"\n\
target datalayout = \"e-p:32:32-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024\"")
else()
message(FATAL_ERROR "Missing target definition for target '${triple}'")
endif()
get_filename_component(SOURCE_NAME "${SOURCE}" NAME_WLE)
configure_file(${SOURCE} "${CMAKE_CURRENT_BINARY_DIR}/bc/${triple}${cap_suf}/${SOURCE_DIR}/${SOURCE_NAME}" @ONLY)
set(SOURCE "${CMAKE_CURRENT_BINARY_DIR}/bc/${triple}${cap_suf}/${SOURCE_DIR}/${SOURCE_NAME}")
get_filename_component(SOURCE_TYPE "${SOURCE}" LAST_EXT)
endif()

set(XTYPE "${SOURCE_TYPE}") # Language for -x option.
set(XTYPE "") # Language for -x option.
set(XOPTS "") # Extra language specific options.
set(OUTPUT
"${CMAKE_CURRENT_BINARY_DIR}/bc/${triple}${cap_suf}/${SUB_SOURCE}.bc")
set(OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/bc/${triple}${cap_suf}/${SOURCE_DIR}/${SOURCE_NAME}.bc")

# The 'Unix Makefiles' and 'MinGW Makefiles' generators do not
# automatically create the output directories the bc files are output to,
Expand All @@ -176,28 +197,46 @@ if(${ABACUS_BUILD_WITH_RUNTIME_TOOLS})
file(MAKE_DIRECTORY ${OUTPUT_DIR})
endif()

if("${SOURCE_TYPE}" STREQUAL "cpp")
set(DEPFILE_ARGS -dependency-file "${OUTPUT}.d" -MT "${OUTPUT}" -sys-header-deps)
if(SOURCE_TYPE STREQUAL ".cpp")
set(XTYPE "c++")
set(XOPTS "-std=c++11")
elseif("${SOURCE_TYPE}" STREQUAL "cl")
elseif(SOURCE_TYPE STREQUAL ".cl")
set(XTYPE "cl")
set(XOPTS "-cl-std=CL1.2")
elseif(SOURCE_TYPE STREQUAL ".ll")
set(XTYPE "ir")
set(DEPFILE_ARGS)
else()
message(FATAL_ERROR "Missing handling for source type '${SOURCE_TYPE}'")
endif()

# This is required to correctly expose all the builtins since some of their
# defintions come from this file.
set(ENABLE_OPENCL_BUILTINS
"-DABACUS_ENABLE_OPENCL_1_2_BUILTINS -DABACUS_ENABLE_OPENCL_3_0_BUILTINS")
add_custom_command(
OUTPUT "${OUTPUT}"
COMMAND ${RUNTIME_COMPILER} -cc1 -x ${XTYPE} ${XOPTS} -triple ${triple}
${ABACUS_RUNTIME_OPTIONS} ${BUILTINS_EXTRA_OPTIONS} ${ENABLE_OPENCL_BUILTINS}
-include "${RUNTIME_CLHEADER}"
-emit-llvm-bc -o "${OUTPUT}"
-dependency-file "${OUTPUT}.d" -MT "${OUTPUT}" -sys-header-deps
"${SOURCE}"
DEPENDS "${SOURCE}" "${RUNTIME_COMPILER}" "${RUNTIME_CLHEADER}"
abacus_generate ${ABACUS_GENERATED_FILES}
DEPFILE "${OUTPUT}.d")
if(DEFINED DEPFILE_ARGS)
add_custom_command(
OUTPUT "${OUTPUT}"
COMMAND ${RUNTIME_COMPILER} -cc1 -x ${XTYPE} ${XOPTS} -triple ${triple}
${ABACUS_RUNTIME_OPTIONS} ${BUILTINS_EXTRA_OPTIONS} ${ENABLE_OPENCL_BUILTINS}
-include "${RUNTIME_CLHEADER}"
-emit-llvm-bc -o "${OUTPUT}" ${DEPFILE_ARGS}
"${SOURCE}"
DEPENDS "${SOURCE}" "${RUNTIME_COMPILER}" "${RUNTIME_CLHEADER}"
abacus_generate ${ABACUS_GENERATED_FILES}
DEPFILE "${OUTPUT}.d")
else()
add_custom_command(
OUTPUT "${OUTPUT}"
COMMAND ${RUNTIME_COMPILER} -cc1 -x ${XTYPE} ${XOPTS} -triple ${triple}
${ABACUS_RUNTIME_OPTIONS} ${BUILTINS_EXTRA_OPTIONS} ${ENABLE_OPENCL_BUILTINS}
-include "${RUNTIME_CLHEADER}"
-emit-llvm-bc -o "${OUTPUT}"
"${SOURCE}"
DEPENDS "${SOURCE}" "${RUNTIME_COMPILER}" "${RUNTIME_CLHEADER}"
abacus_generate ${ABACUS_GENERATED_FILES})
endif()

set(ALL_BCS "${ALL_BCS};${OUTPUT}")
endforeach()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,5 +115,10 @@ set(abacus_math_sources
${CMAKE_CURRENT_SOURCE_DIR}/tanh.cpp
${CMAKE_CURRENT_SOURCE_DIR}/tanpi.cpp
${CMAKE_CURRENT_SOURCE_DIR}/tgamma.cpp
${CMAKE_CURRENT_SOURCE_DIR}/trunc.cpp
${CMAKE_CURRENT_SOURCE_DIR}/trunc.cpp)
set(abacus_math_sources_host ${abacus_math_sources}
${CMAKE_CURRENT_SOURCE_DIR}/inplace_sqrt.cpp
PARENT_SCOPE)
set(abacus_math_sources_device ${abacus_math_sources}
${CMAKE_CURRENT_SOURCE_DIR}/inplace_sqrt.ll.in
PARENT_SCOPE)
Loading

0 comments on commit 51b4ae8

Please sign in to comment.