Skip to content

Commit 81110c2

Browse files
authored
Merge pull request #15 from baileyheading/macos-metal
Adds support for MacOS Arm CPU builds
2 parents 2b1fe51 + d7d535f commit 81110c2

File tree

3 files changed

+21
-7
lines changed

3 files changed

+21
-7
lines changed

CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ if (GGML_CUBLAS)
1414
add_definitions(-DGGML_USE_CUBLAS)
1515
endif()
1616

17+
if (GGML_METAL)
18+
add_definitions(-DGGML_USE_METAL)
19+
set(GGML_METAL_EMBED_LIBRARY ON CACHE BOOL "Embed Metal library")
20+
endif()
21+
1722
add_subdirectory(ggml)
1823

1924
target_link_libraries(tortoise PUBLIC ggml)

README.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,14 @@ git clone --recursive https://github.com/balisujohn/tortoise.cpp.git
1010
# Compiling
1111
For now, CUDA and CPU only. To compile:
1212

13-
## Compile for CPU
13+
## Compile for CPU (works on Linux x86 and Mac ARM)
1414
````
1515
mkdir build
1616
cd build
1717
cmake ..
1818
make
1919
````
20+
This is tested with mac os arm
2021

2122
## Compile for CUDA
2223
````
@@ -27,6 +28,14 @@ make
2728
````
2829
This is tested with Ubuntu 22.04 and cuda 12.0 and a 1070ti
2930

31+
## Compile for Mac OS with metal (work in-progress)
32+
````
33+
mkdir build
34+
cd build
35+
cmake .. -DGGML_METAL=ON
36+
make
37+
````
38+
3039
# Running
3140

3241
**Only lowercase letters, spaces, and punctuation are supported in the prompt.**

main.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -656,7 +656,7 @@ bool autoregressive_model_load(const std::string &fname,
656656

657657
#ifdef GGML_USE_METAL
658658
fprintf(stderr, "%s: using Metal backend\n", __func__);
659-
ggml_metal_log_set_callback(ggml_log_callback_default, nullptr);
659+
// ggml_metal_log_set_callback(ggml_log_callback_default, nullptr);
660660
model.backend = ggml_backend_metal_init();
661661
if (!model.backend) {
662662
fprintf(stderr, "%s: ggml_backend_metal_init() failed\n", __func__);
@@ -822,7 +822,7 @@ bool autoregressive_model_load(const std::string &fname,
822822
}
823823

824824
int32_t nelements = 1;
825-
int32_t ne[2] = {1, 1};
825+
int32_t ne[4] = {1, 1, 1, 1};
826826
for (int i = 0; i < n_dims; ++i) {
827827
fin.read(reinterpret_cast<char *>(&ne[i]), sizeof(ne[i]));
828828
nelements *= ne[i];
@@ -1218,7 +1218,7 @@ bool diffusion_model_load(const std::string &fname, diffusion_model &model) {
12181218

12191219
#ifdef GGML_USE_METAL
12201220
fprintf(stderr, "%s: using Metal backend\n", __func__);
1221-
ggml_metal_log_set_callback(ggml_log_callback_default, nullptr);
1221+
// ggml_metal_log_set_callback(ggml_log_callback_default, nullptr);
12221222
model.backend = ggml_backend_metal_init();
12231223
if (!model.backend) {
12241224
fprintf(stderr, "%s: ggml_backend_metal_init() failed\n", __func__);
@@ -1559,7 +1559,7 @@ bool diffusion_model_load(const std::string &fname, diffusion_model &model) {
15591559
}
15601560

15611561
int32_t nelements = 1;
1562-
int32_t ne[2] = {1, 1};
1562+
int32_t ne[4] = {1, 1, 1, 1};
15631563
for (int i = 0; i < n_dims; ++i) {
15641564
fin.read(reinterpret_cast<char *>(&ne[i]), sizeof(ne[i]));
15651565
nelements *= ne[i];
@@ -1782,7 +1782,7 @@ bool vocoder_model_load(const std::string &fname, vocoder_model &model) {
17821782

17831783
#ifdef GGML_USE_METAL
17841784
fprintf(stderr, "%s: using Metal backend\n", __func__);
1785-
ggml_metal_log_set_callback(ggml_log_callback_default, nullptr);
1785+
// ggml_metal_log_set_callback(ggml_log_callback_default, nullptr);
17861786
model.backend = ggml_backend_metal_init();
17871787
if (!model.backend) {
17881788
fprintf(stderr, "%s: ggml_backend_metal_init() failed\n", __func__);
@@ -1946,7 +1946,7 @@ bool vocoder_model_load(const std::string &fname, vocoder_model &model) {
19461946
}
19471947

19481948
int32_t nelements = 1;
1949-
int32_t ne[2] = {1, 1};
1949+
int32_t ne[4] = {1, 1, 1, 1};
19501950
for (int i = 0; i < n_dims; ++i) {
19511951
fin.read(reinterpret_cast<char *>(&ne[i]), sizeof(ne[i]));
19521952
nelements *= ne[i];

0 commit comments

Comments
 (0)