fix race condition bug in non-inplace ggml_compute_forward_diag_mask_f32
memcpy needs to be synchronized across threads to avoid race conditions. => do it in INIT phase
This commit is contained in:
parent
60f8c361ca
commit
1e6b5bf111
1 changed files with 13 additions and 6 deletions
19
ggml.c
19
ggml.c
|
@ -10450,18 +10450,25 @@ static void ggml_compute_forward_diag_mask_f32(
|
||||||
assert(src1->type == GGML_TYPE_I32);
|
assert(src1->type == GGML_TYPE_I32);
|
||||||
assert(ggml_nelements(src1) == 2);
|
assert(ggml_nelements(src1) == 2);
|
||||||
|
|
||||||
if (params->type == GGML_TASK_INIT || params->type == GGML_TASK_FINALIZE) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const int ith = params->ith;
|
const int ith = params->ith;
|
||||||
const int nth = params->nth;
|
const int nth = params->nth;
|
||||||
|
|
||||||
const int n_past = ((int32_t *) src1->data)[0];
|
const int n_past = ((int32_t *) src1->data)[0];
|
||||||
const bool inplace = (bool)((int32_t *) src1->data)[1];
|
const bool inplace = (bool)((int32_t *) src1->data)[1];
|
||||||
|
|
||||||
if (!inplace) {
|
if (!inplace && (params->type == GGML_TASK_INIT)) {
|
||||||
ggml_compute_forward_dup_same_cont(params, src0, dst);
|
// memcpy needs to be synchronized across threads to avoid race conditions.
|
||||||
|
// => do it in INIT phase
|
||||||
|
GGML_ASSERT(ggml_nelements(dst) == ggml_nelements(src0));
|
||||||
|
GGML_ASSERT(ggml_is_contiguous(dst) && ggml_is_contiguous(src0));
|
||||||
|
memcpy(
|
||||||
|
((char *) dst->data),
|
||||||
|
((char *) src0->data),
|
||||||
|
ggml_nbytes(dst));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (params->type == GGML_TASK_INIT || params->type == GGML_TASK_FINALIZE) {
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: handle transposed/permuted matrices
|
// TODO: handle transposed/permuted matrices
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue