Files
d4r/tools/d4r_native_selection.h
T
ayo b645ef9096 Add DLSS accuracy mode and GLIBC 2.41 release builds
- Add default-off PreferAccuracy for all native kernel families,
  including RDNA4 FP8 variants.

- Restore intermediate FP8 quantization, per-MMA FP16 rounding,
  denormal handling and NGX synchronization in accuracy mode.

- Select separately marked accuracy kernels and use a separate JIT
  cache; reject mixed sets and never silently substitute fast kernels.

- Add a pinned GLIBC 2.41 build environment for ZLUDA/LLVM, the DLLs
  and both kernel sets, with ABI checks and toolchain provenance.

- Support parallel target builds and pre-extracted PTX; correct
  ROCm header paths and Clang-CL input handling.

- Bump to 0.1.3 and update release notes, documentation and tests.

Validation: 11 tests passed; all 912 kernels built; E/K/M GPU harness
runs completed with accuracy off/on. Packaged libraries loaded under
GLIBC 2.41 and require no GLIBC version newer than 2.38.

RTX image-quality parity remains unverified.

Fixes #6
Refs #6
2026-10-01 01:35:39 -04:00

92 lines
3.1 KiB
C

/* Native directory selection shared with the CPU-only configuration tests. */
#pragma once
#include <dirent.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
static int d4r_apply_accuracy_policy(void)
{
const char* prefer = getenv("D4R_PREFER_ACCURACY");
if (prefer == NULL || strcmp(prefer, "1") != 0)
return 0;
setenv("D4R_ZLUDA_IGNORE_DENORMAL", "0", 1);
setenv("D4R_ZLUDA_WMMA_F32ACC", "0", 1);
setenv("D4R_ZLUDA_FAST_MATH", "0", 1);
setenv("D4R_ZLUDA_WAVE64", "0", 1);
setenv("D4R_ELIDE_NGX_SYNC", "0", 1);
return 1;
}
static int d4r_accuracy_directory(const char* directory)
{
char path[1200], version[16];
if (snprintf(path, sizeof(path), "%s/d4r-accuracy.txt", directory) >= (int)sizeof(path))
return 0;
FILE* file = fopen(path, "r");
if (file == NULL)
return 0;
const int valid = fgets(version, sizeof(version), file) != NULL && strcmp(version, "1\n") == 0;
fclose(file);
return valid;
}
/* 1 = hash-checked set, 2 = unmanifested developer set, 0 = no usable set.
Accuracy mode never selects an unmarked directory, including flat legacy developer builds. */
static int d4r_native_candidate(const char* directory, int accuracy)
{
if (accuracy && !d4r_accuracy_directory(directory))
return 0;
char path[1200];
if (snprintf(path, sizeof(path), "%s/d4r-kernels.txt", directory) >= (int)sizeof(path))
return 0;
FILE* file = fopen(path, "r");
if (file != NULL)
{
fclose(file);
return 1;
}
return accuracy ? 2 : 0;
}
static int d4r_select_native_source(const char* configured, const char* architecture, int accuracy,
int fp8, char* source, size_t size)
{
char base[1024];
const int length = accuracy && !d4r_accuracy_directory(configured)
? snprintf(base, sizeof(base), "%s/accuracy", configured)
: snprintf(base, sizeof(base), "%s", configured);
if (length < 0 || length >= (int)sizeof(base))
return 0;
int kind;
if (fp8 && strncmp(architecture, "gfx12", 5) == 0)
{
if (snprintf(source, size, "%s/%s-fp8", base, architecture) >= (int)size)
return 0;
if ((kind = d4r_native_candidate(source, accuracy)) != 0)
return kind;
}
if (architecture[0] != '\0')
{
if (snprintf(source, size, "%s/%s", base, architecture) >= (int)size)
return 0;
if ((kind = d4r_native_candidate(source, accuracy)) != 0)
return kind;
}
if (snprintf(source, size, "%s", base) >= (int)size)
return 0;
if ((kind = d4r_native_candidate(source, accuracy)) != 0)
return kind;
if (accuracy)
return 0;
/* Keep legacy flat developer directories working, but do not hand a release root to ZLUDA. */
DIR* directory = opendir(base);
if (directory == NULL)
return 0;
int targets = 0;
for (struct dirent* entry; (entry = readdir(directory)) != NULL;)
targets += strncmp(entry->d_name, "gfx", 3) == 0;
closedir(directory);
return targets ? 0 : 2;
}