[Application] Bug fix about meson setting
authorSeungbaek Hong <sb92.hong@samsung.com>
Fri, 7 Jun 2024 08:44:10 +0000 (17:44 +0900)
committerMyungJoo Ham <myungjoo.ham@samsung.com>
Fri, 21 Jun 2024 05:51:12 +0000 (14:51 +0900)
Now, PICO GPT and LLAMA are adding extra_defines meson option in the application side.

However, even if this code is executed during build, this definition is not reflected when actually running the app.

Because the application area is built after the process of reflecting extra_defines to add_project_arguments has already been completed, so adding extra_defines during application build is meaningless.

In addition, it is impossible to call add_project_arguments after build, so the structure to add extra_defines during build process is wrong.

The reason why PICO GPT and LLAMA add extra_defines is that the encoder-related script created now does not run on tizen, so encoder-related option was added to the root meson and the options on the application side were removed.

**Self evaluation:**
1. Build test:     [X]Passed [ ]Failed [ ]Skipped
2. Run test:     [X]Passed [ ]Failed [ ]Skipped

Signed-off-by: Seungbaek Hong <sb92.hong@samsung.com>
Applications/LLaMA/jni/main.cpp
Applications/LLaMA/jni/meson.build
Applications/PicoGPT/jni/main.cpp
Applications/PicoGPT/jni/meson.build
meson.build

index c90cb7430552623d6dc61e231ed635b2e4e59579..4b63511bd6907fbb44c40f4ecb2adaa48a95277e 100644 (file)
@@ -31,7 +31,7 @@
 #include <swiglu.h>
 #include <transpose_layer.h>
 
-#if defined(ENABLE_ENCODER2)
+#if defined(DENABLE_ENCODER)
 #include "json.hpp"
 #include <codecvt>
 #include <encoder.hpp>
@@ -573,7 +573,7 @@ void run(std::string text, bool apply_temperature) {
 
   unsigned int init_len;
 
-#if defined(ENABLE_ENCODER2)
+#if defined(DENABLE_ENCODER)
   std::string vocab_file_name = "../Applications/LLaMA/jni/vocab.json";
   std::string merge_file_name = "../Applications/LLaMA/jni/merges.txt";
 
@@ -620,7 +620,7 @@ void run(std::string text, bool apply_temperature) {
   std::cout << " Progress Reading: 100 % " << std::endl;
   std::cout << std::endl << "### Output : " << std::endl;
   if (init_len < INIT_SEQ_LEN) {
-#if defined(ENABLE_ENCODER2)
+#if defined(DENABLE_ENCODER)
     auto decoded_str = tokenizer.decode({static_cast<int64_t>(ids)});
     std::cout << decoded_str << " ";
     std::cout.flush();
@@ -636,7 +636,7 @@ void run(std::string text, bool apply_temperature) {
       input_sample[0] = static_cast<float>(init_input[i]);
     } else {
       input_sample[0] = static_cast<float>(ids);
-#if defined(ENABLE_ENCODER2)
+#if defined(DENABLE_ENCODER)
       auto decoded_str = tokenizer.decode({static_cast<int64_t>(ids)});
       std::cout << decoded_str << " ";
       std::cout.flush();
@@ -685,7 +685,7 @@ void createAndRun(unsigned int epochs, unsigned int batch_size) {
   g_model->load(weight_path);
 }
 
-#if defined(ENABLE_ENCODER2)
+#if defined(DENABLE_ENCODER)
 std::wstring decodeUnicodeEscape(const std::wstring &input) {
   std::wstringstream result;
 
@@ -713,7 +713,7 @@ int main(int argc, char *argv[]) {
   // Setting locale
   std::locale::global(std::locale("ko_KR.UTF-8"));
 
-#if defined(ENABLE_ENCODER2)
+#if defined(DENABLE_ENCODER)
   // Getting arguments From terminal
   std::wstring input;
   std::getline(std::wcin, input);
index 9e6b02dbf94ade10eb7f35fca5fdd61b9b688563..1db8aecbfff9087db36ed0da10421771d4aa5999 100644 (file)
@@ -13,7 +13,6 @@ transpose_dep = declare_dependency(
 )
 
 if get_option('platform') != 'tizen'
-   extra_defines += '-DENABLE_ENCODER2=1'
    run_command(meson.source_root() / 'jni' / 'prepare_encoder.sh', meson.build_root(), '0.2' ,check: true)
 endif
 
index 30eace3946b896df08038c23958c9447d6761f2a..32a1d4889ec891b094503141e0794aa495a850c4 100644 (file)
@@ -17,7 +17,7 @@
 #include <string.h>
 #include <tensor.h>
 
-#if defined(ENABLE_ENCODER)
+#if defined(DENABLE_ENCODER)
 #include "encoder.hpp"
 #endif
 
@@ -43,7 +43,7 @@ bool optimize = false;
 // bool optimize = true;
 bool optimize_attention = false;
 
-#if defined(ENABLE_ENCODER)
+#if defined(DENABLE_ENCODER)
 template <typename T>
 T unwrap(std::optional<T> &&value, const std::string &error_msg) {
   if (value.has_value()) {
@@ -318,7 +318,7 @@ int main(int argc, char *argv[]) {
 
     std::vector<int64_t> init_input;
 
-#if defined(ENABLE_ENCODER)
+#if defined(DENABLE_ENCODER)
 
     std::string vocab_file_name = "../Applications/PicoGPT/jni/vocab.json";
     std::string merge_file_name = "../Applications/PicoGPT/jni/merges.txt";
@@ -372,7 +372,7 @@ int main(int argc, char *argv[]) {
 
       ((uint *)(wpe_input))[0] = i;
 
-#if defined(ENABLE_ENCODER)
+#if defined(DENABLE_ENCODER)
       std::vector<int64_t> token_ids;
       for (auto element : ids) {
         token_ids.push_back(static_cast<int64_t>(element));
index e542d05b3604b3559f700ea430a9a3ed5b9c57c6..b16cd9e8d9e1928301e26de378e2dcbb8940250f 100644 (file)
@@ -3,7 +3,6 @@ nntr_pico_gpt_resdir = nntr_app_resdir / 'PicoGPT'
 run_command('cp', '-lr', res_path, nntr_pico_gpt_resdir)
 
 if get_option('platform') != 'tizen'
-    extra_defines += '-DENABLE_ENCODER=1'
     run_command(meson.source_root() / 'jni' / 'prepare_encoder.sh', meson.build_root(), '0.1' , check: true)
 endif
 
index 0eedb1b83ddaebc7e484c569863bd61a76704571..2c2e6add3d7bad6991e623cd6a271f22d3f79e77 100644 (file)
@@ -34,6 +34,8 @@ if get_option('platform') == 'tizen'
   if get_option('enable-tizen-feature-check')
     add_project_arguments('-D__FEATURE_CHECK_SUPPORT__', language: ['c', 'cpp'])
   endif
+elif get_option('platform') == 'android'
+  add_project_arguments('-DENABLE_ENCODER=1', language: ['c', 'cpp'])
 endif
 
 warning_flags = [