2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

llama.cpp + OpenCLでAdreno GPUを活用したLLM推論をする

Last updated at Posted at 2025-09-19

何をするか

Qualcomm Snapdragon 8 Gen 1, 2, 3 / Eliteを搭載したAndroid端末上で、OpenCLバックエンドを使用したllama.cppを実行する。ちなみに期待する程速くないどころか、多分なにかしらのボトルネックが生じておりCPU推論より遅いです。

自分の𝕏より

前提

Android端末やWindows (Arm64)で広く使われているQualcomm Snapdragon SoCには、AdrenoというブランドのGPUが搭載されている。

llama.cppがOpenCLをサポートしたことにより、Adreno GPUのOpenCLバックエンドを活用したLLM推論が出来るようになっているらしい。

公式記事のビルド手順と、それだけでは上手くいかなかった点の解決策をまとめて、記事にした。

実験環境

  • 母艦
    • Windows 11 24H2
    • wsl Ubuntu 22.04 LTS
  • 実験機 (スマートフォン)
    • POCO F6 Pro (グローバル版)
    • Snapdragon 8 Gen 2 Mobile Processor
    • 16GB LPDDR5X / 1TB UFS 4.0
    • Android 15
    • Hyper OS 2.2 (2.0.201.0.VNKMIXM)
    • Termux

手順

主な参考記事はQualcomm公式デベロッパーブログのこれ。

冒頭にはOpenCLについてやllama.cppのOpenCLサポートの話が書かれている。llama.cppのメインラインに統合された内容はOpenCL 3.0に基づいており、これをサポートするGPUが搭載されていれば簡単に移植できるとのこと。今日にのモバイルGPUであれば大概サポート対象だと思うので、ある程度高性能な端末があれば試してみるのも良いかもしれない。特に、手元に無いDimensityあたりでの挙動はとても気になる。(だれか試したら教えてネ...)

なお、記事中ではSnapdragon X Elite / Elite Plusを搭載したWindows Arm64での実行方法についても解説されている。

Android NDKのインストール

Android NDKのインストールには、Command line toolsを利用する。
これはAndroid Studioに含まれているものだが、個別でダウンロードすることも可能。
WSL環境にはAndroid Studioを入れていなかったので、ここから単体ダウンロードする。image.png

wget https://dl.google.com/android/repository/commandlinetools-linux-[version]_latest.zip
unzip commandlinetools-linux-[version]_latest.zip 
mkdir -p ~/android-sdk/cmdline-tools
mv cmdline-tools latest
mv latest ~/android-sdk/cmdline-tools/
rm -rf commandlinetools-linux-[version]_latest.zip 

NDKをセットアップする

~/android-sdk/cmdline-tools/latest/bin/sdkmanager "ndk;26.3.11579264" 

規約同意プロンプトが出たらyを押してEnter

Javaをインストールする

これは必要な場合のみ行う。

sudo apt install openjdk-21-jre-headless

OpenCLヘッダーとICDローダーを導入する

mkdir -p ~/dev/llm

cd ~/dev/llm 
git clone https://github.com/KhronosGroup/OpenCL-Headers
cd OpenCL-Headers
cp -r CL ~/android-sdk/ndk/26.3.11579264/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include 
 
cd ~/dev/llm
git clone https://github.com/KhronosGroup/OpenCL-ICD-Loader
cd OpenCL-ICD-Loader
mkdir build_ndk26 && cd build_ndk26

cmake .. -G Ninja -DCMAKE_BUILD_TYPE=Release \
  -DCMAKE_TOOLCHAIN_FILE=$HOME/android-sdk/ndk/26.3.11579264/build/cmake/android.toolchain.cmake \
  -DOPENCL_ICD_LOADER_HEADERS_DIR=$HOME/android-sdk/ndk/26.3.11579264/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include \
  -DANDROID_ABI=arm64-v8a \
  -DANDROID_PLATFORM=24 \
  -DANDROID_STL=c++_shared
ninja

cp libOpenCL.so ~/android-sdk/ndk/26.3.11579264/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib/aarch64-linux-android

llama.cppをビルドする

cd ~/dev/llm
 
git clone https://github.com/ggml-org/llama.cpp
cd llama.cpp
mkdir build-android && cd build-android
 
cmake .. -G Ninja \
 -DCMAKE_TOOLCHAIN_FILE=$HOME/android-sdk/ndk/26.3.11579264/build/cmake/android.toolchain.cmake\
 -DANDROID_ABI=arm64-v8a \
 -DANDROID_PLATFORM=android-28 \
 -DGGML_OPENCL=ON \
 -DLLAMA_CURL=OFF \
 -DGGML_OPENMP=OFF
 
