singa-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Wang Wei <wang...@comp.nus.edu.sg>
Subject Re: usage of SINGA
Date Tue, 07 Mar 2017 12:14:50 GMT
Hi Zhongle,

Did you ever encountered such error?
How did you resolve it?
Thanks.

regards,
Wei

On Tue, Mar 7, 2017 at 6:40 PM, Lee Hwee Kuan <leehk@bii.a-star.edu.sg>
wrote:

> hi
>
> thanks. i have a chance to try your suggestion.
>
> glog most probably is being used by other of my programs. i also may have
> multiple glog around, in /usr/local/lib as well as in /usr/local/Cellar
> (from Brew) and perhaps others.
>
> so i opt for option 2, link -lglog manually in my CMakeList.txt file.
> delete build directory, reinvoke "cmake ../“ and then make. howevery i got
> the same errors as before
> —————————
> 175 [100%] Linking CXX executable mytest
> 176 Undefined symbols for architecture x86_64:
> 177   "singa::logging::LogMessageFatal::LogMessageFatal(char const*,
> int)", referenced       from:
> 178       singa::Block::data() const in mytest.cc.o
> 179   "singa::logging::LogMessageFatal::~LogMessageFatal()", referenced
> from:
> 180       singa::Block::data() const in mytest.cc.o
> 181 ld: symbol(s) not found for architecture x86_64
> 182 clang: error: linker command failed with exit code 1 (use -v to see
> invocation)
> 183 make[2]: *** [mytest] Error 1
> 184 make[1]: *** [CMakeFiles/mytest.dir/all] Error 2
> 185 make: *** [all] Error 2
>
>
> hk
>
> On 7 Mar 2017, at 5:13 PM, Wang Wei <wangwei@comp.nus.edu.sg> wrote:
>
> It should be caused by glog. If you have gloged instlled, libsinga.so
> would link to libglog.
> There are 2 solutions:
> 1. uninstall glog and re-compile libsinga.so
> 2. add -lglog into your link flags when generating mytest.
>
> regards,
> wang wei
>
> On Tue, Mar 7, 2017 at 5:10 PM, Lee Hwee Kuan <leehk@bii.a-star.edu.sg>
> wrote:
>
>> Dear Wang Wei,
>>
>> i managed to assign values to Tensor object and compile. when i wish to
>> check if the values are correctly assigned, i found that i cannot link to
>> implementation of LogMessageFatal class. i try to dig at where is the
>> implementation and also change my CMakeLists.txt to manually link libraries
>> but unable to get it to work. line 15 of the mytest.cc leads to error,
>> try to call data() function and data() function calls block->data() which
>> leads to linking errors. may i know in which library you put
>> LogMessageFatal implementation at? I linked everything in
>> incubator-singa/build/lib directory. thanks again.
>>
>> below is cut-and-paste code segments of LogMessageFatal, compile errors,
>> mytest.cc and CMakeList.txt
>>
>> hk
>>
>>
>> /Users/hweekuan/incubator-singa/src/utils/logging.cc
>>
>> 112 LogMessage::~LogMessage() { GenerateLogMessage(); }
>> 113
>> 114 LogMessageFatal::LogMessageFatal(const char* file, int line)
>> 115   : LogMessage(file, line, FATAL) {}
>> 116 LogMessageFatal::~LogMessageFatal() {
>> 117   // abort() ensures we don't return
>> 118   GenerateLogMessage();
>> 119   abort();
>> 120 }
>>
>> ====================
>> hweekuans-MacBook-Pro:buid hweekuan$ make
>> [ 50%] *Linking CXX executable mytest*
>> Undefined symbols for architecture x86_64:
>>   "singa::logging::LogMessageFatal::LogMessageFatal(char const*, int)",
>> referenced from:
>>       singa::Block::data() const in mytest.cc.o
>>   "singa::logging::LogMessageFatal::~LogMessageFatal()", referenced from:
>>       singa::Block::data() const in mytest.cc.o
>> ld: symbol(s) not found for architecture x86_64
>> clang: error: linker command failed with exit code 1 (use -v to see
>> invocation)
>> make[2]: *** [mytest] Error 1
>> make[1]: *** [CMakeFiles/mytest.dir/all] Error 2
>> make: *** [all] Error 2
>>
>> ========================
>>   1 #include "singa/model/metric.h"
>>   2
>>   3 namespace singa {
>>   4
>>   5 void Train() {
>>   6
>>   7   const size_t train_size = 10;
>>   8   Tensor train_x(Shape{train_size,1});
>>   9   int tx[train_size];
>>  10
>>  11   for(unsigned int i=0;i<train_size;++i) { tx[i] = 1; }
>>  12   train_x.CopyDataFromHostPtr(tx,train_size);
>>  13
>>  14   // read back and see if this is correct
>>  15   const int * rx = train_x.data<int>(); // ## error generate from
>> this line
>>  16 //  train_x.GetValue(rx,train_size);
>>  17 }
>>  18 } // namespace singa
>>  19
>>  20 int main(int argc, char **argv) { singa::Train(); }
>>
>> =============================================
>>  19 CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
>>  20
>>  21 SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
>>  22
>>  23 INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR})
>>  24 INCLUDE_DIRECTORIES(${CMAKE_BINARY_DIR}/include)
>>  25 INCLUDE_DIRECTORIES(/Users/hweekuan/incubator-singa/include )
>>  26 INCLUDE_DIRECTORIES(/Users/hweekuan/incubator-singa/build/include )
>>  27
>>  28 # mannually set library to link
>>  29 SET( SINGA_LIB_PATH -L/Users/hweekuan/incubator-singa/build/lib/)
>>  30 SET( SINGA_LIB -lgtest -lopenblas -lopenblas -
>> lopenblas_haswellp-r0.2.16.dev
>>  31                -lprotobuf-lite -lprotobuf -lprotoc  -lsinga)
>>  32
>>  33 ADD_EXECUTABLE(mytest mytest.cc)
>>  34 TARGET_LINK_LIBRARIES(mytest ${SINGA_LIB_PATH} ${SINGA_LIB} )
>>  35
>>  36 # ------ commented out lines here -------------------
>>  37 #SET( PROJECT_LINK_LIBS singa )
>>  38 #LINK_DIRECTORIES( /Users/hweekuan/incubator-singa/build/lib )
>>  39 #ADD_DEPENDENCIES(mytest singa)
>>  40 #TARGET_LINK_LIBRARIES(mytest singa)
>>
>> ===========================
>>
>>
>>
>>
>> On 7 Mar 2017, at 9:35 AM, Wang Wei <wangwei@comp.nus.edu.sg> wrote:
>>
>> You can call http://www.comp.nus.edu.sg/~dbsystem/singa/api/classsinga_1_
>> 1Tensor.html#a6b940544ecf97e88d716af395b728a26
>> to assign a scalar value to each element.
>> Or randomly initialize a Tensor https://github.com/apache/incu
>> bator-singa/blob/master/include/singa/core/tensor.h#L409
>>
>> regards,
>> wang wei
>>
>>
>> On Tue, Mar 7, 2017 at 9:31 AM, Wang Wei <wangwei@comp.nus.edu.sg> wrote:
>>
>>> No. It won't work.
>>>
>>> You can do it in this way.
>>>
>>> int a[]= {1,2,3};
>>> A.CopyDataFromHostPtr(a, 3);
>>>
>>> On Tue, Mar 7, 2017 at 8:59 AM, Lee Hwee Kuan <leehk@bii.a-star.edu.sg>
>>> wrote:
>>>
>>>> May this piece of code will work? I will try it out. thanks.
>>>>
>>>> Tensor A(Shape{2,1})
>>>> int * a = A.data();
>>>> a[0] = 3;
>>>>
>>>>
>>>> 79  template <typename SType>
>>>> 80
>>>> <http://www.comp.nus.edu.sg/%7Edbsystem/singa/api/classsinga_1_1Tensor.html#afc729dc475752550d490203af973a2af>
>>>> const SType *data
>>>> <http://www.comp.nus.edu.sg/%7Edbsystem/singa/api/classsinga_1_1Tensor.html#afc729dc475752550d490203af973a2af>
>>>> () const {
>>>> 81  return static_cast<const SType *>(block
>>>> <http://www.comp.nus.edu.sg/%7Edbsystem/singa/api/classsinga_1_1Tensor.html#abc9c15cf8b1da26e310c79aa9e73460e>
>>>> ()->data());
>>>> 82  }
>>>>
>>>>
>>>> On 7 Mar 2017, at 8:55 AM, Lee Hwee Kuan <leehk@bii.a-star.edu.sg>
>>>> wrote:
>>>>
>>>> Dear Wang Wei,
>>>>
>>>> Thanks for walking me through this. I find some time to work on SINGA
>>>> code again and face new issues. I am trying to just make very simple train
>>>> data that could be feed into net.Train( ) function. I believe I will need
>>>> to use the Tensor class, I could not see how to assign values to the Tensor
>>>> object after looking at Tensor.h. Please see below. Thanks.
>>>>
>>>>
>>>>   1 // #include files and other headers . .  .
>>>>   2
>>>>   3 void Train() {
>>>>   4
>>>>   5   Tensor train_x, train_y;
>>>>   6   // make the simple training data
>>>>   7   Tensor raw_train(Shape{4,1});  // I want to set raw_train = { 1,
>>>> 2, 1, 2 }
>>>>   8   Tensor raw_label(Shape(4,1));  // I want to set raw_label = { 0,
>>>> 1, 0, 1 }
>>>>   9
>>>>  10   // how to input these values { 1, 2, 1, 2 } and { 0, 1, 0, 1}
>>>>  11   // into a Tensor?
>>>>  12
>>>>  13   train_x = raw_train;
>>>>  14   train_y = raw_label;
>>>>  15
>>>>  16   // some other code . . . then train the network
>>>>  17   //auto net = CreateNet();
>>>>  18   //net.Train(100, num_epoch, train_x, train_y, test_x, test_y);
>>>>  19 }
>>>>  20
>>>>  21 // ----------------------------------------------------------
>>>>  22 // comments:
>>>>  23 // Tensor.h file has GetValue and SetValue function, cut and paste
>>>> part of
>>>>  24 // that code here
>>>>  25 //
>>>>  26    79   template <typename SType>
>>>>  27    80   const SType *data() const {
>>>>  28    81     return static_cast<const SType *>(block()->data());
>>>>  29    82   }
>>>>  30    83
>>>>  31    86   template <typename SType>
>>>>  32    87   void GetValue(SType *value, const size_t num) {
>>>>  33    88     CHECK(device_ == defaultDevice);
>>>>  34    89     const SType* ptr = data<SType>();
>>>>  35    90     for(size_t i = 0; i < num; i++) value[i] = ptr[i];
>>>>  36    91   }
>>>>  37
>>>>  38 // no implementation of SetValue here, but I understood from
>>>>  39 // documentation that SetValue set all values of Tensor to a
>>>> constant x
>>>>  40 // which is not what I want
>>>>  41   138
>>>>  42   140   template <typename SType>
>>>>  43   141   void SetValue(const SType x);
>>>>  44   142
>>>>  45
>>>>
>>>>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message