Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
ollama
Commits
daaf42e4
Commit
daaf42e4
authored
Feb 28, 2025
by
Michael Yang
Browse files
ml/backend/ggml: clean up
parent
2dc60d46
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
7 additions
and
8 deletions
+7
-8
ml/backend/ggml/ggml.go
ml/backend/ggml/ggml.go
+7
-8
No files found.
ml/backend/ggml/ggml.go
View file @
daaf42e4
...
@@ -84,12 +84,12 @@ func New(r *os.File, params ml.BackendParams) (ml.Backend, error) {
...
@@ -84,12 +84,12 @@ func New(r *os.File, params ml.BackendParams) (ml.Backend, error) {
}
}
}
}
var
cpuBufferTypes
[]
*
C
.
struct_ggml_backend_buffer_type
cpuDeviceBufferType
:=
deviceBufferType
{
d
:
C
.
ggml_backend_dev_by_type
(
C
.
GGML_BACKEND_DEVICE_TYPE_CPU
)}
for
_
,
d
:=
range
append
(
accels
,
append
(
gpus
,
cpus
...
)
...
)
{
for
_
,
d
:=
range
append
(
accels
,
append
(
gpus
,
cpus
...
)
...
)
{
switch
C
.
ggml_backend_dev_type
(
d
)
{
switch
C
.
ggml_backend_dev_type
(
d
)
{
case
C
.
GGML_BACKEND_DEVICE_TYPE_CPU
,
case
C
.
GGML_BACKEND_DEVICE_TYPE_CPU
,
C
.
GGML_BACKEND_DEVICE_TYPE_ACCEL
:
C
.
GGML_BACKEND_DEVICE_TYPE_ACCEL
:
cpuBufferTypes
=
append
(
cpuBufferTypes
,
C
.
ggml_backend_dev_buffer_type
(
d
))
cpu
Device
BufferType
.
bt
s
=
append
(
cpu
Device
BufferType
.
bt
s
,
C
.
ggml_backend_dev_buffer_type
(
d
))
}
}
}
}
...
@@ -98,7 +98,7 @@ func New(r *os.File, params ml.BackendParams) (ml.Backend, error) {
...
@@ -98,7 +98,7 @@ func New(r *os.File, params ml.BackendParams) (ml.Backend, error) {
bt
:=
C
.
ggml_backend_dev_buffer_type
(
d
)
bt
:=
C
.
ggml_backend_dev_buffer_type
(
d
)
gpuDeviceBufferTypes
=
append
(
gpuDeviceBufferTypes
,
deviceBufferType
{
gpuDeviceBufferTypes
=
append
(
gpuDeviceBufferTypes
,
deviceBufferType
{
d
:
d
,
d
:
d
,
bts
:
append
([]
*
C
.
struct_ggml_backend_buffer_type
{
bt
},
cpuBufferTypes
...
),
bts
:
append
([]
*
C
.
struct_ggml_backend_buffer_type
{
bt
},
cpu
Device
BufferType
.
bt
s
...
),
})
})
}
}
...
@@ -131,18 +131,17 @@ func New(r *os.File, params ml.BackendParams) (ml.Backend, error) {
...
@@ -131,18 +131,17 @@ func New(r *os.File, params ml.BackendParams) (ml.Backend, error) {
splits
[
i
]
/=
sum
splits
[
i
]
/=
sum
}
}
cpuDeviceBufferTypes
:=
deviceBufferType
{
C
.
ggml_backend_dev_by_type
(
C
.
GGML_BACKEND_DEVICE_TYPE_CPU
),
cpuBufferTypes
}
input
:=
cpuDeviceBufferType
input
:=
cpuDeviceBufferTypes
blocks
:=
int
(
meta
.
KV
()
.
BlockCount
())
blocks
:=
int
(
meta
.
KV
()
.
BlockCount
())
assignLayer
:=
func
(
i
int
)
(
temp
deviceBufferType
)
{
assignLayer
:=
func
(
i
int
)
deviceBufferType
{
if
i
>=
params
.
NumGPULayers
{
if
i
>=
params
.
NumGPULayers
{
return
cpuDeviceBufferType
s
return
cpuDeviceBufferType
}
}
index
:=
slices
.
IndexFunc
(
splits
,
func
(
f
float32
)
bool
{
return
float32
(
i
)
/
float32
(
blocks
+
1
)
<
f
})
index
:=
slices
.
IndexFunc
(
splits
,
func
(
f
float32
)
bool
{
return
float32
(
i
)
/
float32
(
blocks
+
1
)
<
f
})
if
index
<
0
||
index
>=
len
(
gpuDeviceBufferTypes
)
{
if
index
<
0
||
index
>=
len
(
gpuDeviceBufferTypes
)
{
return
cpuDeviceBufferType
s
return
cpuDeviceBufferType
}
}
return
gpuDeviceBufferTypes
[
index
]
return
gpuDeviceBufferTypes
[
index
]
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment