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

[User] Increasing ngl parameter decreases performance in Termux #1718

Closed
ghost opened this issue Jun 6, 2023 · 2 comments
Closed

[User] Increasing ngl parameter decreases performance in Termux #1718

ghost opened this issue Jun 6, 2023 · 2 comments
Labels

Comments

@ghost
Copy link

ghost commented Jun 6, 2023

Hi,

Increasing the # in -ngl has the effect of lower performance. I built 2d7bf11 with CLBlast.

Here's ./main;

LD_LIBRARY_PATH=/vendor/lib64 ./main -m ~/llama.cpp/models/Wizard-Vicuna-7B-Uncensored.ggmlv3.q4_1.bin --color -c 2048 --keep -1 -t 3 -i -p "Please list 4 ways to die in a horror movie:"

*note; LD_LIBRARY_PATH=/vendor/lib64 is required else..

ggml_opencl: clGetPlatformIDs(NPLAT, platform_ids, &n_platforms) error -1001 at /data/data/com.termux/files/home/llamacl3/ggml-opencl.cpp:373

Here's -ngl 0, 1, 2, 3;

-ngl 0;

llama_print_timings:        load time =  3812.17 ms
llama_print_timings:      sample time =   180.54 ms /    78 runs   (    2.31 ms per token)
llama_print_timings: prompt eval time =  3517.93 ms /    13 tokens (  270.61 ms per token)
llama_print_timings:        eval time = 26474.67 ms /    78 runs   (  339.42 ms per token)
llama_print_timings:       total time = 30689.09 ms

-ngl 1;

llama_print_timings:        load time =  7241.08 ms
llama_print_timings:      sample time =   166.60 ms /    76 runs   (    2.19 ms per token)
llama_print_timings: prompt eval time =  6735.64 ms /    13 tokens (  518.13 ms per token)
llama_print_timings:        eval time = 35218.78 ms /    75 runs   (  469.58 ms per token)
llama_print_timings:       total time = 43242.04 ms

-ngl 2;

llama_print_timings:        load time =  9793.00 ms                                                 
llama_print_timings:      sample time =   184.10 ms /    83 runs   (    2.22 ms per token)
llama_print_timings: prompt eval time =  9055.40 ms /    13 tokens (  696.57 ms per token)
llama_print_timings:        eval time = 43049.81 ms /    83 runs   (  518.67 ms per token)
llama_print_timings:       total time = 53333.08 ms

-ngl 3;

llama_print_timings:        load time = 13872.06 ms
llama_print_timings:      sample time =   122.20 ms /    56 runs   (    2.18 ms per token)
llama_print_timings: prompt eval time = 11477.85 ms /    13 tokens (  882.91 ms per token)
llama_print_timings:        eval time = 32679.27 ms /    55 runs   (  594.17 ms per token)
llama_print_timings:       total time = 47097.67 ms


For reference, here's an OpenBlas build;

llama_print_timings:        load time =  3787.81 ms
llama_print_timings:      sample time =   161.97 ms /    70 runs   (    2.31 ms per token)
llama_print_timings: prompt eval time =  3502.20 ms /    13 tokens (  269.40 ms per token)
llama_print_timings:        eval time = 23511.92 ms /    69 runs   (  340.75 ms per token)
llama_print_timings:       total time = 27883.11 ms

Lscpu;

Architecture:           aarch64
  CPU op-mode(s):       32-bit, 64-bit
  Byte Order:           Little Endian
CPU(s):                 8
  On-line CPU(s) list:  0-7
Vendor ID:              Qualcomm
  Model name:           Kryo-4XX-Silver
    Model:              14
    Thread(s) per core: 1
    Core(s) per socket: 4
    Socket(s):          1
    Stepping:           0xd
    CPU(s) scaling MHz: 62%
    CPU max MHz:        1785.6000
    CPU min MHz:        300.0000
    BogoMIPS:           38.40
    Flags:              fp asimd evtstrm aes pmull
                         sha1 sha2 crc32 atomics f
                        php asimdhp cpuid asimdrdm
                         lrcpc dcpop asimddp
  Model name:           Kryo-4XX-Gold
    Model:              14
    Thread(s) per core: 1
    Core(s) per socket: 2                             Socket(s):          2
    Stepping:           0xd
    CPU(s) scaling MHz: 80%
    CPU max MHz:        2841.6001
    CPU min MHz:        710.4000
    BogoMIPS:           38.40
    Flags:              fp asimd evtstrm aes pmull                         sha1 sha2 crc32 atomics f
                        php asimdhp cpuid asimdrdm                         lrcpc dcpop asimddp
