Skip to content

Commit 4730fac

Browse files
teleprint-me0cc4m
andauthored
chore : Fix vulkan related compiler warnings, add help text, improve CLI options (#8477)
* chore: Fix compiler warnings, add help text, improve CLI options * Add prototypes for function definitions * Invert logic of --no-clean option to be more intuitive * Provide a new help prompt with clear instructions * chore : Add ignore rule for vulkan shader generator Signed-off-by: teleprint-me <77757836+teleprint-me@users.noreply.github.com> * Update ggml/src/vulkan-shaders/vulkan-shaders-gen.cpp Co-authored-by: 0cc4m <picard12@live.de> * chore : Remove void and apply C++ style empty parameters * chore : Remove void and apply C++ style empty parameters --------- Signed-off-by: teleprint-me <77757836+teleprint-me@users.noreply.github.com> Co-authored-by: 0cc4m <picard12@live.de>
1 parent 4c676c8 commit 4730fac

File tree

2 files changed

+31
-3
lines changed

2 files changed

+31
-3
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ build*
5050
!docs/build.md
5151
/libllama.so
5252
/llama-*
53+
/vulkan-shaders-gen
5354
android-ndk-*
5455
arm_neon.h
5556
cmake-build-*

ggml/src/vulkan-shaders/vulkan-shaders-gen.cpp

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,20 @@
3030

3131
#define ASYNCIO_CONCURRENCY 64
3232

33+
// define prototypes
34+
void execute_command(const std::string& command, std::string& stdout_str, std::string& stderr_str);
35+
bool directory_exists(const std::string& path);
36+
bool create_directory(const std::string& path);
37+
std::string to_uppercase(const std::string& input);
38+
bool string_ends_with(const std::string& str, const std::string& suffix);
39+
std::string join_paths(const std::string& path1, const std::string& path2);
40+
std::string basename(const std::string &path);
41+
void string_to_spv(const std::string& _name, const std::string& in_fname, const std::map<std::string, std::string>& defines, bool fp16);
42+
std::map<std::string, std::string> merge_maps(const std::map<std::string, std::string>& a, const std::map<std::string, std::string>& b);
43+
void matmul_shaders(std::vector<std::future<void>>& tasks, bool fp16, bool matmul_id);
44+
void process_shaders(std::vector<std::future<void>>& tasks);
45+
void write_output_files();
46+
3347
std::mutex lock;
3448
std::vector<std::pair<std::string, std::string>> shader_fnames;
3549

@@ -38,7 +52,7 @@ std::string input_dir = "vulkan-shaders";
3852
std::string output_dir = "/tmp";
3953
std::string target_hpp = "ggml-vulkan-shaders.hpp";
4054
std::string target_cpp = "ggml-vulkan-shaders.cpp";
41-
bool no_clean = false;
55+
bool clean = true;
4256

4357
const std::vector<std::string> type_names = {
4458
"f32",
@@ -464,8 +478,9 @@ void write_output_files() {
464478
}
465479
fprintf(src, "\n};\n\n");
466480

467-
if (!no_clean) {
481+
if (clean) {
468482
std::remove(path.c_str());
483+
// fprintf(stderr, "Removed: %s\n", path.c_str());
469484
}
470485
}
471486

@@ -481,6 +496,18 @@ int main(int argc, char** argv) {
481496
}
482497
}
483498

499+
if (argc <= 1 || args.find("--help") != args.end()) {
500+
std::cout << "Usage:\n"
501+
"\tvulkan-shaders-gen [options]\n\n"
502+
"Options:\n"
503+
"\t--glslc <path> Path to glslc executable (default: /usr/bin/glslc)\n"
504+
"\t--input-dir Directory containing shader sources (required)\n"
505+
"\t--output-dir Output directory for generated SPIR-V files and optional C++ headers\n"
506+
"\t--target-hpp <path> Path to generate a header file with shader declarations in C++ format\n"
507+
"\t--target-cpp <path> Path to generate a source code file implementing the declared shaders (optional)\n"
508+
"\t--no-clean Keep temporary SPIR-V files after build (default: remove them)\n";
509+
return EXIT_SUCCESS;
510+
}
484511
if (args.find("--glslc") != args.end()) {
485512
GLSLC = args["--glslc"]; // Path to glslc
486513
}
@@ -497,7 +524,7 @@ int main(int argc, char** argv) {
497524
target_cpp = args["--target-cpp"]; // Path to generated cpp file
498525
}
499526
if (args.find("--no-clean") != args.end()) {
500-
no_clean = true; // Keep temporary SPIR-V files in output-dir after build
527+
clean = false; // Keep temporary SPIR-V files in output-dir after build
501528
}
502529

503530
if (!directory_exists(input_dir)) {

0 commit comments

Comments
 (0)