Commit 16e82f54 authored by Cianciosa, Mark's avatar Cianciosa, Mark
Browse files

Add support for in memort clang compile of CPU kernels.

parent 9a312f12
Loading
Loading
Loading
Loading
+38 −8
Original line number Diff line number Diff line
@@ -1350,11 +1350,11 @@
				GCC_WARN_UNUSED_VARIABLE = YES;
				HEADER_SEARCH_PATHS = (
					/usr/local/include,
					LLVM/clang/include,
					LLVM/llvm/include,
				);
				LIBRARY_SEARCH_PATHS = (
					/usr/local/lib,
					"build/_deps/llvm-build/lib",
					/usr/local/lib,
				);
				MACOSX_DEPLOYMENT_TARGET = 14.0;
				MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
@@ -1367,13 +1367,28 @@
					"-rpath",
					/usr/local/lib,
					"-lLLVM",
					"-lclangFrontend",
					"-lclangBasic",
					"-lclangEdit",
					"-lclangLex",
					"-lclangDriver",
					"-lclangSerialization",
					"-lclangAST",
					"-lclangSema",
					"-lclangAnalysis",
					"-lclangASTMatchers",
					"-lclangSupport",
					"-lclangParse",
					"-lclangAPINotes",
					"-lclangCodeGen",
				);
				SDKROOT = macosx;
				SYSTEM_HEADER_SEARCH_PATHS = "";
				USER_HEADER_SEARCH_PATHS = (
					LLVM/clang/include,
					LLVM/llvm/include,
					"build/_deps/llvm-build/tools/clang/include",
					"build/_deps/llvm-build/include",
					LLVM/clang/include,
					"build/_deps/llvm-build/tools/clang/include",
				);
			};
			name = Debug;
@@ -1435,11 +1450,11 @@
				GCC_WARN_UNUSED_VARIABLE = YES;
				HEADER_SEARCH_PATHS = (
					/usr/local/include,
					LLVM/clang/include,
					LLVM/llvm/include,
				);
				LIBRARY_SEARCH_PATHS = (
					/usr/local/lib,
					"build/_deps/llvm-build/lib",
					/usr/local/lib,
				);
				MACOSX_DEPLOYMENT_TARGET = 14.0;
				MTL_ENABLE_DEBUG_INFO = NO;
@@ -1452,13 +1467,28 @@
					"-rpath",
					/usr/local/lib,
					"-lLLVM",
					"-lclangFrontend",
					"-lclangBasic",
					"-lclangEdit",
					"-lclangLex",
					"-lclangDriver",
					"-lclangSerialization",
					"-lclangAST",
					"-lclangSema",
					"-lclangAnalysis",
					"-lclangASTMatchers",
					"-lclangSupport",
					"-lclangParse",
					"-lclangAPINotes",
					"-lclangCodeGen",
				);
				SDKROOT = macosx;
				SYSTEM_HEADER_SEARCH_PATHS = "";
				USER_HEADER_SEARCH_PATHS = (
					LLVM/clang/include,
					LLVM/llvm/include,
					"build/_deps/llvm-build/tools/clang/include",
					"build/_deps/llvm-build/include",
					LLVM/clang/include,
					"build/_deps/llvm-build/tools/clang/include",
				);
			};
			name = Release;
