Skip to content

Commit

Permalink
ggml: add CUDA backend to sched-issue
Browse files Browse the repository at this point in the history
  • Loading branch information
danbev committed Dec 17, 2024
1 parent 8b967b5 commit a9c7deb
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
7 changes: 6 additions & 1 deletion fundamentals/ggml/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ CXXFLAGS += -fopenmp
WHOLE_ARCHIVE = -Wl,--whole-archive ggml/build/src/libggml.a -Wl,--no-whole-archive
WHOLE_ARCHIVE += -Wl,--whole-archive ggml/build/src/libggml-base.a -Wl,--no-whole-archive
WHOLE_ARCHIVE += -Wl,--whole-archive ggml/build/src/libggml-cpu.a -Wl,--no-whole-archive
#WHOLE_ARCHIVE += -Wl,--whole-archive ggml/build/src/ggml-cuda/libggml-cuda.a -Wl,--no-whole-archive
WHOLE_ARCHIVE += -Wl,--whole-archive ggml/build/src/ggml-cuda/libggml-cuda.a -Wl,--no-whole-archive
else ifeq ($(OS),Darwin)
CFLAGS += -framework Metal -framework Foundation -framework MetalKit -framework Accelerate
CXXFLAGS += -framework Metal -framework Foundation -framework MetalKit -framework Accelerate
Expand Down Expand Up @@ -90,6 +90,11 @@ conv2d-sched-cuda: CUDA_FLAGS := -L${CUDA_DIR} -lcuda -lcublas -lculibos -lcudar
conv2d-sched-cuda: CC = $(CXX)
conv2d-sched-cuda: conv2d-sched

#.PHONY: sched-issue-cuda
sched-issue-cuda: CUDA_FLAGS := -L${CUDA_DIR} -lcuda -lcublas -lculibos -lcudart -lcublasLt
sched-issue-cuda: CC = $(CXX)
sched-issue-cuda: sched-issue

.PHONY: run-backend-vulkan
run-backend-vulkan: backend-vulkan
env GGML_VULKAN_DEVICE=1 ./bin/backend
Expand Down
8 changes: 8 additions & 0 deletions fundamentals/ggml/src/sched-issue.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ int main(int argc, char **argv) {
};
struct ggml_context* ctx = ggml_init(params);

size_t count = ggml_backend_reg_count();
printf("Number of backends registered: %ld\n", count);

// Tensors for the first graph (simulating the language model):
struct ggml_tensor* l_a = ggml_new_tensor_1d(ctx, GGML_TYPE_F32, 1);
ggml_set_input(l_a);
Expand All @@ -49,6 +52,11 @@ int main(int argc, char **argv) {

// Create a scheduler.
ggml_backend_t cpu_backend = ggml_backend_init_by_name("CPU", NULL);
ggml_backend_t cuda_backend = ggml_backend_init_by_name("CUDA0", NULL);
if (!cuda_backend) {
fprintf(stderr, "Failed to initialize CUDA backend. Did you forget to compile ggml with GGML_CUDA?\n");
return 1;
}

auto threadpool_params = ggml_threadpool_params_default(1);
auto threadpool = ggml_threadpool_new(&threadpool_params);
Expand Down

0 comments on commit a9c7deb

Please sign in to comment.