ninja

オプションは

  • Android用のビルドツールチェーンのパス指定
  • ターゲットABIの指定
  • ターゲットAndroid API Levelの指定 (28 = Android 9+)
  • OpenCLを有効化
  • LibCurlの無効化
  • OpenMPの無効化

となっている。下の二つは無効化しておかないとビルド時に依存関係が読み込めずエラーになる。llama-cliやllama-serverを実行する分にはこの二つは影響しないっぽいので無効にした。

実機転送

ビルドしたファイルは~/dev/llm/llama.cpp/build-android/binに保存されている。

転送方法は任意だが、今回はtarにまとめてQuickShareで送り込んだ。

# WSL
cd ~/dev/llm/llama.cpp/build-android/
tar cvf llama.tar ./bin/
explorer.exe .

今回はQuickShareでAndroidのDownloadsフォルダに配置した。

Termuxを立ち上げ

# Termux
termux-setup-storage

でストレージアクセス権を付与する

# Termux
cd

mkdir ~/llama/
cd ~/llama/
cp ~/storage/downloads/llama.tar .
tar xvf llama.tar
rm llama.tar

モデルにはunsloth/gemma-3-4b-it-GGUFを用いる。

# Termux
mkdir ~/llama/models/
cd ~/llama/models/
wget https://huggingface.co/unsloth/gemma-3-4b-it-GGUF/resolve/main/gemma-3-4b-it-Q4_K_M.gguf?download=true

推論実行

ここまでで以下のような配置になっていれば準備完了。

  • ~/llama/
    • bin/
      • llama-cli
      • llama-server
      • ...
    • models/
      • gemma-3n-E4B-it-Q4_K_M.gguf

実行するには次の通りコマンドを入力する。

# Termux
LD_LIBRARY_PATH=/vendor/lib64:~/llama/bin:$LD_LIBRARY_PATH ~/llama/bin/llama-cli -m ~/llama/models/gemma-3-4b-it-Q4_K_M.gguf -b 128 -ngl 99 -c 2048

ちなみにLD_LIBRARY_PATHはそれぞれ

  • libOpenCL.so (/vendor/lib64)
  • libllama.so (llama-cliと同じbin/フォルダ内)

を参照している。

