Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Numa #1556

Merged
merged 20 commits into from
Jun 26, 2023
Merged

Numa #1556

Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
avoid sending finalize op to thread pool if it does nothing
  • Loading branch information
zrm committed May 21, 2023
commit 9d058c2096b9f1f300e1ee16f5740a6a0a342917
10 changes: 8 additions & 2 deletions ggml.c
Original file line number Diff line number Diff line change
Expand Up @@ -3698,6 +3698,12 @@ static const char * GGML_OP_SYMBOL[GGML_OP_COUNT] = {
"f(x,y)",
};

// only send finalize op to thread pool if it actually does something
// currently none of them?
static const bool GGML_OP_HAS_FINALIZE[GGML_OP_COUNT] = {
0
};

static_assert(GGML_OP_COUNT == 51, "GGML_OP_COUNT != 51");

static_assert(sizeof(struct ggml_object)%GGML_MEM_ALIGN == 0, "ggml_object size must be a multiple of GGML_MEM_ALIGN");
Expand Down Expand Up @@ -14541,7 +14547,7 @@ void ggml_graph_compute(struct ggml_context * ctx, struct ggml_cgraph * cgraph)
}

// FINALIZE
if (node->n_tasks > 1) {
if (node->n_tasks > 1 && GGML_OP_HAS_FINALIZE[node->op]) {
if (atomic_fetch_add(&state_shared.n_ready, 1) == n_threads - 1) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: Dereference of null pointer [clang-analyzer-core.NullDereference]

+) {
                                       ^
Additional context

ggml.c:14165: Assuming 'n_threads' is <= 1

  };
                                               ^

ggml.c:14165: '?' condition is false

  };
                                               ^

ggml.c:14165: 'workers' initialized to a null pointer value

  };
         ^

ggml.c:14168: 'n_threads' is <= 1

pool
             ^

ggml.c:14168: Taking false branch

pool
         ^

ggml.c:14198: Assuming 'i' is < field 'n_nodes'

ions
                             ^

ggml.c:14198: Loop condition is true. Entering loop body

ions
             ^

ggml.c:14201: Control jumps to 'case GGML_OP_MAP_UNARY:' at line 14432

i];
                 ^

ggml.c:14435: Execution continues on line 14199

= 1;
                           ^

ggml.c:14198: Assuming 'i' is >= field 'n_nodes'

ions
                             ^

ggml.c:14198: Loop condition is false. Execution continues on line 14448

ions
             ^

ggml.c:14447: Assuming field 'work' is equal to NULL

  }
                 ^

ggml.c:14447: Left side of '&&' is false

  }
                                      ^

ggml.c:14451: 'work_size' is <= 0

  }
                 ^

ggml.c:14451: Left side of '&&' is false

  }
                               ^

ggml.c:14462: Loop condition is true. Entering loop body

();
         ^

ggml.c:14480: Field 'work' is null

sks,
                                      ^

ggml.c:14480: '?' condition is false

sks,
                              ^

ggml.c:14481: Field 'work' is null

: 0,
                                      ^

ggml.c:14481: '?' condition is false

: 0,
                              ^

ggml.c:14484: Calling 'ggml_compute_forward'

 };
             ^

ggml.c:12939: 'params' is non-null

r) {
                     ^

ggml.h:204: expanded from macro 'GGML_ASSERT'

        if (!(x)) { \
              ^

ggml.c:12939: Taking false branch

r) {
         ^

ggml.h:204: expanded from macro 'GGML_ASSERT'

        if (!(x)) { \
        ^

ggml.c:12939: Loop condition is false. Exiting loop

r) {
         ^

ggml.h:203: expanded from macro 'GGML_ASSERT'

    do { \
    ^

ggml.c:12941: Control jumps to 'case GGML_OP_MAP_UNARY:' at line 13138

s);
         ^

ggml.c:13140: Calling 'ggml_compute_forward_map_unary'

ta);
                     ^

ggml.c:12875: Control jumps to 'case GGML_TYPE_F32:' at line 12877

n) {
         ^

ggml.c:12878: Calling 'ggml_compute_forward_map_unary_f32'

   {
                     ^

ggml.c:12850: Taking false branch

n) {
         ^

ggml.h:204: expanded from macro 'GGML_ASSERT'

        if (!(x)) { \
        ^

ggml.c:12850: Loop condition is false. Exiting loop

n) {
         ^

ggml.h:203: expanded from macro 'GGML_ASSERT'

    do { \
    ^

ggml.c:12852: Field 'type' is equal to GGML_TASK_INIT

));
                     ^

ggml.c:12852: Left side of '||' is true

));
                                            ^

ggml.c:12853: Returning without writing to 'dst->op', which participates in a condition later

E) {
             ^

ggml.c:12878: Returning from 'ggml_compute_forward_map_unary_f32'

   {
                     ^

ggml.c:12879: Execution continues on line 12879

un);
                   ^

ggml.c:12887: Returning without writing to 'dst->op', which participates in a condition later

}
  ^

