Explorar o código

fix compilation issue: undefined symbol for static variable when compiled with `-O0`

Summary: The symbol for Autotune::kCutoffLimit is undefined when compiled without optimization. It needs to be defined in the source file (.cc) instead of the header file.

Reviewed By: EdouardGrave

Differential Revision: D18931166

fbshipit-source-id: 1e63369dc728e898d9d5097294010f1e8ce850bf
Onur Çelebi %!s(int64=6) %!d(string=hai) anos
pai
achega
da2745fccc
Modificáronse 3 ficheiros con 16 adicións e 5 borrados
  1. 8 0
      .circleci/gcc_test.sh
  2. 6 3
      src/autotune.cc
  3. 2 2
      src/autotune.h

+ 8 - 0
.circleci/gcc_test.sh

@@ -15,3 +15,11 @@ make opt
 ./fasttext supervised -input "${DATADIR}/dbpedia.train" -output "${RESULTDIR}/dbpedia" -dim 10 -lr 0.1 -wordNgrams 2 -minCount 1 -bucket 10000000 -epoch 5 -thread 4 -verbose 0
 ./fasttext test "${RESULTDIR}/dbpedia.bin" "${DATADIR}/dbpedia.test"
 ./fasttext predict "${RESULTDIR}/dbpedia.bin" "${DATADIR}/dbpedia.test" > "${RESULTDIR}/dbpedia.test.predict"
+
+make clean
+make debug
+./fasttext supervised -input "${DATADIR}/dbpedia.train" -output "${RESULTDIR}/dbpedia" -dim 10 -lr 0.1 -wordNgrams 2 -minCount 1 -bucket 10000000 -epoch 5 -thread 4 -verbose 0
+./fasttext test "${RESULTDIR}/dbpedia.bin" "${DATADIR}/dbpedia.test"
+./fasttext predict "${RESULTDIR}/dbpedia.bin" "${DATADIR}/dbpedia.test" > "${RESULTDIR}/dbpedia.test.predict"
+
+

+ 6 - 3
src/autotune.cc

@@ -56,6 +56,9 @@ class ElapsedTimeMarker {
 
 namespace fasttext {
 
+constexpr double Autotune::kUnknownBestScore = -1.0;
+constexpr int Autotune::kCutoffLimit = 256;
+
 template <typename T>
 T getArgGauss(
     T val,
@@ -324,7 +327,7 @@ int Autotune::getCutoffForFileSize(
   int target = (fileSize - (107) - 4 * (1 << 8) * dim - outModelSize);
   int cutoff = target / ((dim + dsub - 1) / dsub + (qnorm ? 1 : 0) + 10);
 
-  return std::max(cutoff, kCutoffLimit);
+  return std::max(cutoff, Autotune::kCutoffLimit);
 }
 
 bool Autotune::quantize(Args& args, const Args& autotuneArgs) {
@@ -334,12 +337,12 @@ bool Autotune::quantize(Args& args, const Args& autotuneArgs) {
   auto outputSize = fastText_->getOutputMatrix()->size(0);
 
   args.qnorm = true;
-  args.qout = (outputSize >= kCutoffLimit);
+  args.qout = (outputSize >= Autotune::kCutoffLimit);
   args.retrain = true;
   args.cutoff = getCutoffForFileSize(
       args.qout, args.qnorm, args.dsub, autotuneArgs.getAutotuneModelSize());
   LOG_VAL(cutoff, args.cutoff);
-  if (args.cutoff == kCutoffLimit) {
+  if (args.cutoff == Autotune::kCutoffLimit) {
     return false;
   }
   fastText_->quantize(args);

+ 2 - 2
src/autotune.h

@@ -73,8 +73,8 @@ class Autotune {
     TimeoutError() : std::runtime_error("Autotune timed out.") {}
   };
 
-  static constexpr double kUnknownBestScore = -1.0;
-  static constexpr int kCutoffLimit = 256;
+  static const double kUnknownBestScore;
+  static const int kCutoffLimit;
 
  public:
   Autotune() = delete;