refactor: add new module for backend-specific code#2308
Conversation
i don't know if the bug also affects rocm or not. also, i think the metal device names might be wrong and i think |
Well, I was following the comment. My own card doesn't seem to be affected. Do you have a reference for the bug? The closest I've found (issue 16950) is just a warning, and doesn't fit the timeline for that release.
Found it:
It is correct at least on Vulkan. But I could add a test for skipping non-GPUs/iGPUs, just to be sure. |
what i mean is, its possible for other backends to be initialized first e.g. BLAS, so index 0 is not the only index to check |
But could that happen with current Koboldcpp? Both CUDA0 and BLAS0 appearing on the device list on the same run? (I'm not familiar with the BLAS backend). |
|
Nope, because current koboldcpp defines are set at compile time for each dll, so if you pick that library, it will be set regardless of what devices or backends you have configured on your system. |
dda7a0f to
3b6db85
Compare
Should be safe then. These tests are not adequate for a future, possibly-multi-backend version. But right now the tests are assuming a single type of GPU, to make the transition easier to do piece by piece: just replacing the global ifdefs with the 'global' GPU type. The backend type will still be dictated by which ggml runtime is used at link time. What each test should be doing is passing the |
11afe0a to
3575d94
Compare
0ca4665 to
474a9d9
Compare
This is an initial attempt to replace build-time backend checks with runtime ones.
My main intention is to eventually be able to decouple all code from fixed ggml backends, which would give us the ability to have a distributed binary for any CPU instruction set, use more than one GPU backend type at the same time, etc. But even if that's not achievable (or desired!), I believe Koboldcpp can still benefit from changes in that direction: reduced build times, lower chance of building OK on one backend and failing on another, smaller binaries, etc.
I'm submitting very early to validate the approach before spending too much time on this, so right now it only replaces some easier parts of
gpttype_adapter: checks for tensor splitting, BLAS support, etc. I've also refactored the tensor splitting check to avoid a bit of repetitive code.The runtime backend tests are very similar to the ones used by stable-diffusion.cpp, identifying the backends by their names (with a bit of convenience code to be able to check several at once). Right now, I'm always checking the first device, so it should give the same results as the compile-time checks; but the API is already prepared to accept backend pointers.
There should be only one functional change: the check
also triggered for ROCm; so I've replaced it with a straight CUDA-only check.