実行時のログ(長いので折り畳み)
```text
~$ LD_LIBRARY_PATH=/vendor/lib64:~/llama/bin:$LD_LIBRARY_PATH ~/llama/bin/llama-cli -m ~/llama/models/gemma-3-4b-it-Q4_K_M.gguf -b 128 -ngl 99 -c 2048
ggml_opencl: selected platform: 'QUALCOMM Snapdragon(TM)'
ggml_opencl: device: 'QUALCOMM Adreno(TM) (OpenCL 3.0 Adreno(TM) 740)'
ggml_opencl: OpenCL driver: OpenCL 3.0 QUALCOMM build: commit unknown Compiler E031.41.03.58
ggml_opencl: vector subgroup broadcast support: false
ggml_opencl: device FP16 support: true
ggml_opencl: mem base addr align: 128
ggml_opencl: max mem alloc size: 1024 MB
ggml_opencl: device max workgroup size: 1024
ggml_opencl: SVM coarse grain buffer support: true
ggml_opencl: SVM fine grain buffer support: true
ggml_opencl: SVM fine grain system support: false
ggml_opencl: SVM atomics support: true
ggml_opencl: flattening quantized weights representation as struct of arrays (GGML_OPENCL_SOA_Q)
ggml_opencl: using kernels optimized for Adreno (GGML_OPENCL_USE_ADRENO_KERNELS)
ggml_opencl: loading OpenCL kernels...............................................................
ggml_opencl: default device: 'QUALCOMM Adreno(TM) (OpenCL 3.0 Adreno(TM) 740)'
build: 6497 (cd08fc3e) with Android (11349228, +pgo, +bolt, +lto, -mlgo, based on r487747e) clang version 17.0.2 (https://android.googlesource.com/toolchain/llvm-project d9f89f4d16663d5012e5c09495f3b30ece3d2362) for x86_64-unknown-linux-gnu
main: llama backend init
main: load the model and apply lora adapter, if any
llama_model_load_from_file_impl: using device GPUOpenCL (QUALCOMM Adreno(TM)) (unknown id) - 0 MiB free
llama_model_loader: loaded meta data with 40 key-value pairs and 444 tensors from ./models/gemma-3-4b-it-Q4_K_M.gguf (version GGUF V3 (latest))
llama_model_loader: Dumping metadata keys/values. Note: KV overrides do not apply in this output.
llama_model_loader: - kv   0:                       general.architecture str              = gemma3
llama_model_loader: - kv   1:                               general.type str              = model
llama_model_loader: - kv   2:                               general.name str              = Gemma-3-4B-It
llama_model_loader: - kv   3:                           general.finetune str              = it
llama_model_loader: - kv   4:                           general.basename str              = Gemma-3-4B-It
llama_model_loader: - kv   5:                       general.quantized_by str              = Unsloth
llama_model_loader: - kv   6:                         general.size_label str              = 4B
llama_model_loader: - kv   7:                           general.repo_url str              = https://huggingface.co/unsloth
llama_model_loader: - kv   8:                      gemma3.context_length u32              = 131072
llama_model_loader: - kv   9:                    gemma3.embedding_length u32              = 2560
llama_model_loader: - kv  10:                         gemma3.block_count u32              = 34
llama_model_loader: - kv  11:                 gemma3.feed_forward_length u32              = 10240
llama_model_loader: - kv  12:                gemma3.attention.head_count u32              = 8
llama_model_loader: - kv  13:    gemma3.attention.layer_norm_rms_epsilon f32              = 0.000001
llama_model_loader: - kv  14:                gemma3.attention.key_length u32              = 256
llama_model_loader: - kv  15:              gemma3.attention.value_length u32              = 256
llama_model_loader: - kv  16:                      gemma3.rope.freq_base f32              = 1000000.000000
llama_model_loader: - kv  17:            gemma3.attention.sliding_window u32              = 1024
llama_model_loader: - kv  18:             gemma3.attention.head_count_kv u32              = 4
llama_model_loader: - kv  19:                   gemma3.rope.scaling.type str              = linear
llama_model_loader: - kv  20:                 gemma3.rope.scaling.factor f32              = 8.000000
llama_model_loader: - kv  21:                       tokenizer.ggml.model str              = llama
llama_model_loader: - kv  22:                         tokenizer.ggml.pre str              = default
llama_model_loader: - kv  23:                      tokenizer.ggml.tokens arr[str,262208]  = ["<pad>", "<eos>", "<bos>", "<unk>", ...
llama_model_loader: - kv  24:                      tokenizer.ggml.scores arr[f32,262208]  = [-1000.000000, -1000.000000, -1000.00...
llama_model_loader: - kv  25:                  tokenizer.ggml.token_type arr[i32,262208]  = [3, 3, 3, 3, 3, 4, 3, 3, 3, 3, 3, 3, ...
llama_model_loader: - kv  26:                tokenizer.ggml.bos_token_id u32              = 2
llama_model_loader: - kv  27:                tokenizer.ggml.eos_token_id u32              = 106
llama_model_loader: - kv  28:            tokenizer.ggml.unknown_token_id u32              = 3
llama_model_loader: - kv  29:            tokenizer.ggml.padding_token_id u32              = 0
llama_model_loader: - kv  30:               tokenizer.ggml.add_bos_token bool             = true
llama_model_loader: - kv  31:               tokenizer.ggml.add_eos_token bool             = false
llama_model_loader: - kv  32:                    tokenizer.chat_template str              = {{ bos_token }}\n{%- if messages[0]['r...
llama_model_loader: - kv  33:            tokenizer.ggml.add_space_prefix bool             = false
llama_model_loader: - kv  34:               general.quantization_version u32              = 2
llama_model_loader: - kv  35:                          general.file_type u32              = 15
llama_model_loader: - kv  36:                      quantize.imatrix.file str              = gemma-3-4b-it-GGUF/imatrix_unsloth.dat
llama_model_loader: - kv  37:                   quantize.imatrix.dataset str              = unsloth_calibration_gemma-3-4b-it.txt
llama_model_loader: - kv  38:             quantize.imatrix.entries_count i32              = 238
llama_model_loader: - kv  39:              quantize.imatrix.chunks_count i32              = 663
llama_model_loader: - type  f32:  205 tensors
llama_model_loader: - type q4_K:  204 tensors
llama_model_loader: - type q6_K:   35 tensors
print_info: file format = GGUF V3 (latest)
print_info: file type   = Q4_K - Medium
print_info: file size   = 2.31 GiB (5.12 BPW)
load: printing all EOG tokens:
load:   - 106 ('<end_of_turn>')
load: special tokens cache size = 6415
load: token to piece cache size = 1.9446 MB
print_info: arch             = gemma3
print_info: vocab_only       = 0
print_info: n_ctx_train      = 131072
print_info: n_embd           = 2560
print_info: n_layer          = 34
print_info: n_head           = 8
print_info: n_head_kv        = 4
print_info: n_rot            = 256
print_info: n_swa            = 1024
print_info: is_swa_any       = 1
print_info: n_embd_head_k    = 256
print_info: n_embd_head_v    = 256
print_info: n_gqa            = 2
print_info: n_embd_k_gqa     = 1024
print_info: n_embd_v_gqa     = 1024
print_info: f_norm_eps       = 0.0e+00
print_info: f_norm_rms_eps   = 1.0e-06
print_info: f_clamp_kqv      = 0.0e+00
print_info: f_max_alibi_bias = 0.0e+00
print_info: f_logit_scale    = 0.0e+00
print_info: f_attn_scale     = 6.2e-02
print_info: n_ff             = 10240
print_info: n_expert         = 0
print_info: n_expert_used    = 0
print_info: causal attn      = 1
print_info: pooling type     = 0
print_info: rope type        = 2
print_info: rope scaling     = linear
print_info: freq_base_train  = 1000000.0
print_info: freq_scale_train = 0.125
print_info: n_ctx_orig_yarn  = 131072
print_info: rope_finetuned   = unknown
print_info: model type       = 4B
print_info: model params     = 3.88 B
print_info: general.name     = Gemma-3-4B-It
print_info: vocab type       = SPM
print_info: n_vocab          = 262208
print_info: n_merges         = 0
print_info: BOS token        = 2 '<bos>'
print_info: EOS token        = 106 '<end_of_turn>'
print_info: EOT token        = 106 '<end_of_turn>'
print_info: UNK token        = 3 '<unk>'
print_info: PAD token        = 0 '<pad>'
print_info: LF token         = 248 '<0x0A>'
print_info: EOG token        = 106 '<end_of_turn>'
print_info: max token length = 48
load_tensors: loading model tensors, this can take a while... (mmap = true)
load_tensors: offloading 34 repeating layers to GPU
load_tensors: offloading output layer to GPU
load_tensors: offloaded 35/35 layers to GPU
load_tensors:   CPU_Mapped model buffer size =  2368.28 MiB
load_tensors:       OpenCL model buffer size =   910.03 MiB
..................................................................
llama_context: constructing llama_context
llama_context: n_seq_max     = 1
llama_context: n_ctx         = 2048
llama_context: n_ctx_per_seq = 2048
llama_context: n_batch       = 128
llama_context: n_ubatch      = 128
llama_context: causal_attn   = 1
llama_context: flash_attn    = auto
llama_context: kv_unified    = false
llama_context: freq_base     = 1000000.0
llama_context: freq_scale    = 0.125
llama_context: n_ctx_per_seq (2048) < n_ctx_train (131072) -- the full capacity of the model will not be utilized
llama_context:        CPU  output buffer size =     1.00 MiB
llama_kv_cache_iswa: creating non-SWA KV cache, size = 2048 cells
llama_kv_cache:     OpenCL KV buffer size =    40.00 MiB
llama_kv_cache: size =   40.00 MiB (  2048 cells,   5 layers,  1/1 seqs), K (f16):   20.00 MiB, V (f16):   20.00 MiB
llama_kv_cache_iswa: creating     SWA KV cache, size = 1280 cells
llama_kv_cache:     OpenCL KV buffer size =   145.00 MiB
llama_kv_cache: size =  145.00 MiB (  1280 cells,  29 layers,  1/1 seqs), K (f16):   72.50 MiB, V (f16):   72.50 MiB
llama_context: Flash Attention was auto, set to enabled
llama_context:     OpenCL compute buffer size =   129.28 MiB
llama_context:        CPU compute buffer size =    17.88 MiB
llama_context: graph nodes  = 1369
llama_context: graph splits = 308
common_init_from_params: added <end_of_turn> logit bias = -inf
common_init_from_params: setting dry_penalty_last_n to ctx_size = 2048
common_init_from_params: warming up the model with an empty run - please wait ... (--no-warmup to disable)
main: llama threadpool init, n_threads = 8
main: chat template is available, enabling conversation mode (disable it with -no-cnv)
main: chat template example:
<start_of_turn>user
You are a helpful assistant

Hello<end_of_turn>
<start_of_turn>model
Hi there<end_of_turn>
<start_of_turn>user
How are you?<end_of_turn>
<start_of_turn>model


system_info: n_threads = 8 (n_threads_batch = 8) / 8 | CPU : NEON = 1 | ARM_FMA = 1 | LLAMAFILE = 1 | REPACK = 1 |

main: interactive mode on.
sampler seed: 1846473821
sampler params:
        repeat_last_n = 64, repeat_penalty = 1.000, frequency_penalty = 0.000, presence_penalty = 0.000
        dry_multiplier = 0.000, dry_base = 1.750, dry_allowed_length = 2, dry_penalty_last_n = 2048
        top_k = 40, top_p = 0.950, min_p = 0.050, xtc_probability = 0.000, xtc_threshold = 0.100, typical_p = 1.000, top_n_sigma = -1.000, temp = 0.800
        mirostat = 0, mirostat_lr = 0.100, mirostat_ent = 5.000
sampler chain: logits -> logit-bias -> penalties -> dry -> top-n-sigma -> top-k -> typical -> top-p -> min-p -> xtc -> temp-ext -> dist
generate: n_ctx = 2048, n_batch = 128, n_predict = -1, n_keep = 1

== Running in interactive mode. ==
 - Press Ctrl+C to interject at any time.
 - Press Return to return control to the AI.
 - To return control without starting a new line, end your input with '/'.
 - If you want to submit another line, end your input with '\'.
 - Not using system message. To change it, set a different value via -sys PROMPT


>
```

