Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BIDMat as sbt libraryDependencies #29

Open
dreamflasher opened this issue May 7, 2015 · 12 comments
Open

BIDMat as sbt libraryDependencies #29

dreamflasher opened this issue May 7, 2015 · 12 comments

Comments

@dreamflasher
Copy link

sbt is the default way for dependency management in scala, even though BIDMat uses sbt itself it seems not to be possible to have BIDMat as an sbt reference.
Expected behaviour libraryDependencies += "edu.berkeley.bid" %% "BIDMat" % "1.0.2" is not working.

@malcolmgreaves
Copy link

Bump -- this is a problem for adoption.

@jcanny
Copy link
Contributor

jcanny commented Jul 15, 2015

There's a lot of work to make that work. We need to host BIDMat/BIDMach in a repo with all its native code dependencies compiled for each platform, which isnt too hard because we know how to build it. But we also need to get all of BIDMat's dependencies (and their native code) reliably hosted as well. That's the rubbing point.

We know this is important, we're just trying to budget our resources wisely on all of our priorities.

@malcolmgreaves
Copy link

Thank you for a response! Have you ruled out bintray? I hear it's a bit easier to put stuff there than in Sonatype.

@jcanny
Copy link
Contributor

jcanny commented Jul 16, 2015

Its not so much a problem to push a jar to sonatype. We need a mavenized jcuda for 0.7.0a which wasnt there until recently. I see its there now so it would be a good time to do this...

@tangyuq
Copy link

tangyuq commented Aug 1, 2016

Any update regarding this issue? In between, are there any documents on how to manually include BIDMat and/or BIDMach (along with its/their dependency) as libraries in a sbt project?

@xinleipan
Copy link
Member

@tangyuq Do you mean how to include the libraries of BIDMach/BIDMat? You can do this by writing "import BIDMach._" and "import BIDMach.dependencies" (the same for BIDMat), and then in the root folder directory type in "./sbt package". Then it should be OK. Hope it helps.

@tangyuq
Copy link

tangyuq commented Aug 2, 2016

@xinleipan