Vulnerabilities:
  Itlb multihit:        Not affected
  L1tf:                 Not affected
  Mds:                  Not affected
  Meltdown:             Vulnerable
  Spec store bypass:    Vulnerable
  Spectre v1:           Mitigation; __user pointer                         sanitization
  Spectre v2:           Mitigation; Branch predict                        or hardening
  Srbds:                Not affected                Tsx async abort:      Not affected

Here's clinfo;

Number of platforms                               1                                                   Platform Name                                   QUALCOMM Snapdragon(TM)                             Platform Vendor                                 QUALCOMM
  Platform Version                                OpenCL 2.0 QUALCOMM build: commit #3dad7f8ed7 changeid #I593c16c433 Date: 10/01/21 Fri Local Branch:  Remote Branch: refs/tags/AU_LINUX_ANDROID_LA.UM.9.1.R1.11.00.00.604.073
  Platform Profile                                FULL_PROFILE                                        Platform Extensions                             

  Platform Name                                   QUALCOMM Snapdragon(TM)                           Number of devices                                 1                                                   Device Name                                     QUALCOMM Adreno(TM)                                 Device Vendor                                   QUALCOMM                                            Device Vendor ID                                0x5143
  Device Version                                  OpenCL 2.0 Adreno(TM) 640
  Driver Version                                  OpenCL 2.0 QUALCOMM build: commit #3dad7f8ed7 changeid #I593c16c433 Date: 10/01/21 Fri Local Branch:  Remote Branch: refs/tags/AU_LINUX_ANDROID_LA.UM.9.1.R1.11.00.00.604.073 Compiler E031.37.12.01      Device OpenCL C Version                         OpenCL C 2.0 Adreno(TM) 640
  Device Type                                     GPU
  Device Profile                                  FULL_PROFILE                                        Device Available                                Yes                                                 Compiler Available                              Yes                                                 Linker Available                                Yes                                                 Max compute units                               2
  Max clock frequency                             1MHz
  Device Partition                                (core)
    Max number of sub-devices                     1
    Supported partition types                     None
    Supported affinity domains                    (n/a)
  Max work item dimensions                        3
  Max work item sizes                             1024x1024x1024                                      Max work group size                             1024                                                Preferred work group size multiple (kernel)     128                                                 Preferred / native vector sizes
    char                                                 1 / 1
    short                                                1 / 1
    int                                                  1 / 1                                          long                                                 1 / 0
    half                                                 1 / 1        (cl_khr_fp16)
    float                                                1 / 1
    double                                               0 / 0        (n/a)
  Half-precision Floating-point support           (cl_khr_fp16)                                         Denormals                                     No
    Infinity and NANs                             Yes
    Round to nearest                              Yes
    Round to zero                                 No
    Round to infinity                             Yes
    IEEE754-2008 fused multiply-add               No                                                    Support is emulated in software               No
  Single-precision Floating-point support         (core)
    Denormals                                     No
    Infinity and NANs                             Yes
    Round to nearest                              Yes
    Round to zero                                 No
    Round to infinity                             Yes
    IEEE754-2008 fused multiply-add               No
    Support is emulated in software               No                                                    Correctly-rounded divide and sqrt operations  No                                                  Double-precision Floating-point support         (n/a)
  Address bits                                    64, Little-Endian
  Global memory size                              3911956480 (3.643GiB)                               Error Correction support                        No                                                  Max memory allocation                           977989120 (932.7MiB)                                Unified memory for Host and Device              Yes                                                 Shared Virtual Memory (SVM) capabilities        (core)
    Coarse-grained buffer sharing                 Yes
    Fine-grained buffer sharing                   Yes
    Fine-grained system sharing                   No
    Atomics                                       Yes
  Minimum alignment for any data type             128 bytes
  Alignment of base address                       1024 bits (128 bytes)                               Page size (QCOM)                                4096 bytes
  External memory padding (QCOM)                  0 bytes
  Preferred alignment for atomics                     SVM                                           128 bytes                                             Global                                        0 bytes                                               Local                                         0 bytes                                             Max size for global variable                    65536 (64KiB)                                       Preferred total size of global vars             1048576 (1024KiB)                                   Global Memory cache type                        Read/Write
  Global Memory cache size                        131072 (128KiB)                                     Global Memory cache line size                   64 bytes                                            Image support                                   Yes
    Max number of samplers per kernel             16                                                    Max size for 1D images from buffer            134217728 pixels                                      Max 1D or 2D image array size                 2048 images
    Base address alignment for 2D image buffers   64 bytes
    Pitch alignment for 2D image buffers          64 pixels
    Max 2D image size                             16384x16384 pixels
    Max 3D image size                             16384x16384x2048 pixels
    Max number of read image args                 128
    Max number of write image args                64                                                    Max number of read/write image args           64                                                  Max number of pipe args                         16                                                  Max active pipe reservations                    7680                                                Max pipe packet size                            1024
  Local memory type                               Local
  Local memory size                               32768 (32KiB)                                       Max number of constant args                     8                                                   Max constant buffer size                        65536 (64KiB)
  Max size of kernel argument                     1024
  Queue properties (on host)
    Out-of-order execution                        Yes                                                   Profiling                                     Yes                                                 Queue properties (on device)                        Out-of-order execution                        Yes
    Profiling                                     Yes
    Preferred size                                655376 (640KiB)
    Max size                                      655376 (640KiB)
  Max queues on device                            1                                                   Max events on device                            1024                                                Prefer user sync for interop                    No
  Profiling timer resolution                      1000ns
  Execution capabilities                              Run OpenCL kernels                            Yes
    Run native kernels                            No
  printf() buffer size                            1048576 (1024KiB)
  Built-in kernels                                (n/a)
  Device Extensions                               cl_khr_3d_image_writes cl_img_egl_image cl_khr_byte_addressable_store cl_khr_depth_images cl_khr_egl_event cl_khr_egl_image cl_khr_fp16 cl_khr_gl_sharing cl_khr_global_int32_base_atomics cl_khr_global_int32_extended_atomics cl_khr_local_int32_base_atomics cl_khr_local_int32_extended_atomics cl_khr_image2d_from_buffer cl_khr_mipmap_image cl_khr_srgb_image_writes cl_khr_subgroups cl_qcom_create_buffer_from_image cl_qcom_ext_host_ptr cl_qcom_ion_host_ptr cl_qcom_perf_hint cl_qcom_other_image cl_qcom_subgroup_shuffle cl_qcom_vector_image_ops cl_qcom_extract_image_plane cl_qcom_android_native_buffer_host_ptr cl_qcom_protected_context cl_qcom_priority_hint cl_qcom_compressed_yuv_image_read cl_qcom_compressed_image cl_qcom_ext_host_ptr_iocoherent cl_qcom_accelerated_image_ops cl_qcom_ml_ops      