結果

実行してみると、意外に遅いと思う。というか普通にGPUオフロードしない方が高速。
モデルサイズとかバッチサイズとか調整してみたが、どう頑張ってもCPUの10~30%程度の速度しか出なかった。

試した結果は以下の通り (Eval Tok/s)

unsloth/gemma-3-4b-it-GGUF (Q4_K_M)

ngl b Tok/s
99 128 1.88
0 128 5.68
99 32 2.00
0 32 5.51

unsloth/gemma-3-270m-it-GGUF (Q4_K_M)

ngl b Tok/s
99 128 11.14
0 128 47.81
99 32 10.31
0 32 44.08
結果全文
  • Gemma3 4B
99.128
llama_perf_sampler_print:    sampling time =      21.79 ms /    57 runs   (    0.38 ms per token,  2615.52 tokens per second)
llama_perf_context_print:        load time =    7806.36 ms
llama_perf_context_print: prompt eval time =    3510.83 ms /    10 tokens (  351.08 ms per token,     2.85 tokens per second)
llama_perf_context_print:        eval time =   24984.97 ms /    47 runs   (  531.60 ms per token,     1.88 tokens per second)
llama_perf_context_print:       total time =   37618.79 ms /    57 tokens
llama_perf_context_print:    graphs reused =         46
Interrupted by user

