integrated new version of clblast kernels as a separate file
This commit is contained in:
parent
017023e477
commit
cee8042793
5 changed files with 591 additions and 170 deletions
4
Makefile
4
Makefile
|
@ -218,6 +218,8 @@ ggml_clblast.o: ggml.c ggml.h
|
||||||
$(CC) $(CFLAGS) $(BONUSCFLAGS1) $(BONUSCFLAGS2) $(CLBLAST_FLAGS) -c $< -o $@
|
$(CC) $(CFLAGS) $(BONUSCFLAGS1) $(BONUSCFLAGS2) $(CLBLAST_FLAGS) -c $< -o $@
|
||||||
ggml-opencl.o: ggml-opencl.c ggml-opencl.h
|
ggml-opencl.o: ggml-opencl.c ggml-opencl.h
|
||||||
$(CC) $(CFLAGS) -c $< -o $@
|
$(CC) $(CFLAGS) -c $< -o $@
|
||||||
|
ggml-opencl-legacy.o: ggml-opencl-legacy.c ggml-opencl-legacy.h
|
||||||
|
$(CC) $(CFLAGS) -c $< -o $@
|
||||||
|
|
||||||
#extreme old version compat
|
#extreme old version compat
|
||||||
ggml_v1.o: otherarch/ggml_v1.c otherarch/ggml_v1.h
|
ggml_v1.o: otherarch/ggml_v1.c otherarch/ggml_v1.h
|
||||||
|
@ -262,7 +264,7 @@ koboldcpp_noavx2: ggml_noavx2.o ggml_v1_noavx2.o expose.o common.o gpttype_adapt
|
||||||
koboldcpp_openblas_noavx2: ggml_openblas_noavx2.o ggml_v1_noavx2.o expose.o common.o gpttype_adapter.o
|
koboldcpp_openblas_noavx2: ggml_openblas_noavx2.o ggml_v1_noavx2.o expose.o common.o gpttype_adapter.o
|
||||||
$(OPENBLAS_NOAVX2_BUILD)
|
$(OPENBLAS_NOAVX2_BUILD)
|
||||||
|
|
||||||
koboldcpp_clblast: ggml_clblast.o ggml_v1.o expose.o common.o gpttype_adapter.o ggml-opencl.o
|
koboldcpp_clblast: ggml_clblast.o ggml_v1.o expose.o common.o gpttype_adapter.o ggml-opencl.o ggml-opencl-legacy.o
|
||||||
$(CLBLAST_BUILD)
|
$(CLBLAST_BUILD)
|
||||||
|
|
||||||
quantize_llama: examples/quantize/quantize.cpp ggml.o llama.o
|
quantize_llama: examples/quantize/quantize.cpp ggml.o llama.o
|
||||||
|
|
426
ggml-opencl-legacy.c
Normal file
426
ggml-opencl-legacy.c
Normal file
|
@ -0,0 +1,426 @@
|
||||||
|
#include "ggml-opencl-legacy.h"
|
||||||
|
|
||||||
|
#define CL_TARGET_OPENCL_VERSION 110
|
||||||
|
#include <clblast_c.h>
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include "ggml.h"
|
||||||
|
|
||||||
|
#define MULTILINE_QUOTE(...) #__VA_ARGS__
|
||||||
|
const char * clblast_dequant_legacy = MULTILINE_QUOTE(
|
||||||
|
|
||||||
|
struct block_q4_0
|
||||||
|
{
|
||||||
|
float d;
|
||||||
|
uchar qs[16];
|
||||||
|
};
|
||||||
|
|
||||||
|
__kernel void dequantize_row_q4_0(__global struct block_q4_0* blocks, __global float* result) {
|
||||||
|
const uint i = get_global_id(0) / 32;
|
||||||
|
const uint l = get_local_id(0);
|
||||||
|
|
||||||
|
const float d = blocks[i].d;
|
||||||
|
|
||||||
|
const uchar vi = blocks[i].qs[l];
|
||||||
|
|
||||||
|
const uint index = i*32 + l*2;
|
||||||
|
result[index + 0] = ((vi & 0xf) - 8)*d;
|
||||||
|
result[index + 1] = ((vi >> 4) - 8)*d;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct block_q4_1
|
||||||
|
{
|
||||||
|
float d;
|
||||||
|
float m;
|
||||||
|
uchar qs[16];
|
||||||
|
};
|
||||||
|
|
||||||
|
__kernel void dequantize_row_q4_1(__global struct block_q4_1* blocks, __global float* result) {
|
||||||
|
const uint i = get_global_id(0) / 32;
|
||||||
|
const uint l = get_local_id(0);
|
||||||
|
|
||||||
|
const float d = blocks[i].d;
|
||||||
|
const float m = blocks[i].m;
|
||||||
|
|
||||||
|
const uchar vi = blocks[i].qs[l];
|
||||||
|
|
||||||
|
const uint index = i*32 + l*2;
|
||||||
|
result[index + 0] = (vi & 0xf) * d + m;
|
||||||
|
result[index + 1] = (vi >> 4) * d + m;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct block_q4_2
|
||||||
|
{
|
||||||
|
ushort d;
|
||||||
|
uchar qs[8];
|
||||||
|
};
|
||||||
|
|
||||||
|
__kernel void dequantize_row_q4_2(__global struct block_q4_2* blocks, __global float* result) {
|
||||||
|
const uint i = get_global_id(0) / 16;
|
||||||
|
const uint l = get_local_id(0);
|
||||||
|
|
||||||
|
const float d = vload_half(0, (__global half*) &blocks[i].d);
|
||||||
|
|
||||||
|
const uchar vi = blocks[i].qs[l];
|
||||||
|
|
||||||
|
const uint index = i*16 + l*2;
|
||||||
|
result[index + 0] = ((vi & 0xf) - 8)*d;
|
||||||
|
result[index + 1] = ((vi >> 4) - 8)*d;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct block_q4_3
|
||||||
|
{
|
||||||
|
ushort d;
|
||||||
|
ushort m;
|
||||||
|
uchar qs[8];
|
||||||
|
};
|
||||||
|
|
||||||
|
__kernel void dequantize_row_q4_3(__global struct block_q4_3* blocks, __global float* result) {
|
||||||
|
const uint i = get_global_id(0) / 16;
|
||||||
|
const uint l = get_local_id(0);
|
||||||
|
|
||||||
|
const float d = vload_half(0, (__global half*) &(blocks[i].d));
|
||||||
|
const float m = vload_half(0, (__global half*) &(blocks[i].m));
|
||||||
|
|
||||||
|
const uchar vi = blocks[i].qs[l];
|
||||||
|
|
||||||
|
const uint index = i*16 + l*2;
|
||||||
|
result[index + 0] = (vi & 0xf) * d + m;
|
||||||
|
result[index + 1] = (vi >> 4) * d + m;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct block_q5_0
|
||||||
|
{
|
||||||
|
float d;
|
||||||
|
uint qh;
|
||||||
|
uchar qs[16];
|
||||||
|
};
|
||||||
|
|
||||||
|
__kernel void dequantize_row_q5_0(__global struct block_q5_0* blocks, __global float* result) {
|
||||||
|
const uint i = get_global_id(0) / 32;
|
||||||
|
const uint l = get_local_id(0);
|
||||||
|
|
||||||
|
const float d = blocks[i].d;
|
||||||
|
|
||||||
|
const uchar vi = blocks[i].qs[l];
|
||||||
|
|
||||||
|
const uint l2 = l * 2;
|
||||||
|
|
||||||
|
const uchar vh0 = ((blocks[i].qh & (1 << (l2 + 0))) >> (l2 + 0)) << 4;
|
||||||
|
const uchar vh1 = ((blocks[i].qh & (1 << (l2 + 1))) >> (l2 + 1)) << 4;
|
||||||
|
|
||||||
|
const uint index = i*32 + l2;
|
||||||
|
result[index + 0] = (((vi & 0xf) | vh0) - 16)*d;
|
||||||
|
result[index + 1] = (((vi >> 4) | vh1) - 16)*d;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct block_q5_1
|
||||||
|
{
|
||||||
|
ushort d;
|
||||||
|
ushort m;
|
||||||
|
uint qh;
|
||||||
|
uchar qs[16];
|
||||||
|
};
|
||||||
|
|
||||||
|
__kernel void dequantize_row_q5_1(__global struct block_q5_1* blocks, __global float* result) {
|
||||||
|
const uint i = get_global_id(0) / 32;
|
||||||
|
const uint l = get_local_id(0);
|
||||||
|
|
||||||
|
const float d = vload_half(0, (__global half*) &blocks[i].d);
|
||||||
|
const float m = vload_half(0, (__global half*) &blocks[i].m);
|
||||||
|
|
||||||
|
const uchar vi = blocks[i].qs[l];
|
||||||
|
|
||||||
|
const uint l2 = l * 2;
|
||||||
|
|
||||||
|
const uchar vh0 = ((blocks[i].qh & (1 << (l2 + 0))) >> (l2 + 0)) << 4;
|
||||||
|
const uchar vh1 = ((blocks[i].qh & (1 << (l2 + 1))) >> (l2 + 1)) << 4;
|
||||||
|
|
||||||
|
const uint index = i*32 + l2;
|
||||||
|
result[index + 0] = ((vi & 0xf) | vh0)*d + m;
|
||||||
|
result[index + 1] = ((vi >> 4) | vh1)*d + m;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct block_q8_0
|
||||||
|
{
|
||||||
|
float d;
|
||||||
|
char qs[32];
|
||||||
|
};
|
||||||
|
|
||||||
|
__kernel void dequantize_row_q8_0(__global struct block_q8_0* blocks, __global float* result) {
|
||||||
|
const uint i = get_global_id(0) / 32;
|
||||||
|
const uint l = get_local_id(0);
|
||||||
|
|
||||||
|
result[i*32 + l] = blocks[i].qs[l] * blocks[i].d;
|
||||||
|
}
|
||||||
|
|
||||||
|
);
|
||||||
|
|
||||||
|
#define CL_CHECK(err, name) \
|
||||||
|
do { \
|
||||||
|
cl_int err_ = (err); \
|
||||||
|
if (err_ != CL_SUCCESS) { \
|
||||||
|
fprintf(stderr, "OpenCL %s error %d at %s:%d\n", name, err_, __FILE__, __LINE__); \
|
||||||
|
exit(1); \
|
||||||
|
} \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
|
#define QK5_0 32
|
||||||
|
typedef struct {
|
||||||
|
ggml_fp16_t d; // delta
|
||||||
|
uint8_t qh[4]; // 5-th bit of quants
|
||||||
|
uint8_t qs[QK5_0 / 2]; // nibbles / quants
|
||||||
|
} block_q5_0;
|
||||||
|
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
float d; // delta
|
||||||
|
uint32_t qh; // 5-th bit of quants
|
||||||
|
uint8_t qs[QK5_0 / 2]; // nibbles / quants
|
||||||
|
} cl_block_q5_0;
|
||||||
|
|
||||||
|
static cl_platform_id platform;
|
||||||
|
static cl_device_id device;
|
||||||
|
static cl_context context;
|
||||||
|
static cl_command_queue queue;
|
||||||
|
static cl_program program;
|
||||||
|
static cl_kernel kernel_q4_0, kernel_q4_1, kernel_q4_2, kernel_q4_3, kernel_q5_0, kernel_q5_1, kernel_q8_0;
|
||||||
|
static cl_mem cl_buffer_a, cl_buffer_qb, cl_buffer_b, cl_buffer_c;
|
||||||
|
static size_t cl_size_a = 0, cl_size_qb = 0, cl_size_b = 0, cl_size_c = 0;
|
||||||
|
|
||||||
|
static cl_program build_program_from_source(cl_context ctx, cl_device_id dev, const char* program_buffer) {
|
||||||
|
cl_program p;
|
||||||
|
char *program_log;
|
||||||
|
size_t program_size, log_size;
|
||||||
|
int err;
|
||||||
|
|
||||||
|
program_size = strlen(program_buffer);
|
||||||
|
|
||||||
|
p = clCreateProgramWithSource(ctx, 1, (const char**)&program_buffer, &program_size, &err);
|
||||||
|
if(err < 0) {
|
||||||
|
fprintf(stderr, "OpenCL error creating program");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
err = clBuildProgram(p, 0, NULL, NULL, NULL, NULL);
|
||||||
|
if(err < 0) {
|
||||||
|
|
||||||
|
clGetProgramBuildInfo(p, dev, CL_PROGRAM_BUILD_LOG, 0, NULL, &log_size);
|
||||||
|
program_log = (char*) malloc(log_size + 1);
|
||||||
|
program_log[log_size] = '\0';
|
||||||
|
clGetProgramBuildInfo(p, dev, CL_PROGRAM_BUILD_LOG, log_size + 1, program_log, NULL);
|
||||||
|
printf("%s\n", program_log);
|
||||||
|
free(program_log);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ggml_cl_init_legacy(void) {
|
||||||
|
cl_int err = 0;
|
||||||
|
char * GGML_CLBLAST_PLATFORM = getenv("GGML_CLBLAST_PLATFORM");
|
||||||
|
char * GGML_CLBLAST_DEVICE = getenv("GGML_CLBLAST_DEVICE");
|
||||||
|
int plat_num = (GGML_CLBLAST_PLATFORM == NULL ? 0 : atoi(GGML_CLBLAST_PLATFORM));
|
||||||
|
int dev_num = (GGML_CLBLAST_DEVICE == NULL ? 0 : atoi(GGML_CLBLAST_DEVICE));
|
||||||
|
printf("\nInitializing LEGACY CLBlast (First Run)...");
|
||||||
|
printf("\nAttempting to use: Platform=%d, Device=%d (If invalid, program will crash)\n",plat_num,dev_num);
|
||||||
|
cl_uint num_platforms;
|
||||||
|
clGetPlatformIDs(0, NULL, &num_platforms);
|
||||||
|
cl_platform_id* platforms = (cl_platform_id*)malloc(num_platforms*sizeof(cl_platform_id));
|
||||||
|
clGetPlatformIDs(num_platforms, platforms, NULL);
|
||||||
|
platform = platforms[plat_num];
|
||||||
|
char platform_buffer[1024];
|
||||||
|
clGetPlatformInfo(platform, CL_PLATFORM_NAME, sizeof(platform_buffer), &platform_buffer, NULL);
|
||||||
|
cl_uint num_devices;
|
||||||
|
clGetDeviceIDs(platform, CL_DEVICE_TYPE_ALL, 0, NULL, &num_devices);
|
||||||
|
cl_device_id* devices = (cl_device_id*)malloc(num_devices*sizeof(cl_device_id));
|
||||||
|
clGetDeviceIDs(platform, CL_DEVICE_TYPE_ALL, num_devices, devices, NULL);
|
||||||
|
device = devices[dev_num];
|
||||||
|
char device_buffer[1024];
|
||||||
|
clGetDeviceInfo(device, CL_DEVICE_NAME, sizeof(device_buffer), &device_buffer, NULL);
|
||||||
|
printf("Using Platform: %s Device: %s\n", platform_buffer, device_buffer);
|
||||||
|
context = clCreateContext(NULL, 1, &device, NULL, NULL, &err);
|
||||||
|
CL_CHECK(err, "clCreateContext");
|
||||||
|
queue = clCreateCommandQueue(context, device, CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE, &err);
|
||||||
|
CL_CHECK(err, "clCreateCommandQueue");
|
||||||
|
|
||||||
|
free(platforms);
|
||||||
|
free(devices);
|
||||||
|
|
||||||
|
program = build_program_from_source(context, device, clblast_dequant_legacy);
|
||||||
|
|
||||||
|
// Prepare dequantize kernels
|
||||||
|
kernel_q4_0 = clCreateKernel(program, "dequantize_row_q4_0", &err);
|
||||||
|
CL_CHECK(err, "clCreateKernel");
|
||||||
|
kernel_q4_1 = clCreateKernel(program, "dequantize_row_q4_1", &err);
|
||||||
|
CL_CHECK(err, "clCreateKernel");
|
||||||
|
kernel_q4_2 = clCreateKernel(program, "dequantize_row_q4_2", &err);
|
||||||
|
CL_CHECK(err, "clCreateKernel");
|
||||||
|
kernel_q4_3 = clCreateKernel(program, "dequantize_row_q4_3", &err);
|
||||||
|
CL_CHECK(err, "clCreateKernel");
|
||||||
|
kernel_q5_0 = clCreateKernel(program, "dequantize_row_q5_0", &err);
|
||||||
|
CL_CHECK(err, "clCreateKernel");
|
||||||
|
kernel_q5_1 = clCreateKernel(program, "dequantize_row_q5_1", &err);
|
||||||
|
CL_CHECK(err, "clCreateKernel");
|
||||||
|
kernel_q8_0 = clCreateKernel(program, "dequantize_row_q8_0", &err);
|
||||||
|
CL_CHECK(err, "clCreateKernel");
|
||||||
|
}
|
||||||
|
|
||||||
|
static void ggml_cl_malloc(size_t req_size, size_t* cur_size, cl_mem_flags flags, cl_mem* buf) {
|
||||||
|
if (req_size <= *cur_size) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Reallocate buffer with enough space
|
||||||
|
if (*cur_size > 0) {
|
||||||
|
clReleaseMemObject(*buf);
|
||||||
|
}
|
||||||
|
cl_int err;
|
||||||
|
*buf = clCreateBuffer(context, flags, req_size, NULL, &err);
|
||||||
|
*cur_size = req_size;
|
||||||
|
CL_CHECK(err, "clCreateBuffer");
|
||||||
|
}
|
||||||
|
|
||||||
|
void ggml_cl_sgemm_wrapper_legacy(
|
||||||
|
const enum ggml_blas_order order, const enum ggml_blas_op trans_a, const enum ggml_blas_op trans_b,
|
||||||
|
const int m, const int n, const int k,
|
||||||
|
const float alpha, const void *host_a, const int lda,
|
||||||
|
const float *host_b, const int ldb, const float beta,
|
||||||
|
float *host_c, const int ldc, const int btype) {
|
||||||
|
cl_int err = 0;
|
||||||
|
|
||||||
|
cl_kernel kernel;
|
||||||
|
size_t global = n * k, local, size_qb;
|
||||||
|
bool dequant;
|
||||||
|
cl_block_q5_0* cl_host_b;
|
||||||
|
|
||||||
|
switch (btype) {
|
||||||
|
case GGML_TYPE_F32:
|
||||||
|
dequant = false;
|
||||||
|
break;
|
||||||
|
case GGML_TYPE_Q4_0:
|
||||||
|
dequant = true;
|
||||||
|
kernel = kernel_q4_0;
|
||||||
|
local = 16;
|
||||||
|
size_qb = global * (sizeof(float) + local) / 32;
|
||||||
|
break;
|
||||||
|
case GGML_TYPE_Q4_1:
|
||||||
|
dequant = true;
|
||||||
|
kernel = kernel_q4_1;
|
||||||
|
local = 16;
|
||||||
|
size_qb = global * (sizeof(float) * 2 + local) / 32;
|
||||||
|
break;
|
||||||
|
case GGML_TYPE_Q4_2:
|
||||||
|
dequant = true;
|
||||||
|
kernel = kernel_q4_2;
|
||||||
|
local = 8;
|
||||||
|
size_qb = global * (sizeof(ggml_fp16_t) + local) / 16;
|
||||||
|
break;
|
||||||
|
case GGML_TYPE_Q4_3:
|
||||||
|
dequant = true;
|
||||||
|
kernel = kernel_q4_3;
|
||||||
|
local = 8;
|
||||||
|
size_qb = global * (sizeof(short) * 2 + local) / 16;
|
||||||
|
break;
|
||||||
|
case GGML_TYPE_Q5_0:
|
||||||
|
dequant = true;
|
||||||
|
kernel = kernel_q5_0;
|
||||||
|
local = 16;
|
||||||
|
// For some reason OpenCL seems to be incapable of working with structs of size 22.
|
||||||
|
// 20 and 24 bytes are fine. Workaround to do the fp16 to fp32 step on CPU...
|
||||||
|
// TODO Find the reason, fix and remove workaround.
|
||||||
|
const block_q5_0* b = (const block_q5_0*) host_b;
|
||||||
|
cl_host_b = (cl_block_q5_0*) malloc(sizeof(cl_block_q5_0) * global / 32);
|
||||||
|
for (size_t i = 0; i < global / 32; i++) {
|
||||||
|
cl_host_b[i].d = ggml_fp16_to_fp32(b[i].d);
|
||||||
|
memcpy(&cl_host_b[i].qh, b[i].qh, sizeof(uint32_t));
|
||||||
|
memcpy(&cl_host_b[i].qs, b[i].qs, QK5_0 / 2);
|
||||||
|
}
|
||||||
|
host_b = (const float*) cl_host_b;
|
||||||
|
size_qb = global * (sizeof(float) + sizeof(uint32_t) + local) / 32;
|
||||||
|
break;
|
||||||
|
case GGML_TYPE_Q5_1:
|
||||||
|
dequant = true;
|
||||||
|
kernel = kernel_q5_1;
|
||||||
|
local = 16;
|
||||||
|
size_qb = global * (sizeof(ggml_fp16_t) * 2 + sizeof(uint32_t) + local) / 32;
|
||||||
|
break;
|
||||||
|
case GGML_TYPE_Q8_0:
|
||||||
|
dequant = true;
|
||||||
|
kernel = kernel_q8_0;
|
||||||
|
local = 32;
|
||||||
|
size_qb = global * (sizeof(float) + local) / 32;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
fprintf(stderr, "Error: Unsupported OpenCL btype %d\n", btype);
|
||||||
|
abort();
|
||||||
|
}
|
||||||
|
|
||||||
|
const size_t size_a = m * k * sizeof(float);
|
||||||
|
const size_t size_b = n * k * sizeof(float);
|
||||||
|
const size_t size_c = m * n * sizeof(float);
|
||||||
|
|
||||||
|
// Prepare buffers
|
||||||
|
ggml_cl_malloc(size_a, &cl_size_a, CL_MEM_READ_ONLY, &cl_buffer_a);
|
||||||
|
if (dequant) {
|
||||||
|
ggml_cl_malloc(size_qb, &cl_size_qb, CL_MEM_READ_ONLY, &cl_buffer_qb);
|
||||||
|
}
|
||||||
|
ggml_cl_malloc(size_b, &cl_size_b, CL_MEM_READ_WRITE, &cl_buffer_b);
|
||||||
|
ggml_cl_malloc(size_c, &cl_size_c, CL_MEM_WRITE_ONLY, &cl_buffer_c);
|
||||||
|
|
||||||
|
cl_event ev_a, ev_qb, ev_b;
|
||||||
|
|
||||||
|
if (dequant) {
|
||||||
|
err = clSetKernelArg(kernel, 0, sizeof(cl_mem), &cl_buffer_qb);
|
||||||
|
err |= clSetKernelArg(kernel, 1, sizeof(cl_mem), &cl_buffer_b);
|
||||||
|
CL_CHECK(err, "clSetKernelArg");
|
||||||
|
err = clEnqueueWriteBuffer(queue, cl_buffer_qb, CL_FALSE, 0, size_qb, host_b, 0, NULL, &ev_qb);
|
||||||
|
CL_CHECK(err, "clEnqueueWriteBuffer qb");
|
||||||
|
} else {
|
||||||
|
err = clEnqueueWriteBuffer(queue, cl_buffer_b, CL_FALSE, 0, size_b, host_b, 0, NULL, &ev_b);
|
||||||
|
CL_CHECK(err, "clEnqueueWriteBuffer b");
|
||||||
|
}
|
||||||
|
|
||||||
|
err = clEnqueueWriteBuffer(queue, cl_buffer_a, CL_FALSE, 0, size_a, host_a, 0, NULL, &ev_a);
|
||||||
|
CL_CHECK(err, "clEnqueueWriteBuffer a");
|
||||||
|
if (dequant) {
|
||||||
|
err = clEnqueueNDRangeKernel(queue, kernel, 1, NULL, &global, &local, 1, &ev_qb, &ev_b);
|
||||||
|
CL_CHECK(err, "clEnqueueNDRangeKernel");
|
||||||
|
clReleaseEvent(ev_qb);
|
||||||
|
}
|
||||||
|
clWaitForEvents(1, &ev_a);
|
||||||
|
clWaitForEvents(1, &ev_b);
|
||||||
|
clReleaseEvent(ev_a);
|
||||||
|
clReleaseEvent(ev_b);
|
||||||
|
|
||||||
|
cl_event ev_sgemm;
|
||||||
|
CLBlastStatusCode status = CLBlastSgemm((CLBlastLayout)order,
|
||||||
|
(CLBlastTranspose)trans_a, (CLBlastTranspose)trans_b,
|
||||||
|
m, n, k,
|
||||||
|
alpha,
|
||||||
|
cl_buffer_a, 0, lda,
|
||||||
|
cl_buffer_b, 0, ldb,
|
||||||
|
beta,
|
||||||
|
cl_buffer_c, 0, ldc,
|
||||||
|
&queue, &ev_sgemm);
|
||||||
|
|
||||||
|
if (status != CLBlastSuccess) {
|
||||||
|
fprintf(stderr, "Error: CLBlast SGEMM %d\n", status);
|
||||||
|
abort();
|
||||||
|
}
|
||||||
|
|
||||||
|
cl_event ev_c;
|
||||||
|
clEnqueueReadBuffer(queue, cl_buffer_c, CL_TRUE, 0, size_c, host_c, 1, &ev_sgemm, &ev_c);
|
||||||
|
|
||||||
|
// Wait for completion
|
||||||
|
clWaitForEvents(1, &ev_c);
|
||||||
|
clReleaseEvent(ev_sgemm);
|
||||||
|
clReleaseEvent(ev_c);
|
||||||
|
if (btype == GGML_TYPE_Q5_0) {
|
||||||
|
free((void*) cl_host_b);
|
||||||
|
}
|
||||||
|
}
|
15
ggml-opencl-legacy.h
Normal file
15
ggml-opencl-legacy.h
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "ggml-opencl.h"
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
void ggml_cl_init_legacy(void);
|
||||||
|
|
||||||
|
void ggml_cl_sgemm_wrapper_legacy(const enum ggml_blas_order order, const enum ggml_blas_op trans_a, const enum ggml_blas_op trans_b, const int m, const int n, const int k, const float alpha, const void *host_a, const int lda, const float *host_b, const int ldb, const float beta, float *host_c, const int ldc, const int btype);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
270
ggml-opencl.c
270
ggml-opencl.c
|
@ -7,155 +7,134 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
|
||||||
#include "ggml.h"
|
#include "ggml.h"
|
||||||
|
|
||||||
#define MULTILINE_QUOTE(...) #__VA_ARGS__
|
#define MULTILINE_QUOTE(...) #__VA_ARGS__
|
||||||
const char * clblast_dequant = MULTILINE_QUOTE(
|
const char * clblast_dequant = MULTILINE_QUOTE(
|
||||||
|
|
||||||
|
typedef uchar uint8_t;
|
||||||
|
typedef int int32_t;
|
||||||
|
typedef uint uint32_t;
|
||||||
|
|
||||||
|
constant uint QK4_0 = 32;
|
||||||
struct block_q4_0
|
struct block_q4_0
|
||||||
{
|
{
|
||||||
float d;
|
float d;
|
||||||
uchar qs[16];
|
uint8_t qs[QK4_0 / 2];
|
||||||
};
|
};
|
||||||
|
|
||||||
__kernel void dequantize_row_q4_0(__global struct block_q4_0* blocks, __global float* result) {
|
constant uint QK4_1 = 32;
|
||||||
const uint i = get_global_id(0) / 32;
|
|
||||||
const uint l = get_local_id(0);
|
|
||||||
|
|
||||||
const float d = blocks[i].d;
|
|
||||||
|
|
||||||
const uchar vi = blocks[i].qs[l];
|
|
||||||
|
|
||||||
const uint index = i*32 + l*2;
|
|
||||||
result[index + 0] = ((vi & 0xf) - 8)*d;
|
|
||||||
result[index + 1] = ((vi >> 4) - 8)*d;
|
|
||||||
}
|
|
||||||
|
|
||||||
struct block_q4_1
|
struct block_q4_1
|
||||||
{
|
{
|
||||||
float d;
|
float d;
|
||||||
float m;
|
float m;
|
||||||
uchar qs[16];
|
uint8_t qs[QK4_1 / 2];
|
||||||
};
|
};
|
||||||
|
|
||||||
__kernel void dequantize_row_q4_1(__global struct block_q4_1* blocks, __global float* result) {
|
constant uint QK5_0 = 32;
|
||||||
const uint i = get_global_id(0) / 32;
|
struct __attribute__ ((packed)) block_q5_0
|
||||||
const uint l = get_local_id(0);
|
|
||||||
|
|
||||||
const float d = blocks[i].d;
|
|
||||||
const float m = blocks[i].m;
|
|
||||||
|
|
||||||
const uchar vi = blocks[i].qs[l];
|
|
||||||
|
|
||||||
const uint index = i*32 + l*2;
|
|
||||||
result[index + 0] = (vi & 0xf) * d + m;
|
|
||||||
result[index + 1] = (vi >> 4) * d + m;
|
|
||||||
}
|
|
||||||
|
|
||||||
struct block_q4_2
|
|
||||||
{
|
{
|
||||||
ushort d;
|
half d;
|
||||||
uchar qs[8];
|
uint32_t qh;
|
||||||
|
uint8_t qs[QK5_0 / 2];
|
||||||
};
|
};
|
||||||
|
|
||||||
__kernel void dequantize_row_q4_2(__global struct block_q4_2* blocks, __global float* result) {
|
constant uint QK5_1 = 32;
|
||||||
const uint i = get_global_id(0) / 16;
|
|
||||||
const uint l = get_local_id(0);
|
|
||||||
|
|
||||||
const float d = vload_half(0, (__global half*) &blocks[i].d);
|
|
||||||
|
|
||||||
const uchar vi = blocks[i].qs[l];
|
|
||||||
|
|
||||||
const uint index = i*16 + l*2;
|
|
||||||
result[index + 0] = ((vi & 0xf) - 8)*d;
|
|
||||||
result[index + 1] = ((vi >> 4) - 8)*d;
|
|
||||||
}
|
|
||||||
|
|
||||||
struct block_q4_3
|
|
||||||
{
|
|
||||||
ushort d;
|
|
||||||
ushort m;
|
|
||||||
uchar qs[8];
|
|
||||||
};
|
|
||||||
|
|
||||||
__kernel void dequantize_row_q4_3(__global struct block_q4_3* blocks, __global float* result) {
|
|
||||||
const uint i = get_global_id(0) / 16;
|
|
||||||
const uint l = get_local_id(0);
|
|
||||||
|
|
||||||
const float d = vload_half(0, (__global half*) &(blocks[i].d));
|
|
||||||
const float m = vload_half(0, (__global half*) &(blocks[i].m));
|
|
||||||
|
|
||||||
const uchar vi = blocks[i].qs[l];
|
|
||||||
|
|
||||||
const uint index = i*16 + l*2;
|
|
||||||
result[index + 0] = (vi & 0xf) * d + m;
|
|
||||||
result[index + 1] = (vi >> 4) * d + m;
|
|
||||||
}
|
|
||||||
|
|
||||||
struct block_q5_0
|
|
||||||
{
|
|
||||||
float d;
|
|
||||||
uint qh;
|
|
||||||
uchar qs[16];
|
|
||||||
};
|
|
||||||
|
|
||||||
__kernel void dequantize_row_q5_0(__global struct block_q5_0* blocks, __global float* result) {
|
|
||||||
const uint i = get_global_id(0) / 32;
|
|
||||||
const uint l = get_local_id(0);
|
|
||||||
|
|
||||||
const float d = blocks[i].d;
|
|
||||||
|
|
||||||
const uchar vi = blocks[i].qs[l];
|
|
||||||
|
|
||||||
const uint l2 = l * 2;
|
|
||||||
|
|
||||||
const uchar vh0 = ((blocks[i].qh & (1 << (l2 + 0))) >> (l2 + 0)) << 4;
|
|
||||||
const uchar vh1 = ((blocks[i].qh & (1 << (l2 + 1))) >> (l2 + 1)) << 4;
|
|
||||||
|
|
||||||
const uint index = i*32 + l2;
|
|
||||||
result[index + 0] = (((vi & 0xf) | vh0) - 16)*d;
|
|
||||||
result[index + 1] = (((vi >> 4) | vh1) - 16)*d;
|
|
||||||
}
|
|
||||||
|
|
||||||
struct block_q5_1
|
struct block_q5_1
|
||||||
{
|
{
|
||||||
ushort d;
|
half d;
|
||||||
ushort m;
|
half m;
|
||||||
uint qh;
|
uint32_t qh;
|
||||||
uchar qs[16];
|
uint8_t qs[QK5_1 / 2];
|
||||||
};
|
};
|
||||||
|
|
||||||
__kernel void dequantize_row_q5_1(__global struct block_q5_1* blocks, __global float* result) {
|
constant uint QK8_0 = 32;
|
||||||
const uint i = get_global_id(0) / 32;
|
|
||||||
const uint l = get_local_id(0);
|
|
||||||
|
|
||||||
const float d = vload_half(0, (__global half*) &blocks[i].d);
|
|
||||||
const float m = vload_half(0, (__global half*) &blocks[i].m);
|
|
||||||
|
|
||||||
const uchar vi = blocks[i].qs[l];
|
|
||||||
|
|
||||||
const uint l2 = l * 2;
|
|
||||||
|
|
||||||
const uchar vh0 = ((blocks[i].qh & (1 << (l2 + 0))) >> (l2 + 0)) << 4;
|
|
||||||
const uchar vh1 = ((blocks[i].qh & (1 << (l2 + 1))) >> (l2 + 1)) << 4;
|
|
||||||
|
|
||||||
const uint index = i*32 + l2;
|
|
||||||
result[index + 0] = ((vi & 0xf) | vh0)*d + m;
|
|
||||||
result[index + 1] = ((vi >> 4) | vh1)*d + m;
|
|
||||||
}
|
|
||||||
|
|
||||||
struct block_q8_0
|
struct block_q8_0
|
||||||
{
|
{
|
||||||
float d;
|
float d;
|
||||||
char qs[32];
|
uint8_t qs[QK8_0];
|
||||||
};
|
};
|
||||||
|
|
||||||
__kernel void dequantize_row_q8_0(__global struct block_q8_0* blocks, __global float* result) {
|
|
||||||
const uint i = get_global_id(0) / 32;
|
|
||||||
const uint l = get_local_id(0);
|
|
||||||
|
|
||||||
result[i*32 + l] = blocks[i].qs[l] * blocks[i].d;
|
__kernel void dequantize_row_q4_0(__global struct block_q4_0* x, __global float* y) {
|
||||||
|
constant uint qk = QK4_0;
|
||||||
|
|
||||||
|
const uint i = get_global_id(0) / qk;
|
||||||
|
const uint j = get_local_id(0);
|
||||||
|
|
||||||
|
const float d = x[i].d;
|
||||||
|
|
||||||
|
const int x0 = (x[i].qs[j] & 0xf) - 8;
|
||||||
|
const int x1 = (x[i].qs[j] >> 4) - 8;
|
||||||
|
|
||||||
|
y[i*qk + j + 0 ] = x0*d;
|
||||||
|
y[i*qk + j + qk/2] = x1*d;
|
||||||
|
}
|
||||||
|
|
||||||
|
__kernel void dequantize_row_q4_1(__global struct block_q4_1* x, __global float* y) {
|
||||||
|
constant uint qk = QK4_1;
|
||||||
|
|
||||||
|
const uint i = get_global_id(0) / qk;
|
||||||
|
const uint j = get_local_id(0);
|
||||||
|
|
||||||
|
const float d = x[i].d;
|
||||||
|
const float m = x[i].m;
|
||||||
|
|
||||||
|
const int x0 = (x[i].qs[j] & 0xf);
|
||||||
|
const int x1 = (x[i].qs[j] >> 4);
|
||||||
|
|
||||||
|
y[i*qk + j + 0 ] = x0*d + m;
|
||||||
|
y[i*qk + j + qk/2] = x1*d + m;
|
||||||
|
}
|
||||||
|
|
||||||
|
__kernel void dequantize_row_q5_0(__global struct block_q5_0* x, __global float* y) {
|
||||||
|
constant uint qk = QK5_0;
|
||||||
|
|
||||||
|
const uint i = get_global_id(0) / qk;
|
||||||
|
const uint j = get_local_id(0);
|
||||||
|
|
||||||
|
const float d = vload_half(0, (__global half*) &x[i].d);
|
||||||
|
|
||||||
|
uint32_t qh = x[i].qh;
|
||||||
|
|
||||||
|
const uint8_t xh_0 = ((qh >> (j + 0)) << 4) & 0x10;
|
||||||
|
const uint8_t xh_1 = ((qh >> (j + 12)) ) & 0x10;
|
||||||
|
|
||||||
|
const int32_t x0 = ((x[i].qs[j] & 0xf) | xh_0) - 16;
|
||||||
|
const int32_t x1 = ((x[i].qs[j] >> 4) | xh_1) - 16;
|
||||||
|
|
||||||
|
y[i*qk + j + 0 ] = x0*d;
|
||||||
|
y[i*qk + j + qk/2] = x1*d;
|
||||||
|
}
|
||||||
|
|
||||||
|
__kernel void dequantize_row_q5_1(__global struct block_q5_1* x, __global float* y) {
|
||||||
|
constant uint qk = QK5_1;
|
||||||
|
|
||||||
|
const uint i = get_global_id(0) / qk;
|
||||||
|
const uint j = get_local_id(0);
|
||||||
|
|
||||||
|
const float d = vload_half(0, (__global half*) &x[i].d);
|
||||||
|
const float m = vload_half(0, (__global half*) &x[i].m);
|
||||||
|
|
||||||
|
uint32_t qh = x[i].qh;
|
||||||
|
|
||||||
|
const uint8_t xh_0 = ((qh >> (j + 0)) << 4) & 0x10;
|
||||||
|
const uint8_t xh_1 = ((qh >> (j + 12)) ) & 0x10;
|
||||||
|
|
||||||
|
const int x0 = (x[i].qs[j] & 0xf) | xh_0;
|
||||||
|
const int x1 = (x[i].qs[j] >> 4) | xh_1;
|
||||||
|
|
||||||
|
y[i*qk + j + 0 ] = x0*d + m;
|
||||||
|
y[i*qk + j + qk/2] = x1*d + m;
|
||||||
|
}
|
||||||
|
|
||||||
|
__kernel void dequantize_row_q8_0(__global struct block_q8_0* x, __global float* y) {
|
||||||
|
constant uint qk = QK8_0;
|
||||||
|
const uint i = get_global_id(0) / qk;
|
||||||
|
const uint j = get_local_id(0);
|
||||||
|
|
||||||
|
const float d = x[i].d;
|
||||||
|
y[i*qk + j] = x[i].qs[j]*d;
|
||||||
}
|
}
|
||||||
|
|
||||||
);
|
);
|
||||||
|
@ -169,26 +148,12 @@ __kernel void dequantize_row_q8_0(__global struct block_q8_0* blocks, __global f
|
||||||
} \
|
} \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
#define QK5_0 32
|
|
||||||
typedef struct {
|
|
||||||
ggml_fp16_t d; // delta
|
|
||||||
uint8_t qh[4]; // 5-th bit of quants
|
|
||||||
uint8_t qs[QK5_0 / 2]; // nibbles / quants
|
|
||||||
} block_q5_0;
|
|
||||||
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
float d; // delta
|
|
||||||
uint32_t qh; // 5-th bit of quants
|
|
||||||
uint8_t qs[QK5_0 / 2]; // nibbles / quants
|
|
||||||
} cl_block_q5_0;
|
|
||||||
|
|
||||||
static cl_platform_id platform;
|
static cl_platform_id platform;
|
||||||
static cl_device_id device;
|
static cl_device_id device;
|
||||||
static cl_context context;
|
static cl_context context;
|
||||||
static cl_command_queue queue;
|
static cl_command_queue queue;
|
||||||
static cl_program program;
|
static cl_program program;
|
||||||
static cl_kernel kernel_q4_0, kernel_q4_1, kernel_q4_2, kernel_q4_3, kernel_q5_0, kernel_q5_1, kernel_q8_0;
|
static cl_kernel kernel_q4_0, kernel_q4_1, kernel_q5_0, kernel_q5_1, kernel_q8_0;
|
||||||
static cl_mem cl_buffer_a, cl_buffer_qb, cl_buffer_b, cl_buffer_c;
|
static cl_mem cl_buffer_a, cl_buffer_qb, cl_buffer_b, cl_buffer_c;
|
||||||
static size_t cl_size_a = 0, cl_size_qb = 0, cl_size_b = 0, cl_size_c = 0;
|
static size_t cl_size_a = 0, cl_size_qb = 0, cl_size_b = 0, cl_size_c = 0;
|
||||||
|
|
||||||
|
@ -259,10 +224,6 @@ void ggml_cl_init(void) {
|
||||||
CL_CHECK(err, "clCreateKernel");
|
CL_CHECK(err, "clCreateKernel");
|
||||||
kernel_q4_1 = clCreateKernel(program, "dequantize_row_q4_1", &err);
|
kernel_q4_1 = clCreateKernel(program, "dequantize_row_q4_1", &err);
|
||||||
CL_CHECK(err, "clCreateKernel");
|
CL_CHECK(err, "clCreateKernel");
|
||||||
kernel_q4_2 = clCreateKernel(program, "dequantize_row_q4_2", &err);
|
|
||||||
CL_CHECK(err, "clCreateKernel");
|
|
||||||
kernel_q4_3 = clCreateKernel(program, "dequantize_row_q4_3", &err);
|
|
||||||
CL_CHECK(err, "clCreateKernel");
|
|
||||||
kernel_q5_0 = clCreateKernel(program, "dequantize_row_q5_0", &err);
|
kernel_q5_0 = clCreateKernel(program, "dequantize_row_q5_0", &err);
|
||||||
CL_CHECK(err, "clCreateKernel");
|
CL_CHECK(err, "clCreateKernel");
|
||||||
kernel_q5_1 = clCreateKernel(program, "dequantize_row_q5_1", &err);
|
kernel_q5_1 = clCreateKernel(program, "dequantize_row_q5_1", &err);
|
||||||
|
@ -297,7 +258,6 @@ void ggml_cl_sgemm_wrapper(
|
||||||
cl_kernel kernel;
|
cl_kernel kernel;
|
||||||
size_t global = n * k, local, size_qb;
|
size_t global = n * k, local, size_qb;
|
||||||
bool dequant;
|
bool dequant;
|
||||||
cl_block_q5_0* cl_host_b;
|
|
||||||
|
|
||||||
switch (btype) {
|
switch (btype) {
|
||||||
case GGML_TYPE_F32:
|
case GGML_TYPE_F32:
|
||||||
|
@ -315,34 +275,11 @@ void ggml_cl_sgemm_wrapper(
|
||||||
local = 16;
|
local = 16;
|
||||||
size_qb = global * (sizeof(float) * 2 + local) / 32;
|
size_qb = global * (sizeof(float) * 2 + local) / 32;
|
||||||
break;
|
break;
|
||||||
case GGML_TYPE_Q4_2:
|
|
||||||
dequant = true;
|
|
||||||
kernel = kernel_q4_2;
|
|
||||||
local = 8;
|
|
||||||
size_qb = global * (sizeof(ggml_fp16_t) + local) / 16;
|
|
||||||
break;
|
|
||||||
case GGML_TYPE_Q4_3:
|
|
||||||
dequant = true;
|
|
||||||
kernel = kernel_q4_3;
|
|
||||||
local = 8;
|
|
||||||
size_qb = global * (sizeof(short) * 2 + local) / 16;
|
|
||||||
break;
|
|
||||||
case GGML_TYPE_Q5_0:
|
case GGML_TYPE_Q5_0:
|
||||||
dequant = true;
|
dequant = true;
|
||||||
kernel = kernel_q5_0;
|
kernel = kernel_q5_0;
|
||||||
local = 16;
|
local = 16;
|
||||||
// For some reason OpenCL seems to be incapable of working with structs of size 22.
|
size_qb = global * (sizeof(ggml_fp16_t) + sizeof(uint32_t) + local) / 32;
|
||||||
// 20 and 24 bytes are fine. Workaround to do the fp16 to fp32 step on CPU...
|
|
||||||
// TODO Find the reason, fix and remove workaround.
|
|
||||||
const block_q5_0* b = (const block_q5_0*) host_b;
|
|
||||||
cl_host_b = (cl_block_q5_0*) malloc(sizeof(cl_block_q5_0) * global / 32);
|
|
||||||
for (size_t i = 0; i < global / 32; i++) {
|
|
||||||
cl_host_b[i].d = ggml_fp16_to_fp32(b[i].d);
|
|
||||||
memcpy(&cl_host_b[i].qh, b[i].qh, sizeof(uint32_t));
|
|
||||||
memcpy(&cl_host_b[i].qs, b[i].qs, QK5_0 / 2);
|
|
||||||
}
|
|
||||||
host_b = (const float*) cl_host_b;
|
|
||||||
size_qb = global * (sizeof(float) + sizeof(uint32_t) + local) / 32;
|
|
||||||
break;
|
break;
|
||||||
case GGML_TYPE_Q5_1:
|
case GGML_TYPE_Q5_1:
|
||||||
dequant = true;
|
dequant = true;
|
||||||
|
@ -421,7 +358,4 @@ void ggml_cl_sgemm_wrapper(
|
||||||
clWaitForEvents(1, &ev_c);
|
clWaitForEvents(1, &ev_c);
|
||||||
clReleaseEvent(ev_sgemm);
|
clReleaseEvent(ev_sgemm);
|
||||||
clReleaseEvent(ev_c);
|
clReleaseEvent(ev_c);
|
||||||
if (btype == GGML_TYPE_Q5_0) {
|
}
|
||||||
free((void*) cl_host_b);
|
|
||||||
}
|
|
||||||
}
|
|
46
ggml.c
46
ggml.c
|
@ -144,6 +144,7 @@ inline static void* ggml_aligned_malloc(size_t size) {
|
||||||
#endif
|
#endif
|
||||||
#if defined(GGML_USE_CLBLAST)
|
#if defined(GGML_USE_CLBLAST)
|
||||||
#include "ggml-opencl.h"
|
#include "ggml-opencl.h"
|
||||||
|
#include "ggml-opencl-legacy.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#undef MIN
|
#undef MIN
|
||||||
|
@ -3560,7 +3561,14 @@ struct ggml_context * ggml_init(struct ggml_init_params params) {
|
||||||
#if defined(GGML_USE_CUBLAS)
|
#if defined(GGML_USE_CUBLAS)
|
||||||
ggml_init_cublas();
|
ggml_init_cublas();
|
||||||
#elif defined(GGML_USE_CLBLAST)
|
#elif defined(GGML_USE_CLBLAST)
|
||||||
ggml_cl_init();
|
if(quants_unshuffled)
|
||||||
|
{
|
||||||
|
ggml_cl_init();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ggml_cl_init_legacy();
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
is_first_call = false;
|
is_first_call = false;
|
||||||
|
@ -7474,12 +7482,24 @@ static void ggml_compute_forward_mul_mat_f32(
|
||||||
|
|
||||||
#if defined(GGML_USE_CLBLAST)
|
#if defined(GGML_USE_CLBLAST)
|
||||||
// zT = y * xT
|
// zT = y * xT
|
||||||
|
if(quants_unshuffled)
|
||||||
|
{
|
||||||
ggml_cl_sgemm_wrapper(GGML_BLAS_ORDER_ROW_MAJOR, GGML_BLAS_OP_N, GGML_BLAS_OP_T,
|
ggml_cl_sgemm_wrapper(GGML_BLAS_ORDER_ROW_MAJOR, GGML_BLAS_OP_N, GGML_BLAS_OP_T,
|
||||||
ne11, ne01, ne10,
|
ne11, ne01, ne10,
|
||||||
1.0f, y, ne10,
|
1.0f, y, ne10,
|
||||||
x, ne10,
|
x, ne10,
|
||||||
0.0f, d, ne01,
|
0.0f, d, ne01,
|
||||||
GGML_TYPE_F32);
|
GGML_TYPE_F32);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ggml_cl_sgemm_wrapper_legacy(GGML_BLAS_ORDER_ROW_MAJOR, GGML_BLAS_OP_N, GGML_BLAS_OP_T,
|
||||||
|
ne11, ne01, ne10,
|
||||||
|
1.0f, y, ne10,
|
||||||
|
x, ne10,
|
||||||
|
0.0f, d, ne01,
|
||||||
|
GGML_TYPE_F32);
|
||||||
|
}
|
||||||
#else
|
#else
|
||||||
cblas_sgemm(CblasRowMajor, CblasNoTrans, CblasTrans,
|
cblas_sgemm(CblasRowMajor, CblasNoTrans, CblasTrans,
|
||||||
ne11, ne01, ne10,
|
ne11, ne01, ne10,
|
||||||
|
@ -7664,12 +7684,24 @@ static void ggml_compute_forward_mul_mat_f16_f32(
|
||||||
float * d = (float *) ((char *) dst->data + i02*nb2 + i03*nb3);
|
float * d = (float *) ((char *) dst->data + i02*nb2 + i03*nb3);
|
||||||
|
|
||||||
// zT = y * xT
|
// zT = y * xT
|
||||||
|
if(quants_unshuffled)
|
||||||
|
{
|
||||||
ggml_cl_sgemm_wrapper(GGML_BLAS_ORDER_ROW_MAJOR, GGML_BLAS_OP_N, GGML_BLAS_OP_T,
|
ggml_cl_sgemm_wrapper(GGML_BLAS_ORDER_ROW_MAJOR, GGML_BLAS_OP_N, GGML_BLAS_OP_T,
|
||||||
ne11, ne01, ne10,
|
ne11, ne01, ne10,
|
||||||
1.0f, y, ne10,
|
1.0f, y, ne10,
|
||||||
x, ne10,
|
x, ne10,
|
||||||
0.0f, d, ne01,
|
0.0f, d, ne01,
|
||||||
GGML_TYPE_F32);
|
GGML_TYPE_F32);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ggml_cl_sgemm_wrapper_legacy(GGML_BLAS_ORDER_ROW_MAJOR, GGML_BLAS_OP_N, GGML_BLAS_OP_T,
|
||||||
|
ne11, ne01, ne10,
|
||||||
|
1.0f, y, ne10,
|
||||||
|
x, ne10,
|
||||||
|
0.0f, d, ne01,
|
||||||
|
GGML_TYPE_F32);
|
||||||
|
}
|
||||||
#else
|
#else
|
||||||
const float * x = wdata;
|
const float * x = wdata;
|
||||||
const float * y = (float *) ((char *) src1->data + i02*nb12 + i03*nb13);
|
const float * y = (float *) ((char *) src1->data + i02*nb12 + i03*nb13);
|
||||||
|
@ -7888,12 +7920,24 @@ static void ggml_compute_forward_mul_mat_q_f32(
|
||||||
|
|
||||||
#if defined(GGML_USE_CLBLAST)
|
#if defined(GGML_USE_CLBLAST)
|
||||||
// zT = y * xT
|
// zT = y * xT
|
||||||
|
if(quants_unshuffled)
|
||||||
|
{
|
||||||
ggml_cl_sgemm_wrapper(GGML_BLAS_ORDER_ROW_MAJOR, GGML_BLAS_OP_N, GGML_BLAS_OP_T,
|
ggml_cl_sgemm_wrapper(GGML_BLAS_ORDER_ROW_MAJOR, GGML_BLAS_OP_N, GGML_BLAS_OP_T,
|
||||||
ne11, ne01, ne10,
|
ne11, ne01, ne10,
|
||||||
1.0f, y, ne10,
|
1.0f, y, ne10,
|
||||||
x, ne10,
|
x, ne10,
|
||||||
0.0f, d, ne01,
|
0.0f, d, ne01,
|
||||||
type);
|
type);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ggml_cl_sgemm_wrapper_legacy(GGML_BLAS_ORDER_ROW_MAJOR, GGML_BLAS_OP_N, GGML_BLAS_OP_T,
|
||||||
|
ne11, ne01, ne10,
|
||||||
|
1.0f, y, ne10,
|
||||||
|
x, ne10,
|
||||||
|
0.0f, d, ne01,
|
||||||
|
type);
|
||||||
|
}
|
||||||
#else
|
#else
|
||||||
cblas_sgemm(CblasRowMajor, CblasNoTrans, CblasTrans,
|
cblas_sgemm(CblasRowMajor, CblasNoTrans, CblasTrans,
|
||||||
ne11, ne01, ne10,
|
ne11, ne01, ne10,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue