Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,13 @@ changes (where available).

### New Features

- N/A
- Added Lua AI API (`darktable.ai`) for scripting AI model inference.
Provides tensor creation, model loading with GPU provider selection,
and two calling conventions for inference (pre-allocated and
auto-allocated outputs). Image I/O includes loading from file or
darktable library (full pipeline export), raw CFA sensor data
access, and DNG output with EXIF preservation. Enables Lua scripts
to implement custom AI workflows such as raw denoise or upscale.

### Bug Fixes

Expand Down
1 change: 1 addition & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -792,6 +792,7 @@ if(USE_LUA)
if(USE_LUA)
add_definitions("-DUSE_LUA")
FILE(GLOB SOURCE_FILES_LUA
"lua/ai.c"
"lua/cairo.c"
"lua/call.c"
"lua/configuration.c"
Expand Down
15 changes: 15 additions & 0 deletions src/common/ai_models.c
Original file line number Diff line number Diff line change
Expand Up @@ -951,6 +951,8 @@ void dt_ai_models_cleanup(dt_ai_registry_t *registry)

g_mutex_clear(&registry->lock);

if(registry->env)
dt_ai_env_destroy(registry->env);
g_free(registry->repository);
g_free(registry->models_dir);
g_free(registry->cache_dir);
Expand Down Expand Up @@ -1931,6 +1933,19 @@ void dt_ai_model_card_free(dt_ai_model_card_t *card)
g_free(card);
}

dt_ai_environment_t *dt_ai_registry_get_env(dt_ai_registry_t *registry)
{
if(!registry || !registry->ai_enabled)
return NULL;

g_mutex_lock(&registry->lock);
if(!registry->env)
registry->env = dt_ai_env_init(NULL);
g_mutex_unlock(&registry->lock);

return registry->env;
}

// clang-format off
// modelines: These editor modelines have been set for all relevant files by tools/update_modelines.py
// vim: shiftwidth=2 expandtab tabstop=2 cindent
Expand Down
10 changes: 10 additions & 0 deletions src/common/ai_models.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ typedef struct dt_ai_registry_t
gboolean ai_enabled; // Global AI enable/disable
dt_ai_provider_t provider; // Selected execution provider
gboolean updates_checked; // TRUE after first check_updates call
struct dt_ai_environment_t *env; // Lazily created backend environment
GMutex lock; // Thread safety for registry access
} dt_ai_registry_t;

Expand Down Expand Up @@ -348,3 +349,12 @@ dt_ai_model_card_t *dt_ai_models_get_card(
* @brief Free a model card returned by dt_ai_models_get_card
*/
void dt_ai_model_card_free(dt_ai_model_card_t *card);

/**
* @brief Get or lazily create the AI backend environment.
* The environment is cached in the registry and destroyed
* by dt_ai_models_cleanup().
* @param registry The registry
* @return Environment handle, or NULL if AI is disabled
*/
dt_ai_environment_t *dt_ai_registry_get_env(dt_ai_registry_t *registry);
Loading