0.128
llama_perf_sampler_print:    sampling time =      66.43 ms /    69 runs   (    0.96 ms per token,  1038.67 tokens per second)
llama_perf_context_print:        load time =     827.40 ms
llama_perf_context_print: prompt eval time =    1193.27 ms /    10 tokens (  119.33 ms per token,     8.38 tokens per second)
llama_perf_context_print:        eval time =   10386.29 ms /    59 runs   (  176.04 ms per token,     5.68 tokens per second)
llama_perf_context_print:       total time =   19247.48 ms /    69 tokens
llama_perf_context_print:    graphs reused =         58
Interrupted by user

99.32
llama_perf_sampler_print:    sampling time =      18.93 ms /    57 runs   (    0.33 ms per token,  3010.30 tokens per second)
llama_perf_context_print:        load time =    7718.04 ms
llama_perf_context_print: prompt eval time =    3323.28 ms /    10 tokens (  332.33 ms per token,     3.01 tokens per second)
llama_perf_context_print:        eval time =   23473.94 ms /    47 runs   (  499.45 ms per token,     2.00 tokens per second)
llama_perf_context_print:       total time =   33214.88 ms /    57 tokens
llama_perf_context_print:    graphs reused =         46
Interrupted by user

0.32
llama_perf_sampler_print:    sampling time =      10.78 ms /    74 runs   (    0.15 ms per token,  6866.47 tokens per second)
llama_perf_context_print:        load time =     812.56 ms
llama_perf_context_print: prompt eval time =     996.31 ms /    10 tokens (   99.63 ms per token,    10.04 tokens per second)
llama_perf_context_print:        eval time =   11607.39 ms /    64 runs   (  181.37 ms per token,     5.51 tokens per second)
llama_perf_context_print:       total time =   17741.16 ms /    74 tokens
llama_perf_context_print:    graphs reused =         63
Interrupted by user
  • Gemma3 270M