I have my own sbt project, say under the folder MyPractice.

  1. I copy all the BIDMat/lib/* to MyPractice/lib/
  2. My build.sbt:

name := "MyPractice"

version := "0.1"

scalaVersion := "2.11.8"

//scalaVersion := "2.10.3" //for some reason 2.10.3 will report missing dependency on cuda libraries as I am using CPU only version

resolvers += "Typesafe Repo" at "http://repo.typesafe.com/typesafe/releases/"

//...other dependency

  1. In my main file:
    package ScratchPractice.BIDMatPractice
    import BIDMat.{SBMat, CMat, CSMat, DMat, Dict, IDict, FMat, HMat, IMat, Mat, SMat, SDMat}
    import BIDMat.MatFunctions._
    import BIDMat.SciFunctions._
    import BIDMat.Solvers._

object BasicBIDMat {
def main(args: Array[String]) {
val a = rand(3000,3000)
val b = a*a;
}
}

  1. run sbt:

runMain ScratchPractice.BIDMatPractice.BasicBIDMat
Got the error:
Running ScratchPractice.BIDMatPractice.BasicBIDMat
0.40857 0.46985 0.73041 0.73059 0.97158 0.0050249 0.23612 0.39407 0.88620 0.10853 0.23605 0.059405 0.072903 0.24985 0.76655 0.35533 0.97935 0.12887...
0.82198 0.88560 0.62665 0.89901 0.70573 0.19389 0.44033 0.12269 0.30396 0.41130 0.061355 0.67393 0.82517 0.018485 0.99806 0.89467 0.37737 0.58714...
0.13365 0.35648 0.42906 0.46898 0.66782 0.56183 0.97848 0.28216 0.62547 0.33921 0.36478 0.74682 0.66214 0.26247 0.75434 0.62846 0.78409 0.47058...
.. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. ..

error java.lang.UnsatisfiedLinkError: edu.berkeley.bid.CBLAS.sgemm(IIIIIIF[FI[FIF[FI)V
java.lang.UnsatisfiedLinkError: edu.berkeley.bid.CBLAS.sgemm(IIIIIIF[FI[FIF[FI)V
at edu.berkeley.bid.CBLAS.sgemm(Native Method)
at BIDMat.FMat.fDMult(FMat.scala:391)
at BIDMat.FMat.$times(FMat.scala:1435)
at ScratchPractice.BIDMatPractice.BasicBIDMat$.main(BasicBIDMat.scala:15)
at ScratchPractice.BIDMatPractice.BasicBIDMat.main(BasicBIDMat.scala)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
[trace] Stack trace suppressed: run last compile:runMain for the full output.
java.lang.RuntimeException: Nonzero exit code: 1
at scala.sys.package$.error(package.scala:27)

Am I missing anything? Running the same two lines from ./bidmat, there are no errors. I've copied the whole bidmat script to my project to start sbt (only replace the last step with sbt) to set up the same environment as bidmat hoping that this can resolve the linking errors.

It would nice if there is an explicit list of setting to make this work. For example,

  1. Copy the compiled BIDMat.jar to ${YourPorject}/lib
    Copy additional non-public jars to ${YourPorject}/lib
  2. Add to build.sbt:
    //The public repositories that contains the dependency jars required by BIDmat
    resolvers += "Typesafe Repo" at "http://repo.typesafe.com/typesafe/releases/" //and/or others
libraryDependencies += ... //public available dependencies
  1. Set up for sbt , e.g.
    export LD_LIBRARY_PATH=${SomePath}/lib/cuda:${SomePath}/code/QSML/lib:/usr/local/cuda/lib64: export JAVA_NATIVE=${SomePath}//lib/cuda:${SomePath}//code/QSML/lib:/usr/local/cuda/lib64:/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib:
    other environment variables

  2. Set up for Eclipse (along with sbt eclipse): ...

ps. If this post contains too much information, please feel free to delete it.

@tangyuq
Copy link

tangyuq commented Aug 3, 2016

After some struggle, I resolved the issue by adding the following two lines for initialization before calling any major BIDMat operations:
Mat.checkMKL(true)
Mat.checkCUDA(true)

It would nice to document these steps to include BIDMat as dependency in a standalone project ( it is possible that I might have missed such document somewhere).

@tangyuq
Copy link

tangyuq commented Aug 3, 2016

Before the official public package of BIDMat becomes available, in case it is useful for others, here is my little note on how to manually include BIDMat as dependency in a stand-alone sbt project (e.g. $YourProject) in the Linux environment:

  1. cp $BIDMat/lib/_.jar $YourProject/lib (create $YourProject/lib if it does not exist)
  2. cp $BIDMat/lib/_.so $YourProject/natives (create $YourProject/natives if it does not exist)
  3. In your Scala code,
    a) import the following and other packages if necessary:
    import BIDMat.{SBMat, CMat, CSMat, DMat, Dict, IDict, FMat, HMat, IMat, Mat, SMat, SDMat}
    import BIDMat.MatFunctions._
    import BIDMat.SciFunctions._
    import BIDMat.Solvers._
    b) Before using any BIDMat operators, initialize BIDMat by calling the following lines:
    Mat.checkMKL(true) //set the boolean flag depending on your choice
    Mat.checkCUDA(true) //set the boolean flag depending on your choice
  4. For sbt:
    a) using command line: sbt -Djava.library.path=./natives
    b) OR add to build.sbt (for fork := True:
    javaOptions += s"""-Djava.library.path=${baseDirectory.value / "natives"}"""
  5. OR set environment variable:
    export LD_LIBRARY_PATH="${YourProject}/natives":$LD_LIBRARY_PATH
  6. In Eclipse:
    a) add a line:
    -Djava.library.path=c:/code/BIDMach/lib
    to eclipse.ini
    b) OR open the project property, in "Java Build Path", in scala or java's "Native Library Location", add ${YourProject}/natives
    (See installation notes of BIDMat)
  7. Note that if CUDA is used, the CUDA 7.0 library path should also be added into "java.library.path" or the eclipse "Native Library Location" or the "LD_LIBRARY_PATH"
    (See installation notes of BIDMat)

@jcanny
Copy link
Contributor

jcanny commented Aug 18, 2016

We now have support for BIDMat/BIDMach as maven dependencies. That's designed to make it easy to build with Apache Spark. sbt doesnt pick up the dependency correctly however. If you have any idea how to fix this please let us know.

An sbt dependency of:
libraryDependencies += "BIDMat" % "BIDMat" % "1.1.0-cuda7.5"

Will correctly find the BIDMat pom, but when it looks for the BIDMat jar it incorrectly resolves it to:
https://dl.bintray.com/biddata/BIDData/BIDMat_2.11/1.1.0-cuda7.5/BIDMat-1.1.0-cuda7.5.jar

But our maven repository is set up with this path:
https://dl.bintray.com/biddata/BIDData/BIDMat/1.1.0-cuda7.5/BIDMat-1.1.0-cuda7.5.jar

And if we change the artifact id to "BIDMat_2.11", we get the still-mismatched jar path:
https://dl.bintray.com/biddata/BIDData/BIDMat_2.11/1.1.0-cuda7.5/BIDMat_2.11-1.1.0-cuda7.5.jar

There may be some way to make both maven and sbt happy with some overrides in the maven directory hierarchy, but for now only maven is working.

@jcanny
Copy link
Contributor

jcanny commented Aug 18, 2016

Another problem is that bintray recently (starting on 8/15/2016) to reject maven artifacts with underscores "_" in the path names. So there is no way to deploy and artifact with BIDMat_2.11 in the path name.

@Ajk4
Copy link

Ajk4 commented Sep 16, 2016

@jcanny

Will correctly find the BIDMat pom, but when it looks for the BIDMat jar it incorrectly resolves it to:
https://dl.bintray.com/biddata/BIDData/BIDMat_2.11/1.1.0-cuda7.5/BIDMat-1.1.0-cuda7.5.jar

But our maven repository is set up with this path:
https://dl.bintray.com/biddata/BIDData/BIDMat/1.1.0-cuda7.5/BIDMat-1.1.0-cuda7.5.jar

And if we change the artifact id to "BIDMat_2.11", we get the still-mismatched jar path:
https://dl.bintray.com/biddata/BIDData/BIDMat_2.11/1.1.0-cuda7.5/BIDMat_2.11-1.1.0-cuda7.5.jar

From my experiments it seems like it is because Organization name is the same as Module name.

If I'd manualy replace

libraryDependencies += "BIDMat" % "BIDMat" % "1.1.0-cuda7.5"

with

libraryDependencies += "BIDMat-OTHER_NAME" % "BIDMat" % "1.1.0-cuda7.5"

the link resolves correctly without 2_11 in it.

Perhaps you could change your organization name?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants