Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Are there any JIT mode optimizations flags? #1120

Open
ArtemkaKun opened this issue Jun 3, 2024 · 10 comments
Open

Are there any JIT mode optimizations flags? #1120

ArtemkaKun opened this issue Jun 3, 2024 · 10 comments

Comments

@ArtemkaKun
Copy link

ArtemkaKun commented Jun 3, 2024

Hi, I'm trying to compare daScript performance with the performance of my programming language (Spawn) in the Fibonacci example.
daScript's performance info states the following:

daScript Just-in-Time compilation is based on LLVM backend, and often outperforms C++, due to daScript providing more information to LLVM than AOT. 

and provides the following table

image

daScript code I'm benchmarking is the following:

def fibI(n)
    var last = 1
    var cur = 0
    for i in range(n)
        let tmp = cur
        cur += last
        last = tmp
    return cur

[export]
def main
    print("{fibI(6511134)}")

I'm running it with just das fibI.das

Spawn code is the following:

fn main() {
    print('${fib_i(6511134)}')
}

fn fib_i(n u64) -> u64 {
    mut last := 1
    mut cur := 0

    for i in 0 .. n {
        tmp := cur
	cur += last
	last = tmp
    }

    return cur
}

I'm building executable with ./spawnlang --cc clang --opt-fast --show-timings=false -o fib_sp ../fibI.sp

I'm comparing both daScript and Spawn using hyperfine hyperfine -N --warmup 5 "das fibI.das" ../../spawn/fib_sp
The results are the following

Benchmark 1: das fibI.das
Time (mean ± σ):     292.5 ms ±  11.0 ms    [User: 276.2 ms, System: 13.6 ms]
Range (min … max):   275.4 ms … 319.6 ms    10 runs

Benchmark 2: ../../spawn/fib_sp
Time (mean ± σ):       4.5 ms ±   0.6 ms    [User: 3.1 ms, System: 1.1 ms]
Range (min … max):     2.2 ms …   5.9 ms    574 runs

Summary
../../spawn/fib_sp ran
64.72 ± 8.79 times faster than das fibI.das

Am I doing something wrong? Should I add any optimization flags to daScript build command or something? I can't try AOT for now (see #1119), but seems JIT mode of daScript should perform sometimes better than AOT mode, and I have drastically difference in comparison with my compiled programming language that should have similar performance as AOT

I'm on Arch Linux, with lastest GCC and Clang and dev tools

@ArtemkaKun
Copy link
Author

I found options optimize=true in https://spiiin.github.io/blog/2115627465/ and added it on the top of my file, but seems this changed nothing in term of performance

@borisbat
Copy link
Collaborator

borisbat commented Jun 3, 2024

das -jit fibI.das
it runs interpreted otherwise

@ArtemkaKun
Copy link
Author

Hi, thanks for the response. Unfortunately, this doesn't work for me

╰─λ das -jit fibI.das
failed to add extra dependency just_in_time from /home/yuart/Projects/daScript/daslib/just_in_time.das
function 'main' not found

@borisbat
Copy link
Collaborator

borisbat commented Jun 4, 2024

u'r missing dasLLVM submodule

@ArtemkaKun
Copy link
Author

Hmm, when running python modules.py --path ./build --on dasLLVM from the root of the daScript repo folder, I have the following output

