Skip to content

Commit

Permalink
Revert "opencl : no need to allocate cl_mem on heap (ggerganov#1612)"
Browse files Browse the repository at this point in the history
This reverts commit bb051d9.
  • Loading branch information
LostRuins committed May 31, 2023
1 parent 5645679 commit 4afa38e
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions ggml-opencl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -676,7 +676,7 @@ static void ggml_cl_mul_mat_f32(const ggml_tensor * src0, const ggml_tensor * sr
size_t d_size;
cl_mem d_X;
if (src0->backend == GGML_BACKEND_CL) {
d_X = (cl_mem) src0->data;
d_X = *(cl_mem*) src0->data;
} else {
d_X = ggml_cl_pool_malloc(sizeof(ggml_fp16_t) * x_ne, &x_size, CL_MEM_READ_ONLY);
}
Expand Down Expand Up @@ -753,7 +753,7 @@ static void ggml_cl_mul_mat_f16(const ggml_tensor * src0, const ggml_tensor * sr
size_t d_size;
cl_mem d_X;
if (src0->backend == GGML_BACKEND_CL) {
d_X = (cl_mem) src0->data;
d_X = *(cl_mem*) src0->data;
} else {
d_X = ggml_cl_pool_malloc(sizeof(ggml_fp16_t) * x_ne, &x_size, CL_MEM_READ_ONLY);
}
Expand Down Expand Up @@ -881,7 +881,7 @@ static void ggml_cl_mul_mat_q_f32(const ggml_tensor * src0, const ggml_tensor *
events.emplace_back();
CL_CHECK(ggml_cl_h2d_tensor_2d(queue, d_Q, 0, src0, i03, i02, events.data() + ev_idx++));
} else if (src0->backend == GGML_BACKEND_CL) {
d_Q = (cl_mem) src0->data;
d_Q = *(cl_mem*) src0->data;
} else {
GGML_ASSERT(false);
}
Expand Down Expand Up @@ -1029,13 +1029,14 @@ void ggml_cl_transform_tensor(ggml_tensor * tensor) {
const size_t q_sz = ggml_type_size(type) * ne0 * ne1 * ne2 * ne3 / ggml_blck_size(type);

size_t q_size;
cl_mem dst = ggml_cl_pool_malloc(q_sz, &q_size, CL_MEM_READ_ONLY);
cl_mem* dst = (cl_mem*) malloc(sizeof(cl_mem));
*dst = ggml_cl_pool_malloc(q_sz, &q_size, CL_MEM_READ_ONLY);

// copy tensor to device
for (int64_t i3 = 0; i3 < ne3; i3++) {
for (int64_t i2 = 0; i2 < ne2; i2++) {
int i = i3*ne2 + i2;
CL_CHECK(ggml_cl_h2d_tensor_2d(queue, dst, i*ne0*ne1, tensor, i3, i2, NULL));
CL_CHECK(ggml_cl_h2d_tensor_2d(queue, *dst, i*ne0*ne1, tensor, i3, i2, NULL));
}
}

Expand Down

0 comments on commit 4afa38e

Please sign in to comment.