feat: add OpenCL kernel definitions and include files for division operations

This commit is contained in:
chraac 2026-01-14 13:20:08 +08:00
parent 463dc3faef
commit e6db6313a9
4 changed files with 50 additions and 2 deletions

View File

@ -1,5 +1,7 @@
#pragma OPENCL EXTENSION cl_khr_fp16 : enable
#include "div.h"
//------------------------------------------------------------------------------
// div
//------------------------------------------------------------------------------

View File

@ -0,0 +1,31 @@
#ifndef __KERNELS_DIV_H__
#define __KERNELS_DIV_H__
#include "ocl_defs.h"
kernel void kernel_div(global char * src0,
ulong offset0,
global char * src1,
ulong offset1,
global char * dst,
ulong offsetd,
ulong nb00,
ulong nb01,
ulong nb02,
ulong nb03,
int ne10,
int ne11,
int ne12,
int ne13,
ulong nb10,
ulong nb11,
ulong nb12,
ulong nb13,
int ne0,
ulong nb0,
ulong nb1,
ulong nb2,
ulong nb3);
#endif // __KERNELS_DIV_H__

View File

@ -7,12 +7,11 @@ import os
logger = logging.getLogger("opencl-embed-kernel")
INCLUDE_PATTERN = re.compile(r'#include\s+"(.*)"')
INCLUDE_PATTERN = re.compile(r'#include\s+"(.*)".*')
def parse_file_line(ifile, ofile, base_path: str):
for i in ifile:
i = i.rstrip()
if m := INCLUDE_PATTERN.match(i):
include_file = os.path.join(base_path, m.group(1))
logger.info(f"Embedding file: {include_file}")

View File

@ -0,0 +1,16 @@
#ifndef __OCL_DEFS_H__
#define __OCL_DEFS_H__
#ifdef __OPENCL_C_VERSION__
// Device (OpenCL) Definitions
#else
// Host (C++) Definitions
# define kernel
# define global
# define __kernel
# define __global
# define ulong cl_ulong
#endif
#endif // __OCL_DEFS_H__