From 39cd59caec8a66aa3e31205a6c0ca9d4daca82f5 Mon Sep 17 00:00:00 2001 From: austinvhuang Date: Sun, 3 Mar 2024 10:33:29 -0500 Subject: [PATCH] [WIP] create skeleton for example frontend application --- examples/look/CMakeLists.txt | 45 ++++++++++++++++++++++++++++++++++ examples/look/build/.gitignore | 0 examples/look/run.cc | 28 +++++++++++++++++++++ 3 files changed, 73 insertions(+) create mode 100644 examples/look/CMakeLists.txt create mode 100644 examples/look/build/.gitignore create mode 100644 examples/look/run.cc diff --git a/examples/look/CMakeLists.txt b/examples/look/CMakeLists.txt new file mode 100644 index 0000000..8666ce7 --- /dev/null +++ b/examples/look/CMakeLists.txt @@ -0,0 +1,45 @@ +# Copyright 2019 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +cmake_minimum_required(VERSION 3.11) + +project(look) + +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD_REQUIRED ON) + +include(FetchContent) + +FetchContent_Declare(highway GIT_REPOSITORY https://github.com/google/highway.git GIT_TAG da250571a45826b21eebbddc1e50d0c1137dee5f) +FetchContent_MakeAvailable(highway) + +FetchContent_Declare(sentencepiece GIT_REPOSITORY https://github.com/google/sentencepiece GIT_TAG 53de76561cfc149d3c01037f0595669ad32a5e7c) +FetchContent_MakeAvailable(sentencepiece) + +FetchContent_Declare(gemma GIT_REPOSITORY https://github.com/google/gemma.cpp.git GIT_TAG 808dbdc42b216c3ac1f1c40dfa638bcff24bbd2b) +FetchContent_MakeAvailable(gemma) + +if(NOT CMAKE_BUILD_TYPE) + set(CMAKE_BUILD_TYPE "Release") +endif() + +add_executable(look run.cc) +target_sources(look PRIVATE ${SOURCES}) +set_property(TARGET look PROPERTY CXX_STANDARD 17) +target_link_libraries(look hwy hwy_contrib sentencepiece libgemma) +target_include_directories(look PRIVATE ./) +FetchContent_GetProperties(sentencepiece) +target_include_directories(look PRIVATE ${sentencepiece_SOURCE_DIR}) +target_compile_definitions(look PRIVATE $<$:_CRT_SECURE_NO_WARNINGS NOMINMAX>) +target_compile_options(look PRIVATE $<$:-Wno-deprecated-declarations>) diff --git a/examples/look/build/.gitignore b/examples/look/build/.gitignore new file mode 100644 index 0000000..e69de29 diff --git a/examples/look/run.cc b/examples/look/run.cc new file mode 100644 index 0000000..85b0da4 --- /dev/null +++ b/examples/look/run.cc @@ -0,0 +1,28 @@ +#include + +// copybara:import_next_line:gemma_cpp +#include "compression/compress.h" +// copybara:end +// copybara:import_next_line:gemma_cpp +#include "gemma.h" // Gemma +// copybara:end +// copybara:import_next_line:gemma_cpp +#include "util/app.h" +// copybara:end +// copybara:import_next_line:gemma_cpp +#include "util/args.h" // HasHelp +// copybara:end +#include "hwy/base.h" +#include "hwy/contrib/thread_pool/thread_pool.h" +#include "hwy/highway.h" +#include "hwy/per_target.h" +#include "hwy/profiler.h" +#include "hwy/timer.h" + +int main(int argc, char** argv) { + gcpp::LoaderArgs loader(argc, argv); + gcpp::AppArgs app(argc, argv); + hwy::ThreadPool pool(app.num_threads); + gcpp::Gemma model(loader, pool); + std::cout << "Done" << std::endl; +}