Skip to content
Merged
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
7 changes: 5 additions & 2 deletions ggml/src/ggml-webgpu/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,11 @@ file(MAKE_DIRECTORY ${SHADER_OUTPUT_DIR})

message(STATUS "Shader output dir: ${SHADER_OUTPUT_DIR}")

# Find all WGSL files
file(GLOB WGSL_SHADER_FILES "${SHADER_DIR}/*.wgsl")
# Find all WGSL sources
file(GLOB WGSL_SHADER_FILES
"${SHADER_DIR}/*.wgsl"
"${SHADER_DIR}/*.tmpl"
)

# Generate the header using a Python script
add_custom_command(
Expand Down
659 changes: 347 additions & 312 deletions ggml/src/ggml-webgpu/ggml-webgpu-shader-lib.hpp

Large diffs are not rendered by default.

416 changes: 224 additions & 192 deletions ggml/src/ggml-webgpu/ggml-webgpu.cpp

Large diffs are not rendered by default.

44 changes: 37 additions & 7 deletions ggml/src/ggml-webgpu/pre_wgsl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,33 @@ static std::string trim(const std::string & s) {
}

static std::string trim_value(std::istream & is) {
std::string str;
std::getline(is, str);
return trim(str);
std::ostringstream ss;
ss << is.rdbuf();
return trim(ss.str());
}

static bool isIdentChar(char c) {
return std::isalnum(static_cast<unsigned char>(c)) || c == '_';
}

static bool endsWithContinuation(const std::string & line) {
size_t i = line.size();
while (i > 0 && std::isspace((unsigned char) line[i - 1])) {
i--;
}
return i > 0 && line[i - 1] == '\\';
}

static void stripContinuation(std::string & line) {
size_t i = line.size();
while (i > 0 && std::isspace((unsigned char) line[i - 1])) {
i--;
}
if (i > 0 && line[i - 1] == '\\') {
line.erase(i - 1);
}
}

static std::string expandMacrosRecursiveInternal(const std::string & line,
const std::unordered_map<std::string, std::string> & macros,
std::unordered_set<std::string> & visiting);
Expand Down Expand Up @@ -595,19 +613,31 @@ class Preprocessor {
std::string line;

while (std::getline(in, line)) {
std::string t = trim(line);
std::string logical = line;
std::string t = trim(logical);
if (!t.empty() && t[0] == '#') {
while (endsWithContinuation(logical)) {
stripContinuation(logical);
if (!std::getline(in, line)) {
break;
}
logical += "\n";
logical += line;
}
t = trim(logical);
}

if (!t.empty() && t[0] == '#') {
bool handled = handleDirective(t, out, macros, predefined_macros, cond, include_stack, mode);
if (mode == DirectiveMode::IncludesOnly && !handled) {
out << line << "\n";
out << logical << "\n";
}
} else {
if (mode == DirectiveMode::IncludesOnly) {
out << line << "\n";
out << logical << "\n";
} else if (condActive(cond)) {
// Expand macros in the line before outputting
std::string expanded = expandMacrosRecursive(line, macros);
std::string expanded = expandMacrosRecursive(logical, macros);
out << expanded << "\n";
}
}
Expand Down
Loading
Loading