const uint row = gl_WorkGroupID.x + gl_NumWorkGroups.x * gl_WorkGroupID.z;
const uint tid = gl_LocalInvocationID.x;
+ // There are not enough cols to use all threads
+ if (tid >= p.ncols) {
+ return;
+ }
+
+ const uint block_size = min(p.ncols, BLOCK_SIZE);
+
uint a_offset, b_offset, d_offset;
get_offsets(a_offset, b_offset, d_offset);
tmp[tid] = FLOAT_TYPE(0.0f);
- [[unroll]] for (uint i = 0; i < p.ncols/BLOCK_SIZE; i += 2) {
- const uint col = i*BLOCK_SIZE + 2*tid;
+ [[unroll]] for (uint i = 0; i < p.ncols/block_size; i += 2) {
+ const uint col = i*block_size + 2*tid;
const uint ib = (row*p.ncols + col)/QUANT_K; // block index
const uint iqs = (col%QUANT_K)/QUANT_R; // quant index
const uint iybs = col - col%QUANT_K; // y block start index
// sum up partial sums and write back result
barrier();
- [[unroll]] for (uint s = BLOCK_SIZE/2; s > 0; s >>= 1) {
+ [[unroll]] for (uint s = block_size/2; s > 0; s >>= 1) {
if (tid < s) {
tmp[tid] += tmp[tid + s];
}
#ifdef _WIN32
#include <windows.h>
#include <direct.h> // For _mkdir on Windows
+ #include <algorithm> // For std::replace on w64devkit
#else
#include <unistd.h>
#include <sys/wait.h>
return std::equal(suffix.rbegin(), suffix.rend(), str.rbegin());
}
-#ifdef _WIN32
- static const char path_separator = '\\';
-#else
- static const char path_separator = '/';
-#endif
+static const char path_separator = '/';
std::string join_paths(const std::string& path1, const std::string& path2) {
return path1 + path_separator + path2;
std::string out_fname = join_paths(output_dir, name + ".spv");
std::string in_path = join_paths(input_dir, in_fname);
- std::vector<std::string> cmd = {GLSLC, "-fshader-stage=compute", "--target-env=vulkan1.2", "-O", in_path, "-o", out_fname};
+ #ifdef _WIN32
+ std::vector<std::string> cmd = {GLSLC, "-fshader-stage=compute", "--target-env=vulkan1.2", "-O", "\"" + in_path + "\"", "-o", "\"" + out_fname + "\""};
+ #else
+ std::vector<std::string> cmd = {GLSLC, "-fshader-stage=compute", "--target-env=vulkan1.2", "-O", in_path, "-o", out_fname};
+ #endif
for (const auto& define : defines) {
cmd.push_back("-D" + define.first + "=" + define.second);
}
for (const auto& pair : shader_fnames) {
const std::string& name = pair.first;
- const std::string& path = pair.second;
+ #ifdef _WIN32
+ std::string path = pair.second;
+ std::replace(path.begin(), path.end(), '/', '\\' );
+ #else
+ const std::string& path = pair.second;
+ #endif
+
FILE* spv = fopen(path.c_str(), "rb");
if (!spv) {
- std::cerr << "Error opening SPIR-V file: " << path << "\n";
+ std::cerr << "Error opening SPIR-V file: " << path << " (" << strerror(errno) << ")\n";
continue;
}
size_t read_size = fread(data.data(), 1, size, spv);
fclose(spv);
if (read_size != size) {
- std::cerr << "Error reading SPIR-V file: " << path << "\n";
+ std::cerr << "Error reading SPIR-V file: " << path << " (" << strerror(errno) << ")\n";
continue;
}