99.128
llama_perf_sampler_print:    sampling time =       2.00 ms /    21 runs   (    0.10 ms per token, 10473.82 tokens per second)
llama_perf_context_print:        load time =    3727.69 ms
llama_perf_context_print: prompt eval time =     476.41 ms /    10 tokens (   47.64 ms per token,    20.99 tokens per second)
llama_perf_context_print:        eval time =     987.63 ms /    11 runs   (   89.78 ms per token,    11.14 tokens per second)
llama_perf_context_print:       total time =    8478.29 ms /    21 tokens
llama_perf_context_print:    graphs reused =         10
Interrupted by user

0.128
llama_perf_sampler_print:    sampling time =      12.83 ms /    21 runs   (    0.61 ms per token,  1636.53 tokens per second)
llama_perf_context_print:        load time =     512.57 ms
llama_perf_context_print: prompt eval time =      97.01 ms /    10 tokens (    9.70 ms per token,   103.08 tokens per second)
llama_perf_context_print:        eval time =     230.06 ms /    11 runs   (   20.91 ms per token,    47.81 tokens per second)
llama_perf_context_print:       total time =    5547.31 ms /    21 tokens
llama_perf_context_print:    graphs reused =         10
Interrupted by user

99.32
llama_perf_sampler_print:    sampling time =       3.79 ms /    21 runs   (    0.18 ms per token,  5540.90 tokens per second)
llama_perf_context_print:        load time =    4327.94 ms
llama_perf_context_print: prompt eval time =     779.88 ms /    10 tokens (   77.99 ms per token,    12.82 tokens per second)
llama_perf_context_print:        eval time =    1066.77 ms /    11 runs   (   96.98 ms per token,    10.31 tokens per second)
llama_perf_context_print:       total time =    7130.24 ms /    21 tokens
llama_perf_context_print:    graphs reused =         10
Interrupted by user

0.32
llama_perf_sampler_print:    sampling time =      15.45 ms /    20 runs   (    0.77 ms per token,  1294.83 tokens per second)
llama_perf_context_print:        load time =     390.46 ms
llama_perf_context_print: prompt eval time =     224.99 ms /    10 tokens (   22.50 ms per token,    44.45 tokens per second)
llama_perf_context_print:        eval time =     226.88 ms /    10 runs   (   22.69 ms per token,    44.08 tokens per second)
llama_perf_context_print:       total time =    5078.80 ms /    20 tokens
llama_perf_context_print:    graphs reused =          9
Interrupted by user

chart.png

ログを読む・考察

ggml_opencl: selected platform: 'QUALCOMM Snapdragon(TM)'
ggml_opencl: device: 'QUALCOMM Adreno(TM) (OpenCL 3.0 Adreno(TM) 740)'
ggml_opencl: OpenCL driver: OpenCL 3.0 QUALCOMM build: commit unknown Compiler E031.41.03.58

(中略)

ggml_opencl: loading OpenCL kernels...............................................................
ggml_opencl: default device: 'QUALCOMM Adreno(TM) (OpenCL 3.0 Adreno(TM) 740)'

OpenCLの読み込みはできていそう。

load_tensors: loading model tensors, this can take a while... (mmap = true)
load_tensors: offloading 34 repeating layers to GPU
load_tensors: offloading output layer to GPU
load_tensors: offloaded 35/35 layers to GPU

GPUへのオフロードも上手く行っているっぽい

load_tensors:   CPU_Mapped model buffer size =  2368.28 MiB
load_tensors:       OpenCL model buffer size =   910.03 MiB

あれ? CPUにマップされてる分が多い?

ggml_opencl: max mem alloc size: 1024 MB

少し戻ったところにこんな表記が
OpenCLのメモリアロケーションサイズが制限されている?

つまり、

  • なんらかの理由でOpenCL処理用に割り当てられるメモリ量が制限されている
  • 制限を超えた分がCPU側のメモリ(といっても内部的には1チップだが)に読み込まれている
  • CPU-GPU間のデータ転送がボトルネックになり遅くなっている

という構図かと予想。この制限値を引き上げたり、外したりする方法を調べているところで一旦この記事は終了とする。

最後に

お疲れ様でした。
締まらない終わり方になってしまいすみません。
解決策・設定の提案・感想など、コメントでお寄せいただけると幸いです。

ありがとうございました。

参考記事

2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?