Skip to content

Commit 79ace09

Browse files
committed
cmake is woking nicely but the dispatch plugins fail due to llvm bug
1 parent c1f580e commit 79ace09

File tree

13 files changed

+67
-312
lines changed

13 files changed

+67
-312
lines changed

CMakeLists.txt

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,33 +9,30 @@ option(VERBOSE "Verbose runtime logs" OFF)
99
option(DEBUG "Build with debug symbols" OFF)
1010
option(BUILD_PLUGINS "Build Clang/LLVM plugins" ON)
1111
option(BUILD_TESTS "Build test executables" ON)
12-
option(BUILD_PYBIND "Build Python bindings" ON)
12+
option(BUILD_PYBIND "Build Python bindings" OFF)
1313

1414
set(CMAKE_CXX_STANDARD 17)
1515
set(CMAKE_CXX_STANDARD_REQUIRED ON)
1616
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
1717

1818
message(STATUS "Detecting architecture...")
1919

20+
# ─────────────────────────────── Architecture detection ───────────────────────────────
2021
if (CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64|AMD64")
2122
message(STATUS "→ Building for x86_64 (AVX/AVX2/AVX512 enabled)")
2223
add_compile_definitions(TENSORIUM_X86)
2324
add_compile_options(-mavx2 -mfma)
2425
elseif (CMAKE_SYSTEM_PROCESSOR MATCHES "arm64|aarch64")
2526
message(STATUS "→ Building for ARM64 / Apple Silicon (NEON enabled)")
2627
add_compile_definitions(TENSORIUM_ARM)
27-
find_package(OpenMP)
28-
if (OpenMP_CXX_FOUND)
29-
target_link_libraries(${PROJECT_NAME} PUBLIC OpenMP::OpenMP_CXX)
30-
endif()
3128
else()
3229
message(WARNING "→ Unknown architecture: ${CMAKE_SYSTEM_PROCESSOR}, using scalar fallback.")
3330
add_compile_definitions(TENSORIUM_FALLBACK)
3431
endif()
35-
# ─────────────────────────────── Includes ──────────────────────────────
32+
3633
include_directories(${CMAKE_SOURCE_DIR}/Includes)
3734

38-
# ─────────────────────────────── CPU architecture flags ───────────────────────────────
35+
# ─────────────────────────────── CPU optimization flags ───────────────────────────────
3936
if(CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64" OR CMAKE_SYSTEM_PROCESSOR MATCHES "amd64")
4037
message(STATUS "Configuring for x86_64: enabling AVX2/FMA or AVX512")
4138
set(BASE_FLAGS "-O3 -mtune=native -Wno-ignored-attributes -Rpass-analysis=tensorium-align")
@@ -46,7 +43,6 @@ if(CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64" OR CMAKE_SYSTEM_PROCESSOR MATCHES "am
4643
else()
4744
set(CMAKE_CXX_FLAGS "${BASE_FLAGS} ${AVX2_FLAGS}")
4845
endif()
49-
5046
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "arm64" OR CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64")
5147
message(STATUS "Configuring for Apple Silicon ARM64: disabling AVX flags")
5248
set(CMAKE_CXX_FLAGS "-O3 -mcpu=apple-m1 -Wno-ignored-attributes")
@@ -62,9 +58,6 @@ if(VERBOSE)
6258
add_compile_definitions(VERBOSE)
6359
endif()
6460

65-
66-
67-
# ─────────────────────────────── Architecture detection ───────────────────────────────
6861
message(STATUS "Detected architecture: ${CMAKE_SYSTEM_PROCESSOR}")
6962

7063
# ─────────────────────────────── OpenMP handling ───────────────────────────────
@@ -88,15 +81,12 @@ else()
8881
endif()
8982
endif()
9083

91-
# ─────────────────────────────── Subdirectories ───────────────────────────────
84+
# ─────────────────────────────── Plugins ───────────────────────────────
9285
if(BUILD_PLUGINS)
9386
add_subdirectory(Plugins)
9487
endif()
9588

89+
# ─────────────────────────────── Tests ───────────────────────────────
9690
if(BUILD_TESTS)
9791
add_subdirectory(Tests)
9892
endif()
99-
100-
if(BUILD_PYBIND)
101-
add_subdirectory(Pybind)
102-
endif()

Makefile

Lines changed: 0 additions & 147 deletions
This file was deleted.

Plugins/CMakeLists.txt

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,22 @@ find_package(LLVM REQUIRED CONFIG)
22
include_directories(${LLVM_INCLUDE_DIRS})
33
add_definitions(${LLVM_DEFINITIONS})
44

5-
# AST plugin
5+
# List of components to map to libraries
6+
set(LLVM_COMPONENTS
7+
Core
8+
Support
9+
IRReader
10+
Analysis
11+
Passes
12+
TransformUtils
13+
)
14+
15+
llvm_map_components_to_libnames(LLVM_LIBS ${LLVM_COMPONENTS})
16+
17+
# Tensorium Dispatch Plugin (Clang AST)
618
add_library(TensoriumDispatchPlugin SHARED TensoriumDispatchPlugin.cpp)
7-
target_link_libraries(TensoriumDispatchPlugin PRIVATE clang-cpp LLVM)
8-
set_target_properties(TensoriumDispatchPlugin PROPERTIES COMPILE_FLAGS "")
19+
target_link_libraries(TensoriumDispatchPlugin PRIVATE clang-cpp ${LLVM_LIBS})
920

10-
# LLVM IR plugin
21+
# Tensorium LLVM IR Plugin
1122
add_library(TensoriumLLVM_IRCheck SHARED TensoriumLLVM_IRCheck.cpp)
12-
target_link_libraries(TensoriumLLVM_IRCheck PRIVATE LLVM)
13-
set_target_properties(TensoriumLLVM_IRCheck PROPERTIES COMPILE_FLAGS "")
23+
target_link_libraries(TensoriumLLVM_IRCheck PRIVATE ${LLVM_LIBS})

Plugins/TensoriumDispatchPlugin.cpp

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@
66
#include "clang/Lex/Preprocessor.h"
77
#include "clang/Tooling/Tooling.h"
88
#include "llvm/Support/MemoryBuffer.h"
9+
#include <iostream>
10+
//
11+
// static int _ = []() {
12+
// std::cerr << "[TensoriumDispatchPlugin] Plugin loaded into Clang.\n";
13+
// return 0;
14+
// }();
915
// #include "LLVM_Handler.hpp"
1016
/**
1117
* @file TensoriumPlugin.cpp
@@ -59,7 +65,8 @@ class TensoriumASTConsumer : public ASTConsumer {
5965
// SourceLocation loc = FD->getBeginLoc();
6066
// for (const auto &entry : TensoriumTargetTable) {
6167
// if (Context.getSourceManager().isBeforeInTranslationUnit(entry.loc,
62-
// loc)) { std::string fname = FD->getNameAsString(); llvm::errs() << "[tensorium] Target("
68+
// loc)) { std::string fname = FD->getNameAsString();
69+
// llvm::errs() << "[tensorium] Target("
6370
// << entry.platform << ", " << entry.isa
6471
// << ") applies to function " << fname << "\n";
6572
//
@@ -300,6 +307,16 @@ class TensoriumPluginAction : public PluginASTAction {
300307

301308
} // namespace
302309

303-
/// @brief Register the plugin under the name "tensorium-dispatch"
304-
static FrontendPluginRegistry::Add<TensoriumPluginAction> X("tensorium-dispatch",
305-
"Handle #pragma tensorium directives");
310+
// @brief Register the plugin under the name "tensorium-dispatch"
311+
// Important: we avoid double-free issues by wrapping in a ManagedStatic,
312+
313+
#include "clang/Frontend/FrontendPluginRegistry.h"
314+
315+
//
316+
317+
using clang::FrontendPluginRegistry;
318+
319+
static FrontendPluginRegistry::Add<TensoriumPluginAction>
320+
X("tensorium-dispatch", "Handle #pragma tensorium directives");
321+
322+

Pybind/bindings.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
#include "Tensorium/Tensorium.hpp"
1+
#include "../includes/Tensorium/Tensorium.hpp"
22
#include <iostream>
3-
#include <omp.h>
3+
// #include <omp.h>
44
#include <pybind11/numpy.h>
55
#include <pybind11/pybind11.h>
66
#include <pybind11/stl.h>

Tests/CMakeLists.txt

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
file(GLOB TEST_SOURCES
32
${CMAKE_CURRENT_SOURCE_DIR}/*.cpp
43
${CMAKE_CURRENT_SOURCE_DIR}/Matrix/*.cpp
@@ -10,7 +9,7 @@ file(GLOB TEST_SOURCES
109

1110
add_executable(TensoriumTests ${TEST_SOURCES})
1211

13-
# --- OpenMP flags selon architecture ---
12+
# ─────────────────────────────── OpenMP flags ───────────────────────────────
1413
if(APPLE AND CMAKE_SYSTEM_PROCESSOR MATCHES "arm64")
1514
include_directories(${OPENMP_INCLUDE_PATH})
1615
link_directories(${OPENMP_LIB_PATH})
@@ -20,7 +19,7 @@ elseif(DEFINED OPENMP_LIB)
2019
target_link_libraries(TensoriumTests PRIVATE ${OPENMP_LIB})
2120
endif()
2221

23-
# --- MPI / KNL ---
22+
# ─────────────────────────────── MPI / KNL options ───────────────────────────────
2423
if(USE_MPI)
2524
find_package(MPI REQUIRED)
2625
target_link_libraries(TensoriumTests PRIVATE MPI::MPI_CXX)
@@ -33,3 +32,12 @@ if(USE_KNL)
3332
target_link_libraries(TensoriumTests PRIVATE memkind)
3433
endif()
3534

35+
# # ─────────────────────────────── Inject the plugins ───────────────────────────────
36+
# set(DISPATCH_PLUGIN_PATH "${CMAKE_BINARY_DIR}/Plugins/libTensoriumDispatchPlugin.so")
37+
#
38+
# add_dependencies(TensoriumTests TensoriumDispatchPlugin)
39+
#
40+
# # inject the clang plugin (frontend)
41+
# set_property(TARGET TensoriumTests APPEND_STRING PROPERTY COMPILE_FLAGS
42+
# " -Xclang -load -Xclang ${DISPATCH_PLUGIN_PATH} -Xclang -add-plugin -Xclang tensorium-dispatch"
43+
# )

Tests/Matrix/Matrix.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ tensorium::Matrix<K> mul_mat_reference(const tensorium::Matrix<K>& A, const tens
3131
}
3232
int matrix_bench() {
3333
using namespace tensorium;
34-
std::vector<std::size_t> sizes = {256};
34+
std::vector<std::size_t> sizes = {8192};
3535

3636
for (std::size_t N : sizes) {
3737
Matrix<double> A(N, N);

Tests/test.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#include <cstdlib>
1010
#include <cstring>
1111
#include <algorithm>
12-
#include <omp.h>
12+
// #include <omp.h>
1313
#include <iomanip>
1414
#include <random>
1515

build_linux.sh

Lines changed: 0 additions & 20 deletions
This file was deleted.

0 commit comments

Comments
 (0)