BIDData / BIDMach

CPU and GPU-accelerated Machine Learning Library
BSD 3-Clause "New" or "Revised" License
916 stars 168 forks source link

exec a program in command #18

Closed maydaygmail closed 9 years ago

maydaygmail commented 9 years ago

I write a src/main/scala/exp/lrexp.scala file: //////////////////////////////////// package exp

import BIDMat.{CMat,CSMat,DMat,Dict,IDict,Image,FMat,FND,GMat,GIMat,GSMat,HMat,IMat,Mat,SMat,SBMat,SDMat} import BIDMat.MatFunctions. import BIDMat.SciFunctions. import BIDMat.Solvers. import BIDMat.Plotting. import BIDMach.Learner import BIDMach.models.{FM,GLM,KMeans,KMeansw,LDA,LDAgibbs,Model,NMF,SFA} import BIDMach.datasources.{DataSource,MatDS,FilesDS,SFilesDS} import BIDMach.mixins.{CosineSim,Perplexity,Top,L1Regularizer,L2Regularizer} import BIDMach.updaters.{ADAGrad,Batch,BatchNorm,IncMult,IncNorm,Telescoping} import BIDMach.causal.{IPTW}

object LRExp { def main(args:Array[String]) = { println("LRExp") val a = grand(20,30) println(a) } } ///////////////////////////////////////

./sbt package
generate a jar

and then typing ./sbt "runMain exp.LRExp"

println("LRExp") can be executed successfully

then appear errors: error java.lang.UnsatisfiedLinkError: Could not load the native library. [error] Error while loading native library "bidmatmkl-linux-x86_64" with base name "bidmatmkl" [error] Operating system name: Linux [error] Architecture : amd64 [error] Architecture bit size: 64 [error] Stack trace from the attempt to load the library as a resource: [error] java.lang.NullPointerException: No resource found with name '/lib/libbidmatmkl-linux-x86_64.so' [error] at jcuda.LibUtils.loadLibraryResource(LibUtils.java:149)

however, in interactive shells, scala scripts can run successfully:

  1. ./bidmach
  2. val a = grand(20,30)

how can I run the program in a command not in interactive? Thanks!

jcanny commented 9 years ago

You can run scripts directly from the command line:

bidmach mycommands.scala

the behavior is the same as calling ":load" from the scala prompt. You dont need to create a main method (it wont be called unless you do it in the script), just give a list of expressions to be eval'ed.

If you really want to use your own jar, you can put it in /lib and edit /bidmach to include your jar in "$ALL_LIBS". Then do

bidmach -e expression

to invoke a class from your jar (its a complete expression so can include arguments). There are examples of both approaches in /scripts/*.sh

We dont use sbt to run BIDMach/BIDMat since they both require native path setting which I think is out of sbt's reach (as a pure java application).