ggml.c:13140: Returning from 'ggml_compute_forward_map_unary'

ta);
                     ^

ggml.c:13142: Execution continues on line 13141

   }
                 ^

ggml.c:13160: Returning without writing to 'tensor->op', which participates in a condition later

}
  ^

ggml.c:14484: Returning from 'ggml_compute_forward'

 };
             ^

ggml.c:14487: Field 'n_tasks' is <= 1

PUTE
                       ^

ggml.c:14487: Taking false branch

PUTE
             ^

ggml.c:14520: Calling 'ggml_compute_forward'

UTE;
             ^

ggml.c:12939: 'params' is non-null

r) {
                     ^

ggml.h:204: expanded from macro 'GGML_ASSERT'

        if (!(x)) { \
              ^

ggml.c:12939: Taking false branch

r) {
         ^

ggml.h:204: expanded from macro 'GGML_ASSERT'

        if (!(x)) { \
        ^

ggml.c:12939: Loop condition is false. Exiting loop

r) {
         ^

ggml.h:203: expanded from macro 'GGML_ASSERT'

    do { \
    ^

ggml.c:12941: Control jumps to 'case GGML_OP_MAP_UNARY:' at line 13138

s);
         ^

ggml.c:13140: Calling 'ggml_compute_forward_map_unary'

ta);
                     ^

ggml.c:12875: Control jumps to 'case GGML_TYPE_F32:' at line 12877

n) {
         ^

ggml.c:12878: Value assigned to field 'op', which participates in a condition later

   {
                     ^

ggml.c:12879: Execution continues on line 12879

un);
                   ^

ggml.c:13140: Returning from 'ggml_compute_forward_map_unary'

ta);
                     ^

ggml.c:13142: Execution continues on line 13141

   }
                 ^

ggml.c:14520: Returning from 'ggml_compute_forward'

UTE;
             ^

ggml.c:14523: Assuming field 'n_tasks' is > 1

pool
                 ^

ggml.c:14523: Taking true branch

pool
             ^

ggml.c:14524: Assuming the condition is false

1) {
                     ^

/usr/lib/llvm-15/lib/clang/15.0.7/include/stdatomic.h:141: expanded from macro 'atomic_fetch_add'

#define atomic_fetch_add(object, operand) __c11_atomic_fetch_add(object, operand, __ATOMIC_SEQ_CST)
                                          ^

ggml.c:14524: Taking false branch

1) {
                 ^

ggml.c:14528: Loop condition is false. Execution continues on line 14534

  }
                 ^

ggml.c:14535: Loop condition is false. Execution continues on line 14543

1);
                 ^

ggml.c:14542: Field 'n_tasks' is > 1

LIZE
                       ^

ggml.c:14542: Left side of '&&' is true

LIZE
                 ^

ggml.c:14542: Assuming the condition is true

LIZE
                                      ^

ggml.c:14542: Taking true branch

LIZE
             ^

ggml.c:14543: Assuming the condition is false

]) {
                     ^

/usr/lib/llvm-15/lib/clang/15.0.7/include/stdatomic.h:141: expanded from macro 'atomic_fetch_add'

#define atomic_fetch_add(object, operand) __c11_atomic_fetch_add(object, operand, __ATOMIC_SEQ_CST)
                                          ^

ggml.c:14543: Taking false branch

]) {
                 ^

ggml.c:14547: Loop condition is false. Execution continues on line 14554

  }
                 ^

ggml.c:14553: Assuming the condition is true

pool
                                 ^

ggml.c:14553: Loop condition is true. Entering loop body

pool
                 ^

ggml.c:14558: Field 'work' is null

sks,
                                          ^

ggml.c:14558: '?' condition is false

sks,
                                  ^

ggml.c:14559: Field 'work' is null

: 0,
                                          ^

ggml.c:14559: '?' condition is false

: 0,
                                  ^

ggml.c:14554: Dereference of null pointer

+) {
                                       ^

atomic_store(&state_shared.has_work, false);
}
Expand Down Expand Up @@ -14577,7 +14583,7 @@ void ggml_graph_compute(struct ggml_context * ctx, struct ggml_cgraph * cgraph)
ggml_compute_forward(&params, node);

// wait for thread pool
if (node->n_tasks > 1) {
if (node->n_tasks > 1 && GGML_OP_HAS_FINALIZE[node->op]) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a good change

if (atomic_fetch_add(&state_shared.n_ready, 1) == n_threads - 1) {
atomic_store(&state_shared.has_work, false);
}
Expand Down