|
@@ -30,6 +30,20 @@
|
|
|
|
|
|
|
|
#define ASYNCIO_CONCURRENCY 64
|
|
#define ASYNCIO_CONCURRENCY 64
|
|
|
|
|
|
|
|
|
|
+// define prototypes
|
|
|
|
|
+void execute_command(const std::string& command, std::string& stdout_str, std::string& stderr_str);
|
|
|
|
|
+bool directory_exists(const std::string& path);
|
|
|
|
|
+bool create_directory(const std::string& path);
|
|
|
|
|
+std::string to_uppercase(const std::string& input);
|
|
|
|
|
+bool string_ends_with(const std::string& str, const std::string& suffix);
|
|
|
|
|
+std::string join_paths(const std::string& path1, const std::string& path2);
|
|
|
|
|
+std::string basename(const std::string &path);
|
|
|
|
|
+void string_to_spv(const std::string& _name, const std::string& in_fname, const std::map<std::string, std::string>& defines, bool fp16);
|
|
|
|
|
+std::map<std::string, std::string> merge_maps(const std::map<std::string, std::string>& a, const std::map<std::string, std::string>& b);
|
|
|
|
|
+void matmul_shaders(std::vector<std::future<void>>& tasks, bool fp16, bool matmul_id);
|
|
|
|
|
+void process_shaders(std::vector<std::future<void>>& tasks);
|
|
|
|
|
+void write_output_files();
|
|
|
|
|
+
|
|
|
std::mutex lock;
|
|
std::mutex lock;
|
|
|
std::vector<std::pair<std::string, std::string>> shader_fnames;
|
|
std::vector<std::pair<std::string, std::string>> shader_fnames;
|
|
|
|
|
|
|
@@ -38,7 +52,7 @@ std::string input_dir = "vulkan-shaders";
|
|
|
std::string output_dir = "/tmp";
|
|
std::string output_dir = "/tmp";
|
|
|
std::string target_hpp = "ggml-vulkan-shaders.hpp";
|
|
std::string target_hpp = "ggml-vulkan-shaders.hpp";
|
|
|
std::string target_cpp = "ggml-vulkan-shaders.cpp";
|
|
std::string target_cpp = "ggml-vulkan-shaders.cpp";
|
|
|
-bool no_clean = false;
|
|
|
|
|
|
|
+bool clean = true;
|
|
|
|
|
|
|
|
const std::vector<std::string> type_names = {
|
|
const std::vector<std::string> type_names = {
|
|
|
"f32",
|
|
"f32",
|
|
@@ -464,8 +478,9 @@ void write_output_files() {
|
|
|
}
|
|
}
|
|
|
fprintf(src, "\n};\n\n");
|
|
fprintf(src, "\n};\n\n");
|
|
|
|
|
|
|
|
- if (!no_clean) {
|
|
|
|
|
|
|
+ if (clean) {
|
|
|
std::remove(path.c_str());
|
|
std::remove(path.c_str());
|
|
|
|
|
+ // fprintf(stderr, "Removed: %s\n", path.c_str());
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -481,6 +496,18 @@ int main(int argc, char** argv) {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ if (argc <= 1 || args.find("--help") != args.end()) {
|
|
|
|
|
+ std::cout << "Usage:\n"
|
|
|
|
|
+ "\tvulkan-shaders-gen [options]\n\n"
|
|
|
|
|
+ "Options:\n"
|
|
|
|
|
+ "\t--glslc <path> Path to glslc executable (default: /usr/bin/glslc)\n"
|
|
|
|
|
+ "\t--input-dir Directory containing shader sources (required)\n"
|
|
|
|
|
+ "\t--output-dir Output directory for generated SPIR-V files and optional C++ headers\n"
|
|
|
|
|
+ "\t--target-hpp <path> Path to generate a header file with shader declarations in C++ format\n"
|
|
|
|
|
+ "\t--target-cpp <path> Path to generate a source code file implementing the declared shaders (optional)\n"
|
|
|
|
|
+ "\t--no-clean Keep temporary SPIR-V files after build (default: remove them)\n";
|
|
|
|
|
+ return EXIT_SUCCESS;
|
|
|
|
|
+ }
|
|
|
if (args.find("--glslc") != args.end()) {
|
|
if (args.find("--glslc") != args.end()) {
|
|
|
GLSLC = args["--glslc"]; // Path to glslc
|
|
GLSLC = args["--glslc"]; // Path to glslc
|
|
|
}
|
|
}
|
|
@@ -497,7 +524,7 @@ int main(int argc, char** argv) {
|
|
|
target_cpp = args["--target-cpp"]; // Path to generated cpp file
|
|
target_cpp = args["--target-cpp"]; // Path to generated cpp file
|
|
|
}
|
|
}
|
|
|
if (args.find("--no-clean") != args.end()) {
|
|
if (args.find("--no-clean") != args.end()) {
|
|
|
- no_clean = true; // Keep temporary SPIR-V files in output-dir after build
|
|
|
|
|
|
|
+ clean = false; // Keep temporary SPIR-V files in output-dir after build
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if (!directory_exists(input_dir)) {
|
|
if (!directory_exists(input_dir)) {
|