Skip to content

Commit

Permalink
xe: jit: gemm: remove mixing of oneDNN and gemmstone code
Browse files Browse the repository at this point in the history
As a side-effect, also enables targeting an out-of-tree gemmstone by setting
ONEDNN_GEMMSTONE_DIR.
  • Loading branch information
rjoursler committed Jan 9, 2025
1 parent 8b017b0 commit a258080
Show file tree
Hide file tree
Showing 102 changed files with 100 additions and 65 deletions.
4 changes: 3 additions & 1 deletion src/gpu/intel/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#===============================================================================
# Copyright 2024 Intel Corporation
# Copyright 2024-2025 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -25,6 +25,8 @@ file(GLOB SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/*.cpp
)

set(ONEDNN_GEMMSTONE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/jit/gemm/gemmstone" CACHE PATH "Path to gemmstone source code")

add_definitions_with_host_compiler(-DNGEN_CPP11)
add_definitions_with_host_compiler(-DNGEN_SAFE)
add_definitions_with_host_compiler(-DNGEN_NEO_INTERFACE)
Expand Down
49 changes: 5 additions & 44 deletions src/gpu/intel/jit/gemm/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#===============================================================================
# Copyright 2024 Intel Corporation
# Copyright 2024-2025 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -19,57 +19,18 @@ if(CMAKE_CXX_COMPILER_ID STREQUAL "IntelLLVM" OR CMAKE_CXX_COMPILER_ID MATCHES "
append(CMAKE_CXX_FLAGS " -Wno-implicit-int-conversion")
endif()

set(DIRS "generator;generator/pieces;selector")
add_subdirectory(${ONEDNN_GEMMSTONE_DIR} gemmstone)
set_property(GLOBAL APPEND PROPERTY DNNL_LIB_DEPS
${GEMMSTONE_LIBRARY_NAME})

file(GLOB SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/*.hpp
${CMAKE_CURRENT_SOURCE_DIR}/*.cpp
)
foreach(d ${DIRS})
file(GLOB_RECURSE d_sources
${CMAKE_CURRENT_SOURCE_DIR}/${d}/*.hpp
${CMAKE_CURRENT_SOURCE_DIR}/${d}/*.cpp
)
list(APPEND SOURCES "${d_sources}")
endforeach()

# There is no easy way to emulate target_compile_definitions() with the dpcpp
# host compiler arguments. As such, we cannot split compilation of the generator
# templates by using defines.
if(DPCPP_HOST_COMPILER_KIND STREQUAL "DEFAULT")
list(REMOVE_ITEM SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/generator/generator.cpp)

file (GLOB GENERATOR_SOURCES
generator/generator.cpp
)

if (DNNL_ENABLE_PRIMITIVE_GPU_ISA STREQUAL "ALL")
set(DNNL_GPU_ISA_LIST "GEN9;GEN11;XELP;XEHP;XEHPG;XEHPC;XE2;XE3")
else()
foreach(isa ${DNNL_ENABLE_PRIMITIVE_GPU_ISA})
string(TOUPPER ${isa} ISA)
set(DNNL_GPU_ISA_LIST "${DNNL_GPU_ISA_LIST};${ISA}")
endforeach()
endif()

foreach(isa ${DNNL_GPU_ISA_LIST})
set(GENERATOR_LIB generator${isa})
add_library(${GENERATOR_LIB} OBJECT ${GENERATOR_SOURCES})
target_compile_definitions(${GENERATOR_LIB} PRIVATE DNNL_GPU_ISA_${isa})
set_property(GLOBAL APPEND PROPERTY DNNL_LIB_DEPS
$<TARGET_OBJECTS:${GENERATOR_LIB}>)
endforeach()
endif()
include_directories(${OBJ_LIB} ${ONEDNN_GEMMSTONE_DIR}/.. ${ONEDNN_GEMMSTONE_DIR} ${ONEDNN_GEMMSTONE_DIR}/include)

set(OBJ_LIB ${LIB_PACKAGE_NAME}_gpu_intel_jit_gemm)
add_library(${OBJ_LIB} OBJECT ${SOURCES})
set_property(GLOBAL APPEND PROPERTY DNNL_LIB_DEPS
$<TARGET_OBJECTS:${OBJ_LIB}>)

include_directories_with_host_compiler_before(${OBJ_LIB} ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/include ${CMAKE_CURRENT_SOURCE_DIR}/../ngen)

# Workaround for LTO bug in GCC 10, 11, 12 (possibly other versions)
if(CMAKE_COMPILER_IS_GNUCC)
set_source_files_properties(generator/pieces/loop_sequencer.cpp PROPERTIES COMPILE_FLAGS -fno-lto)
set_source_files_properties(generator/generator.cpp PROPERTIES COMPILE_FLAGS -fno-lto)
endif()
69 changes: 69 additions & 0 deletions src/gpu/intel/jit/gemm/gemmstone/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#===============================================================================
# Copyright 2024-2025 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# 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.
#===============================================================================

# TODO: Extend conversion warning support to GEMM code
if(CMAKE_CXX_COMPILER_ID STREQUAL "IntelLLVM" OR CMAKE_CXX_COMPILER_ID MATCHES "(Apple)?[Cc]lang")
append(CMAKE_CXX_FLAGS " -Wno-implicit-int-conversion")
endif()

set(DIRS "generator;generator/pieces;selector")

foreach(d ${DIRS})
file(GLOB_RECURSE d_sources
${CMAKE_CURRENT_SOURCE_DIR}/${d}/*.hpp
${CMAKE_CURRENT_SOURCE_DIR}/${d}/*.cpp
)
list(APPEND GEMMSTONE_SOURCES "${d_sources}")
endforeach()

# There is no easy way to emulate target_compile_definitions() with the dpcpp
# host compiler arguments. As such, we cannot split compilation of the generator
# templates by using defines.
if(DPCPP_HOST_COMPILER_KIND STREQUAL "DEFAULT")
list(REMOVE_ITEM GEMMSTONE_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/generator/generator.cpp)

file (GLOB GENERATOR_SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/generator/generator.cpp
)

if (DNNL_ENABLE_PRIMITIVE_GPU_ISA STREQUAL "ALL")
set(DNNL_GPU_ISA_LIST "GEN9;GEN11;XELP;XEHP;XEHPG;XEHPC;XE2;XE3")
else()
foreach(isa ${DNNL_ENABLE_PRIMITIVE_GPU_ISA})
string(TOUPPER ${isa} ISA)
set(DNNL_GPU_ISA_LIST "${DNNL_GPU_ISA_LIST};${ISA}")
endforeach()
endif()

foreach(isa ${DNNL_GPU_ISA_LIST})
set(GENERATOR_LIB generator${isa})
add_library(${GENERATOR_LIB} OBJECT ${GENERATOR_SOURCES})
target_compile_definitions(${GENERATOR_LIB} PRIVATE DNNL_GPU_ISA_${isa})
set_property(GLOBAL APPEND PROPERTY DNNL_LIB_DEPS
$<TARGET_OBJECTS:${GENERATOR_LIB}>)
endforeach()
endif()

set(GEMMSTONE_LIBRARY_NAME ${LIB_PACKAGE_NAME}_gpu_intel_jit_gemmstone)
add_library(${GEMMSTONE_LIBRARY_NAME} OBJECT ${GEMMSTONE_SOURCES})

include_directories(${GEMMSTONE_LIBRARY_NAME} ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/include)

# Workaround for LTO bug in GCC 10, 11, 12 (possibly other versions)
if(CMAKE_COMPILER_IS_GNUCC)
set_source_files_properties(generator/pieces/loop_sequencer.cpp PROPERTIES COMPILE_FLAGS -fno-lto)
set_source_files_properties(generator/generator.cpp PROPERTIES COMPILE_FLAGS -fno-lto)
endif()
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright 2024 Intel Corporation
* Copyright 2024-2025 Intel Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -20,7 +20,6 @@
#include "generator.hpp"
#include "kernel_selector.hpp"
#include "strategy_parser.hpp"
#include "npack/neo_packager.hpp"

#include "internal/namespace_start.hxx"

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright 2019-2024 Intel Corporation
* Copyright 2019-2025 Intel Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -18,3 +18,4 @@

# include "gpu/intel/jit/ngen/ngen_opencl.hpp"
# include "gpu/intel/jit/ngen/ngen_register_allocator.hpp"
# include "gpu/intel/jit/ngen/npack/neo_packager.hpp"
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions src/gpu/intel/jit/gemm/gen_gemm.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright 2019-2024 Intel Corporation
* Copyright 2019-2025 Intel Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -22,7 +22,7 @@
#include "common/type_helpers.hpp"
#include "gpu/intel/compute/utils.hpp"
#include "gpu/intel/jit/gemm/gemm_walk_orders.hpp"
#include "gpu/intel/jit/gemm/include/driver_info.hpp"
#include "gemmstone/include/driver_info.hpp"

namespace dnnl {
namespace impl {
Expand Down
4 changes: 2 additions & 2 deletions src/gpu/intel/jit/gemm/gen_gemm_kernel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
#include "gpu/intel/jit/gemm/gen_gemm_kernel.hpp"
#include "common/impl_registration.hpp"
#include "gpu/intel/compute/device_info.hpp"
#include "gpu/intel/jit/gemm/include/generator.hpp"
#include "gpu/intel/jit/gemm/include/strategy_parser.hpp"
#include "gemmstone/include/generator.hpp"
#include "gemmstone/include/strategy_parser.hpp"
#include "gpu/intel/jit/utils/ngen_type_bridge.hpp"
#include "gpu/intel/utils.hpp"

Expand Down
14 changes: 7 additions & 7 deletions src/gpu/intel/jit/gemm/gen_gemm_kernel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@
#include "common/c_types_map.hpp"
#include "gpu/intel/compute/device_info.hpp"
#include "gpu/intel/compute/kernel_arg_list.hpp"
#include "gpu/intel/jit/gemm/include/driver_info.hpp"
#include "gpu/intel/jit/gemm/include/kernel_catalog.hpp"
#include "gpu/intel/jit/gemm/include/kernel_evaluator.hpp"
#include "gpu/intel/jit/gemm/include/kernel_selector.hpp"
#include "gpu/intel/jit/gemm/include/problem.hpp"
#include "gpu/intel/jit/gemm/include/strategy.hpp"
#include "gpu/intel/jit/gemm/include/type.hpp"
#include "gemmstone/include/driver_info.hpp"
#include "gemmstone/include/kernel_catalog.hpp"
#include "gemmstone/include/kernel_evaluator.hpp"
#include "gemmstone/include/kernel_selector.hpp"
#include "gemmstone/include/problem.hpp"
#include "gemmstone/include/strategy.hpp"
#include "gemmstone/include/type.hpp"
#include "gpu/intel/jit/jit_generator_base.hpp"
#include "gpu/intel/kernel_cache.hpp"
#include "xpu/utils.hpp"
Expand Down
2 changes: 1 addition & 1 deletion src/gpu/intel/jit/gemm/jit_gemm_pd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*******************************************************************************/

#include "gpu/intel/jit/gemm/jit_gemm_pd.hpp"
#include "gpu/intel/jit/gemm/include/generator.hpp"
#include "gemmstone/include/generator.hpp"

namespace dnnl {
namespace impl {
Expand Down
6 changes: 3 additions & 3 deletions src/gpu/intel/jit/gemm/xe_hp_systolic_gemm.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright 2019-2024 Intel Corporation
* Copyright 2019-2025 Intel Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -25,8 +25,8 @@
#include "common/memory_storage.hpp"
#include "common/utils.hpp"
#include "gpu/intel/gemm/gpu_gemm.hpp"
#include "gpu/intel/jit/gemm/include/driver_info.hpp"
#include "gpu/intel/jit/gemm/include/problem.hpp"
#include "gemmstone/include/driver_info.hpp"
#include "gemmstone/include/problem.hpp"
#include "gpu/intel/jit/gemm/jit_gemm_pd.hpp"

namespace dnnl {
Expand Down
5 changes: 4 additions & 1 deletion src/gpu/intel/ocl/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#===============================================================================
# Copyright 2019-2024 Intel Corporation
# Copyright 2019-2025 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -37,6 +37,9 @@ gen_gpu_kernel_list(

list(APPEND SOURCES ${kernel_list_src})

# Add gemmstone include
include_directories(${OBJ_LIB} ${ONEDNN_GEMMSTONE_DIR}/..)

set(OBJ_LIB ${LIB_PACKAGE_NAME}_gpu_intel_ocl)
add_library(${OBJ_LIB} OBJECT ${SOURCES})
set_property(GLOBAL APPEND PROPERTY DNNL_LIB_DEPS
Expand Down
2 changes: 1 addition & 1 deletion src/gpu/intel/ocl/micro_sdpa.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#include "common/type_helpers.hpp"
#include "gpu/intel/compute/utils.hpp"
#include "gpu/intel/jit/gemm/gen_gemm_kernel.hpp"
#include "gpu/intel/jit/gemm/include/microkernel_provider.hpp"
#include "gemmstone/include/microkernel_provider.hpp"

#include <algorithm>
#include <cstdio>
Expand Down

0 comments on commit a258080

Please sign in to comment.