ggml-webgpu: FlashAttention refactor + standardize quantization support (#23834)
* Start work on flash_attn refactor * Refactor * Split k/v quantization * Refactor and abstract quantization logic for flash_attn and mul_mat * Add quantization support to tile path * formatting * Move to functions, add a check
This commit is contained in:
@@ -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);
|
||||
@@ -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";
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user