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

ggml : change ggml_graph_compute() API to not require context #1999

Merged
merged 20 commits into from
Jul 7, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
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
llama : fix duplicate symbols + refactor example benchmark
  • Loading branch information
ggerganov committed Jul 6, 2023
commit 9c9bdaf0b8e9e3d04c0caa83a7722a14b629e475
38 changes: 14 additions & 24 deletions examples/benchmark/benchmark-matmult.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,17 @@
#pragma warning(disable: 4244 4267) // possible loss of data
#endif

void ggml_graph_compute_helper(std::vector<uint8_t> & buf, ggml_cgraph * graph, int n_threads) {
struct ggml_cplan plan = ggml_graph_plan(graph, n_threads);

if (plan.work_size > 0) {
buf.resize(plan.work_size);
plan.work_data = buf.data();
}

ggml_graph_compute(graph, &plan);
}

float tensor_sum_elements(const ggml_tensor * tensor) {
float sum = 0;
if (tensor->type==GGML_TYPE_F32) {
Expand Down Expand Up @@ -166,14 +177,7 @@ int main(int argc, char ** argv) {

std::vector<uint8_t> work_buffer;

{
ggml_cplan pf = ggml_graph_plan(&gf, benchmark_params.n_threads);
if (pf.work_size > 0) {
work_buffer.resize(pf.work_size);
pf.work_data = work_buffer.data();
}
ggml_graph_compute(&gf, &pf);
}
ggml_graph_compute_helper(work_buffer, &gf, benchmark_params.n_threads);

TENSOR_DUMP(gf.nodes[0]);

Expand Down Expand Up @@ -227,14 +231,7 @@ int main(int argc, char ** argv) {

long long int start = ggml_time_us();
//printf("Running ggml_graph_compute\n");
{
ggml_cplan pf31 = ggml_graph_plan(&gf31, benchmark_params.n_threads);
if (pf31.work_size > 0) {
work_buffer.resize(pf31.work_size);
pf31.work_data = work_buffer.data();
}
ggml_graph_compute(&gf31, &pf31);
}
ggml_graph_compute_helper(work_buffer, &gf31, benchmark_params.n_threads);

long long int stop = ggml_time_us();
long long int usec = stop-start;
Expand Down Expand Up @@ -267,14 +264,7 @@ int main(int argc, char ** argv) {
}

// Running a different graph computation to make sure we override the CPU cache lines
{
ggml_cplan pf32 = ggml_graph_plan(&gf32, benchmark_params.n_threads);
if (pf32.work_size > 0) {
work_buffer.resize(pf32.work_size);
pf32.work_data = work_buffer.data();
}
ggml_graph_compute(&gf32, &pf32);
}
ggml_graph_compute_helper(work_buffer, &gf32, benchmark_params.n_threads);
}
printf("\n");
printf("Average%78.2f\n",gflops_sum/((double)benchmark_params.n_iterations));
Expand Down
2 changes: 1 addition & 1 deletion llama.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ void llama_nop(struct ggml_tensor * tensor) { // don't offload by default
// ggml helpers
//

void ggml_graph_compute_helper(std::vector<uint8_t> & buf, ggml_cgraph * graph, int n_threads) {
static void ggml_graph_compute_helper(std::vector<uint8_t> & buf, ggml_cgraph * graph, int n_threads) {
struct ggml_cplan plan = ggml_graph_plan(graph, n_threads);

if (plan.work_size > 0) {
Expand Down
Loading