🔴] × python modules.py --path ./build --on dasLLVM
/home/yuart/Projects/daScript/modules.py:238: SyntaxWarning: invalid escape sequence '\d'
description='''This is cmake/git configuration tool.
CMake Warning at modules/dasClangBind/CMakeLists.txt:6 (message):
can't find libclang at /home/yuart/Projects/daScript/../libclang
Call Stack (most recent call first):
CMakeLists.txt:273 (INCLUDE)


-- dasGlsl module included.
CMake Warning at modules/dasLLVM/CMakeLists.txt:4 (message):
can't find libclang at /home/yuart/Projects/daScript/../libclang
Call Stack (most recent call first):
CMakeLists.txt:273 (INCLUDE)


-- dasOpenAI module included.
-- dasOpenGL module included.
-- dasPEG module included.
-- dasStbImage module included.
REGISTER DAS MODULE libDasModuleStbImage
-- dasStbTrueType module included.
REGISTER DAS MODULE libDasModuleStbTrueType
-- dasStdDlg module included.
REGISTER DAS MODULE libDasModuleStdDlg
-- dasTELEGRAM module included.
-- FLEX `2.6.4` found
-- BISON `3.8.2` found
-- File is not changed. Generation skipped.
-- File is not changed. Generation skipped.
-- File is not changed. Generation skipped.
-- File is not changed. Generation skipped.
-- File is not changed. Generation skipped.
-- File is not changed. Generation skipped.
-- File is not changed. Generation skipped.
-- File is not changed. Generation skipped.
-- Configuring done (0.4s)
-- Generating done (0.1s)
-- Build files have been written to: /home/yuart/Projects/daScript
dasLLVM turned on successfully (see log above)!
Q - exit, U - update list, D - disable all modules, arrows/J/K - navigation, enter - toggle module state
- : dasAudio
- : dasBGFX
- : dasClangBind
+ : dasGlfw
: dasGlsl - option for this module is unknown
- : dasHV
- : dasImgui
-> - : dasLLVM
- : dasMinfft
: dasOpenAI - option for this module is unknown
: dasOpenGL - option for this module is unknown
: dasPEG - option for this module is unknown
: dasPUGIXML - option for this module is unknown
- : dasQuirrel
- : dasSFML
: dasSQLITE - option for this module is unknown
+ : dasStbImage
+ : dasStbTrueType
+ : dasStdDlg
: dasTelegram - option for this module is unknown
- : dasXbyak

What exactly is libclang?

@borisbat
Copy link
Collaborator

borisbat commented Jun 4, 2024

installation of LLVM. 16.0.6 inside looks like this

02/29/2024  10:26 AM    <DIR>          bin
11/03/2023  10:56 PM    <DIR>          include
02/29/2024  10:26 AM    <DIR>          lib
02/29/2024  10:26 AM    <DIR>          libexec
02/29/2024  10:26 AM    <DIR>          share

@ArtemkaKun
Copy link
Author

Ok, trying

@ArtemkaKun
Copy link
Author

I downloaded llvm-18.1.6.src.tar.xz from https://github.com/llvm/llvm-project/releases/tag/llvmorg-18.1.6, and just renamed it into libclang and placed to suitable place.

Its content
image

Now python modules.py --path ./build --on dasLLVM outputs the following

/home/yuart/Projects/daScript/modules.py:238: SyntaxWarning: invalid escape sequence '\d'
description='''This is cmake/git configuration tool.
-- dasClangBind module included.
LIBCLANG_INCLUDE at /home/yuart/Projects/daScript/../libclang/include
LIBCLANG_LIB at /home/yuart/Projects/daScript/../libclang/lib
REGISTER DAS MODULE libDasModuleClangBind
-- dasGlsl module included.
-- dasLlvm module included.
LIBCLANG_INCLUDE at /home/yuart/Projects/daScript/../libclang/include
LIBCLANG_LIB at /home/yuart/Projects/daScript/../libclang/lib
REGISTER DAS MODULE libDasModuleLlvm
-- dasOpenAI module included.
-- dasOpenGL module included.
-- dasPEG module included.
-- dasStbImage module included.
REGISTER DAS MODULE libDasModuleStbImage
-- dasStbTrueType module included.
REGISTER DAS MODULE libDasModuleStbTrueType
-- dasStdDlg module included.
REGISTER DAS MODULE libDasModuleStdDlg
-- dasTELEGRAM module included.
-- FLEX `2.6.4` found
-- BISON `3.8.2` found
-- File is not changed. Generation skipped.
-- File is not changed. Generation skipped.
-- File is not changed. Generation skipped.
-- File is not changed. Generation skipped.
-- File is not changed. Generation skipped.
-- File is not changed. Generation skipped.
-- File is not changed. Generation skipped.
-- File is not changed. Generation skipped.
-- Configuring done (0.4s)
CMake Error at modules/dasLLVM/CMakeLists.txt:133 (ADD_LIBRARY):
Cannot find source file:

/home/yuart/Projects/daScript/modules/dasLlvm/src/cb_dasLLVM.h

Tried extensions .c .C .c++ .cc .cpp .cxx .cu .mpp .m .M .mm .ixx .cppm
.ccm .cxxm .c++m .h .hh .h++ .hm .hpp .hxx .in .txx .f .F .for .f77 .f90
.f95 .f03 .hip .ispc
Call Stack (most recent call first):
CMakeLists.txt:273 (INCLUDE)


CMake Error at modules/dasLLVM/CMakeLists.txt:133 (ADD_LIBRARY):
No SOURCES given to target: libDasModuleLlvm
Call Stack (most recent call first):
CMakeLists.txt:273 (INCLUDE)


CMake Generate step failed.  Build files cannot be regenerated correctly.
ERROR: there was an error executing 'cmake -DDAS_LLVM_DISABLED:BOOL=OFF /home/yuart/Projects/daScript'

@ArtemkaKun
Copy link
Author

Hmm, but the file is present
image

@borisbat
Copy link
Collaborator

borisbat commented Jun 4, 2024

https://t.me/daScript since this is turning into chat

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants