blob: 11ba05e363dda1fe9a88014732b80734b7f62512 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package ai.vespa.llama;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import java.util.logging.Logger;
/**
* @author arnej
* Finds native libraries when the bundle is activated.
**/
public class LlamaBundleActivator implements BundleActivator {
private static final String PATH_PROPNAME = "de.kherud.llama.lib.path";
private static final Logger log = Logger.getLogger(LlamaBundleActivator.class.getName());
@Override
public void start(BundleContext ctx) {
log.fine("start bundle");
if (checkFilenames(
"/dev/nvidia0",
"/opt/vespa-deps/lib64/cuda/libllama.so",
"/opt/vespa-deps/lib64/cuda/libjllama.so")) {
System.setProperty(PATH_PROPNAME, "/opt/vespa-deps/lib64/cuda");
} else if (checkFilenames(
"/opt/vespa-deps/lib64/libllama.so",
"/opt/vespa-deps/lib64/libjllama.so")) {
System.setProperty(PATH_PROPNAME, "/opt/vespa-deps/lib64");
} else {
throw new IllegalArgumentException("Cannot find shared libraries");
}
}
@Override
public void stop(BundleContext ctx) {
log.fine("stop bundle");
}
private boolean checkFilenames(String... filenames) {
for (String fn : filenames) {
var f = new java.io.File(fn);
if (! f.canRead()) {
return false;
}
}
return true;
}
}
|