+1 −3
Original line number Diff line number Diff line
@@ -7,10 +7,8 @@ target_compile_features (rays
)
target_compile_definitions (rays
                            INTERFACE
                            $<$<PLATFORM_ID:Darwin>:CXX_ARGS="-I${CMAKE_OSX_SYSROOT}/usr/include/c++/v1 -I${CMAKE_OSX_SYSROOT}/../../../../../Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/15.0.0/include -I${CMAKE_OSX_SYSROOT}/usr/include -I${CMAKE_CURRENT_SOURCE_DIR} -fgnuc-version=4.2.1"> #-std=gnu++2a>
                            $<$<PLATFORM_ID:Darwin>:CXX_FLAGS="">#"-g">
                            $<$<PLATFORM_ID:Darwin>:CXX_ARGS="-I${CMAKE_OSX_SYSROOT}/usr/include/c++/v1 -I${CMAKE_OSX_SYSROOT}/../../../../../Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/15.0.0/include -I${CMAKE_OSX_SYSROOT}/usr/include -I${CMAKE_CURRENT_SOURCE_DIR} -fgnuc-version=4.2.1 -std=gnu++2a">
                            $<$<PLATFORM_ID:Linux>:CXX_ARGS="${CMAKE_CXX_COMPILER} -I${CMAKE_CURRENT_SOURCE_DIR} -std=gnu++2a -fPIC -fno-use-cxa-atexit">
                            $<$<PLATFORM_ID:Linux>:CXX_FLAGS="-g">
                            EFIT_FILE="${CMAKE_CURRENT_SOURCE_DIR}/../graph_tests/efit.nc"
                            VMEC_FILE="${CMAKE_CURRENT_SOURCE_DIR}/../graph_tests/vmec.nc"
                            $<$<BOOL:${USE_CUDA}>:HEADER_DIR="$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>">
+20 −28
Original line number Diff line number Diff line
@@ -13,6 +13,9 @@
#include <cstring>
#include <thread>

//  Clang headers will define IBAction and IBOutlet these so undefine them here.
#undef IBAction
#undef IBOutlet
#include "clang/Frontend/TextDiagnosticPrinter.h"
#include "clang/Frontend/CompilerInvocation.h"
#include "clang/Frontend/CompilerInstance.h"
@@ -39,17 +42,14 @@ namespace gpu {
///  @param[in] string Input string.
///  @returns The string split into an array of arguments.
//------------------------------------------------------------------------------
    std::vector<const std::string> split_string(const std::string &string) {
        std::vector<const std::string> args;
    std::vector<const char *> split_string(std::string &string) {
        std::vector<const char *> args = {string.data()};

        size_t end_position = string.find(" ");
        args.push_back(string.substr(0, end_position));

        while (end_position < string.size()) {
            const size_t start_position = end_position + 1;
            end_position = string.find(" ", start_position);
            args.push_back(string.substr(start_position, 
                                         end_position - start_position));
            string[end_position] = '\0';
            args.push_back(string.data() + end_position + 1);
            end_position = string.find(" ");
        }

        return args;
@@ -121,32 +121,24 @@ namespace gpu {

            const std::string filename = temp_stream.str();

            temp_stream.str(std::string());
            temp_stream.clear();

            temp_stream.str(std::string());
            temp_stream.clear();

            temp_stream  << filename << " " << CXX_ARGS;
#ifndef NDEBUG
            temp_stream << " " << CXX_FLAGS;
#else
            temp_stream << " -O3";
#endif

            if (jit::verbose) {
                std::cout << "CPU info." << std::endl;
                std::cout << "  Command Line    : " << std::endl;
            }

            std::vector<const std::string> args = split_string(temp_stream.str());
            std::vector<const char *> args_c;
            std::string temp_string = CXX_ARGS;
            std::vector<const char *> args = split_string(temp_string);
            args.push_back(filename.c_str());
#ifndef NDEBUG
            args.push_back("-g");
#else
            args.push_back("-O3");
#endif
            //if (jit::verbose) {
                for (auto &arg : args) {
                if (jit::verbose) {
                    std::cout << "    " << arg << std::endl;
                }
                args_c.push_back(arg.c_str());
            }
            //}

            llvm::IntrusiveRefCntPtr<clang::DiagnosticOptions> diagnostic_options;
            auto diagnostic_printer = std::make_unique<clang::TextDiagnosticPrinter> (llvm::errs(),
@@ -158,7 +150,7 @@ namespace gpu {
                                                       diagnostic_printer.release());

            auto invocation = std::make_shared<clang::CompilerInvocation> ();
            clang::CompilerInvocation::CreateFromArgs(*(invocation.get()), args_c,
            clang::CompilerInvocation::CreateFromArgs(*(invocation.get()), args,
                                                      diagnostic_engine);

            llvm::StringRef source_code_data(kernel_source);