NULL platform behavior                              clGetPlatformInfo(NULL, CL_PLATFORM_NAME, ...)  No platform
  clGetDeviceIDs(NULL, CL_DEVICE_TYPE_ALL, ...)   No platform
  clCreateContext(NULL, ...) [default]            No platform
  clCreateContext(NULL, ...) [other]              Success [P0]
  clCreateContextFromType(NULL, CL_DEVICE_TYPE_DEFAULT)  Success (1)
    Platform Name                                 QUALCOMM Snapdragon(TM)
    Device Name                                   QUALCOMM Adreno(TM)                                 clCreateContextFromType(NULL, CL_DEVICE_TYPE_CPU)  No devices found in platform                     clCreateContextFromType(NULL, CL_DEVICE_TYPE_GPU)  Success (1)                                        Platform Name                                 QUALCOMM Snapdragon(TM)                               Device Name                                   QUALCOMM Adreno(TM)                                 clCreateContextFromType(NULL, CL_DEVICE_TYPE_ACCELERATOR)  No devices found in platform             clCreateContextFromType(NULL, CL_DEVICE_TYPE_CUSTOM)  Invalid device type for platform              clCreateContextFromType(NULL, CL_DEVICE_TYPE_ALL)  Success (1)
    Platform Name                                 QUALCOMM Snapdragon(TM)                               Device Name                                   QUALCOMM Adreno(TM)

I expect offloading to improve llama.cpp performance.

@gustrd
Copy link
Contributor

gustrd commented Jun 26, 2023

I've made the same observation as you. It's conceivable that the behavior we're noticing is related to how the shared memory interacts between the CPU and GPU.

On my personal laptop, I've typically noticed that peak performance is achieved when the number of layers utilized is significantly below the system's maximum capacity. This suggests that there may be an optimal threshold, beyond which additional layers may not necessarily contribute to enhancing the performance, possibly due to resource management or allocation constraints.

@ghost ghost changed the title ngl parameter causing slowness and crash [User] Increasing ngl parameter decreases performance in Termux Jun 26, 2023
@github-actions github-actions bot added the stale label Mar 25, 2024
Copy link
Contributor

This issue was closed because it has been inactive for 14 days since being marked as stale.

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

No branches or pull requests

1 participant