Skip to content

Commit 8215a77

Browse files
fix multiple cards and signle card
1 parent a6f7096 commit 8215a77

File tree

3 files changed

+13
-16
lines changed

3 files changed

+13
-16
lines changed

ggml-sycl.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5893,6 +5893,8 @@ GGML_CALL static void ggml_backend_sycl_set_tensor_async(ggml_backend_t backend,
58935893

58945894
GGML_ASSERT(buf->buft == ggml_backend_sycl_buffer_type(sycl_ctx->device) && "unsupported buffer type");
58955895
const queue_ptr stream = sycl_ctx->stream(sycl_ctx->device, 0);
5896+
printf("zjy ggml_backend_sycl_set_tensor_async sycl_ctx->device=%d stream=%p\n", sycl_ctx->device, stream);
5897+
58965898
SYCL_CHECK(CHECK_TRY_ERROR((stream)->memcpy(
58975899
(char *)tensor->data + offset, data, size).wait()));
58985900
}
@@ -6156,22 +6158,17 @@ static ggml_guid_t ggml_backend_sycl_guid() {
61566158

61576159
GGML_CALL ggml_backend_t ggml_backend_sycl_init(int device_id) {
61586160
GGML_SYCL_DEBUG("[SYCL] call ggml_backend_sycl_init, device_id=%d\n", device_id);
6159-
printf("zjy ggml_backend_sycl_init 1\n");
61606161
check_allow_device_id(device_id);
6161-
printf("zjy ggml_backend_sycl_init 2\n");
61626162
ggml_backend_sycl_context * ctx = new ggml_backend_sycl_context(ggml_sycl_info(), device_id);
6163-
printf("zjy ggml_backend_sycl_init 3\n");
61646163
if (ctx == nullptr) {
61656164
fprintf(stderr, "%s: error: failed to allocate context\n", __func__);
61666165
return nullptr;
61676166
};
6168-
printf("zjy ggml_backend_sycl_init 3\n");
61696167
ggml_backend_t sycl_backend = new ggml_backend {
61706168
/* .guid = */ ggml_backend_sycl_guid(),
61716169
/* .interface = */ ggml_backend_sycl_interface,
61726170
/* .context = */ ctx
61736171
};
6174-
printf("zjy ggml_backend_sycl_init 4\n");
61756172
return sycl_backend;
61766173
}
61776174

ggml-sycl/common.hpp

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ static void crash() {
128128
"Meet error in this line code!"); \
129129
} while (0)
130130

131+
131132
#if DPCT_COMPAT_RT_VERSION >= 11100
132133
#define GGML_SYCL_ASSUME(x) __builtin_assume(x)
133134
#else
@@ -241,22 +242,24 @@ class sycl_device_mgr {
241242

242243
sycl::queue * create_queue_for_device(sycl::context &ctx, sycl::device &device) {
243244
dpct::select_device(dpct::dev_mgr::instance().get_device_id(device));
244-
printf("zjy create_queue_for_device 1\n");
245245
auto res = dpct::get_current_device().create_queue(ctx, device);
246-
printf("zjy create_queue_for_device 4\n");
247246
return res;
248247
}
249248

250249
sycl::queue * create_queue_for_device_id(int device_id) {
251-
printf("zjy create_queue_for_device_id 0 ctxs.size()=%d\n", ctxs.size());
252-
253-
sycl::context ctx=ctxs[device_id];
254-
printf("zjy create_queue_for_device_id 1\n");
250+
int i = get_device_index(device_id);
251+
sycl::context ctx=ctxs[i];
255252
sycl::device device = dpct::dev_mgr::instance().get_device(device_id);;
256-
printf("zjy create_queue_for_device_id 2\n");
257253
return create_queue_for_device(ctx, device);
258254
}
259255

256+
int get_device_index(int device_id) {
257+
for (int i = 0; i < device_ids.size(); i++) {
258+
if (device_ids[i] == device_id) return i;
259+
}
260+
return -1;
261+
}
262+
260263
void create_context_for_devices() {
261264
for (int i = 0; i < device_ids.size(); i++) {
262265
sycl::context ctx = sycl::context(devices[i]);
@@ -552,10 +555,9 @@ struct ggml_backend_sycl_context {
552555
explicit ggml_backend_sycl_context(struct ggml_sycl_device_info &sycl_device_info, int device_id) :
553556
device(device_id),
554557
name(GGML_SYCL_NAME + std::to_string(device)) {
555-
printf("zjy ggml_backend_sycl_context 1\n");
556558
for (int i=0;i<GGML_SYCL_MAX_STREAMS; i++){
557-
printf("zjy ggml_backend_sycl_context 2 i=%d id=%d\n", i, device_id );
558559
qptrs[device_id][i] = sycl_device_info.device_mgr->create_queue_for_device_id(device_id);
560+
printf("zjy ggml_backend_sycl_context sycl_ctx->device=%d i=%d stream=%p\n", device_id, i, qptrs[device_id][i]);
559561
}
560562
}
561563

ggml-sycl/dpct/helper.hpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -891,9 +891,7 @@ namespace dpct
891891
void select_device(unsigned int id)
892892
{
893893
std::lock_guard<std::recursive_mutex> lock(m_mutex);
894-
printf("zjy create_queue_for_device 2\n");
895894
check_id(id);
896-
printf("zjy create_queue_for_device 3\n");
897895
_thread2dev_map[get_tid()] = id;
898896
}
899897
unsigned int device_count() { return _devs.size(); }

0 commit comments

Comments
 (0)