Skip to content

Commit 04351ab

Browse files
authored
Merge pull request #49 from Paulanerus/dev
Dev
2 parents c8a14c2 + d76fb61 commit 04351ab

File tree

13 files changed

+145
-63
lines changed

13 files changed

+145
-63
lines changed

api/build.gradle.kts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,4 @@ dependencies {
1313
implementation(kotlin("stdlib"))
1414

1515
implementation("com.fasterxml.jackson.core:jackson-annotations:${rootProject.extra["jackson.version"]}")
16-
}
17-
18-
kotlin {
19-
jvmToolchain(21)
2016
}

build.gradle.kts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
import org.gradle.kotlin.dsl.configure
12
import org.jetbrains.compose.desktop.application.dsl.TargetFormat
3+
import org.jetbrains.kotlin.gradle.dsl.KotlinJvmProjectExtension
24

35
plugins {
46
kotlin("jvm")
@@ -23,8 +25,12 @@ dependencies {
2325
implementation(project(":ui"))
2426
}
2527

26-
kotlin {
27-
jvmToolchain(21)
28+
allprojects {
29+
plugins.withId("org.jetbrains.kotlin.jvm") {
30+
extensions.configure<KotlinJvmProjectExtension> {
31+
jvmToolchain(21)
32+
}
33+
}
2834
}
2935

3036
compose.desktop {

core/build.gradle.kts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,4 @@ dependencies {
5252

5353
tasks.test {
5454
useJUnitPlatform()
55-
}
56-
57-
kotlin {
58-
jvmToolchain(21)
5955
}

core/src/main/kotlin/dev/paulee/core/data/FileService.kt

Lines changed: 38 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,16 @@ import org.slf4j.LoggerFactory.getLogger
88
import java.nio.file.Path
99
import kotlin.io.path.Path
1010
import kotlin.io.path.createDirectories
11+
import kotlin.io.path.listDirectoryEntries
1112
import kotlin.io.path.notExists
1213

1314
internal object FileService {
1415

15-
enum class OperatingSystem {
16+
enum class Platform {
1617
Windows, MacOS, Linux, Other;
1718

1819
companion object {
19-
val current: OperatingSystem by lazy {
20+
val current: Platform by lazy {
2021
val os = System.getProperty("os.name")?.lowercase() ?: return@lazy Other
2122

2223
when {
@@ -34,32 +35,47 @@ internal object FileService {
3435
val isLinux: Boolean get() = current == Linux
3536

3637
val isOther: Boolean get() = current == Other
37-
}
38-
}
3938

40-
val isCuda12xInstalled: Boolean by lazy {
41-
if (OperatingSystem.isMacOS) return@lazy false
39+
val isCuda12xInstalled: Boolean by lazy {
40+
if (isMacOS) return@lazy false
4241

43-
runCatching {
44-
val process = ProcessBuilder().apply {
45-
command("nvcc", "--version")
46-
redirectErrorStream(true)
47-
}.start()
42+
runCatching {
43+
val process = ProcessBuilder().apply {
44+
command("nvcc", "--version")
45+
redirectErrorStream(true)
46+
}.start()
4847

49-
val output = process.inputStream.bufferedReader().use { it.readText() }
50-
process.waitFor()
48+
val output = process.inputStream.bufferedReader().use { it.readText() }
49+
process.waitFor()
5150

52-
val versionRegex = Regex("""V(\d+)\.(\d+)\.(\d+)""")
53-
val matchResult = versionRegex.find(output)
51+
val versionRegex = Regex("""V(\d+)\.(\d+)\.(\d+)""")
52+
val matchResult = versionRegex.find(output)
5453

55-
if (matchResult != null) {
56-
val majorVersion = matchResult.groupValues[1].toIntOrNull() ?: 0
54+
if (matchResult != null) {
55+
val majorVersion = matchResult.groupValues[1].toIntOrNull() ?: 0
5756

58-
majorVersion == 12
59-
} else {
60-
false
57+
majorVersion == 12
58+
} else {
59+
false
60+
}
61+
}.getOrDefault(false)
6162
}
62-
}.getOrDefault(false)
63+
64+
val isCuDNNInstalled by lazy {
65+
if (isMacOS) return@lazy false
66+
67+
// This is a temporary solution until JDK 25 with FFM API can be used.
68+
return@lazy runCatching {
69+
if (isWindows) {
70+
System.getenv("PATH").contains("NVIDIA\\CUDNN\\v9")
71+
} else {
72+
val lib = Path("/usr/lib")
73+
74+
lib.listDirectoryEntries("libcudnn.so.9*").isNotEmpty()
75+
}
76+
}.getOrDefault(false)
77+
}
78+
}
6379
}
6480

6581
val appDir: Path get() = ensureDir(".textexplorer", true)
@@ -75,7 +91,7 @@ internal object FileService {
7591
private val mapper = jacksonObjectMapper().apply { enable(SerializationFeature.INDENT_OUTPUT) }
7692

7793
init {
78-
logger.info("Operating system: ${OperatingSystem.current} | CUDA: $isCuda12xInstalled")
94+
logger.info("Operating system: ${Platform.current} | CUDA: ${Platform.isCuda12xInstalled}, cuDNN: ${Platform.isCuDNNInstalled}")
7995
}
8096

8197
fun toJson(dataInfo: DataInfo): String? = runCatching { this.mapper.writeValueAsString(dataInfo) }

core/src/main/kotlin/dev/paulee/core/data/provider/EmbeddingProvider.kt

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -42,24 +42,31 @@ internal object EmbeddingProvider {
4242

4343
private val sessions = mutableMapOf<Embedding.Model, OrtSession?>()
4444

45-
private val availableProvider by lazy {
46-
OrtEnvironment.getAvailableProviders().orEmpty().mapNotNull { it }.toSet()
45+
private val availableProvider = OrtEnvironment.getAvailableProviders().orEmpty().mapNotNull { it }.toSet()
46+
47+
private val canCuda = with(FileService.Platform) {
48+
OrtProvider.CUDA in availableProvider && isCuda12xInstalled && isCuDNNInstalled
4749
}
4850

49-
private val options = OrtSession.SessionOptions().apply {
50-
setOptimizationLevel(OrtSession.SessionOptions.OptLevel.ALL_OPT)
51-
setMemoryPatternOptimization(true)
52-
setInterOpNumThreads(Runtime.getRuntime().availableProcessors())
53-
setIntraOpNumThreads(max(1, Runtime.getRuntime().availableProcessors() / 2))
51+
private val lazyOptions = lazy {
52+
runCatching {
53+
OrtSession.SessionOptions().apply {
54+
setOptimizationLevel(OrtSession.SessionOptions.OptLevel.ALL_OPT)
55+
setMemoryPatternOptimization(true)
56+
setInterOpNumThreads(Runtime.getRuntime().availableProcessors())
57+
setIntraOpNumThreads(max(1, Runtime.getRuntime().availableProcessors() / 2))
58+
59+
if (!FileService.Platform.isMacOS && canCuda) {
60+
logger.info("Selecting CUDA provider.")
61+
addCUDA()
62+
}
5463

55-
if (!FileService.OperatingSystem.isMacOS) {
56-
if (OrtProvider.CUDA in availableProvider && FileService.isCuda12xInstalled) {
57-
logger.info("Selecting CUDA provider.")
58-
addCUDA()
64+
addCPU(true)
5965
}
66+
}.getOrElse {
67+
logger.error("Failed to create session options.", it)
68+
null
6069
}
61-
62-
addCPU(true)
6370
}
6471

6572
private const val CACHE_SIZE = 60_000
@@ -241,7 +248,10 @@ internal object EmbeddingProvider {
241248

242249
sessions.values.forEach { it?.close() }
243250

244-
options.close()
251+
with(lazyOptions) {
252+
if (isInitialized())
253+
value?.close()
254+
}
245255

246256
env.close()
247257
}
@@ -394,10 +404,12 @@ internal object EmbeddingProvider {
394404
}
395405

396406
private fun createSession(model: Embedding.Model): OrtSession? {
407+
if (lazyOptions.value == null) return null
408+
397409
return runCatching {
398410
env.createSession(
399411
FileService.modelsDir.resolve(model.name).resolve(model.modelData.model).toString(),
400-
options
412+
lazyOptions.value
401413
)
402414
}.getOrElse {
403415
logger.error("Failed to create session for model ${model.name}", it)

docs/source/content/installation.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@ Both plugins and data sets can be loaded directly within the application, as doc
2020

2121
By default, the application runs embedding models for semantic queries on the CPU, which may result in longer loading times depending on the model, data size, and hardware. GPU acceleration generally reduces these loading times. Below is a list of supported platforms for GPU acceleration:
2222

23-
### NVIDIA GPUs
24-
GPU acceleration supported using CUDA. Requires CUDA 12.x installed. Available on Linux and Windows.
25-
For installation, see [CUDA Toolkit](https://developer.nvidia.com/cuda-downloads).
23+
### NVIDIA
24+
GPU acceleration supported using CUDA. Requires[ CUDA 12.x](https://developer.nvidia.com/cuda-toolkit-archive) and [cuDNN 9.x](https://developer.nvidia.com/cudnn) installed. Available on Linux and Windows.
25+
For installation, see [CUDA Installation Guide](https://docs.nvidia.com/cuda/cuda-installation-guide-microsoft-windows/index.html) and [Installing cuDNN Backend](https://docs.nvidia.com/deeplearning/cudnn/installation/latest/windows.html).
2626

27-
### AMD GPUs
27+
### AMD
2828
Currently not supported, but planned.
2929

30-
### Apple GPUs
30+
### Apple
3131
Not supported, no plans soon.

gradle.properties

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@ duckdb.version=1.4.0.0
1414
caffeine.version=3.2.2
1515

1616
api.version=1.13.1
17-
core.version=1.16.11
18-
ui.version=1.17.1
19-
app.version=1.5.1
17+
core.version=1.16.14
18+
ui.version=1.17.2
19+
app.version=1.5.2

plugins/demo/build.gradle.kts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,4 @@ tasks.jar {
2626
manifest{
2727
attributes["Main-Class"] = "dev.paulee.demo.DemoPlugin"
2828
}
29-
}
30-
31-
kotlin {
32-
jvmToolchain(21)
3329
}

ui/build.gradle.kts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,4 @@ dependencies {
2020

2121
implementation(compose.desktop.currentOs)
2222
implementation("org.jetbrains.compose.material:material-icons-core:${rootProject.extra["icons.version"]}")
23-
}
24-
25-
kotlin {
26-
jvmToolchain(21)
2723
}

ui/src/main/kotlin/dev/paulee/ui/TextExplorerUI.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ enum class Window {
4949
PluginInfo,
5050
Settings,
5151
ModelManagement,
52+
PoolManagement
5253
}
5354

5455
class TextExplorerUI(
@@ -208,6 +209,7 @@ class TextExplorerUI(
208209
"setting.load_data" -> openWindow = Window.LoadData
209210
"plugin.title" -> openWindow = Window.PluginInfo
210211
"model_management.title" -> openWindow = Window.ModelManagement
212+
"pools_management.title" -> openWindow = Window.PoolManagement
211213
"settings.title" -> openWindow = Window.Settings
212214
}
213215
}
@@ -680,6 +682,8 @@ class TextExplorerUI(
680682

681683
Window.ModelManagement -> ModelManagerWindow(dataService) { openWindow = Window.None }
682684

685+
Window.PoolManagement -> PoolManagerWindow(dataService) { openWindow = Window.None }
686+
683687
else -> {}
684688
}
685689
}

0 commit comments

Comments
 (0)