mirror of
https://github.com/fumiama/gozel.git
synced 2026-06-13 05:02:20 +08:00
feat(ze): add event support & vadd demo & refactor (#5)
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
extern "C" SYCL_EXT_ONEAPI_FUNCTION_PROPERTY((sycl::ext::oneapi::experimental::nd_range_kernel<1>))
|
||||
void vector_add(float* a, float* b) {
|
||||
auto item = sycl::ext::oneapi::this_work_item::get_nd_item<1>();
|
||||
int idx = item.get_global_id(0);
|
||||
int idx = item.get_global_linear_id();
|
||||
|
||||
a[idx] += b[idx];
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ package main
|
||||
import (
|
||||
_ "embed"
|
||||
"fmt"
|
||||
"math"
|
||||
"math/rand"
|
||||
"os"
|
||||
"strconv"
|
||||
@@ -11,7 +12,7 @@ import (
|
||||
"time"
|
||||
"unsafe"
|
||||
|
||||
"github.com/fumiama/gozel"
|
||||
"github.com/fumiama/gozel/gozel"
|
||||
"github.com/fumiama/gozel/ze"
|
||||
)
|
||||
|
||||
@@ -69,8 +70,7 @@ func main() {
|
||||
fmt.Printf("%-28s (%d, %d, %d)\n", "Max Group Count (X, Y, Z):", cprop.Maxgroupcountx, cprop.Maxgroupcounty, cprop.Maxgroupcountz)
|
||||
fmt.Printf("%-28s %d\n", "Max Total Group Size:", cprop.Maxtotalgroupsize)
|
||||
fmt.Printf("%-28s %d\n", "Max Shared Local Memory:", cprop.Maxsharedlocalmemory)
|
||||
fmt.Printf("%-28s %d\n", "Num Subgroup Sizes:", cprop.Numsubgroupsizes)
|
||||
fmt.Printf("%-28s %v\n", "Subgroup Sizes:", cprop.Subgroupsizes[:])
|
||||
fmt.Printf("%-28s %v\n", "Subgroup Sizes:", cprop.Subgroupsizes[:cprop.Numsubgroupsizes])
|
||||
|
||||
var (
|
||||
X, Y, Z = uintptr(cprop.Maxgroupsizex), uintptr(1), uintptr(1)
|
||||
@@ -84,7 +84,7 @@ func main() {
|
||||
fmt.Printf("%-28s %d\n", "Total Elements (N):", N)
|
||||
fmt.Printf("%-28s %d MiB\n", "Buffer Size:", bufsz/1024/1024)
|
||||
|
||||
q, err := ctx.CommandQueueCreate(dev)
|
||||
q, err := ctx.CommandQueueCreate(dev, gozel.ZE_COMMAND_QUEUE_MODE_DEFAULT)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
@@ -135,11 +135,11 @@ func main() {
|
||||
}
|
||||
defer krn.Destroy()
|
||||
|
||||
err = krn.SetArgumentValue(0, unsafe.Sizeof(uintptr(0)), unsafe.Pointer(&dbufV1))
|
||||
err = krn.SetArgumentValue(0, &dbufV1)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
err = krn.SetArgumentValue(1, unsafe.Sizeof(uintptr(0)), unsafe.Pointer(&dbufV2))
|
||||
err = krn.SetArgumentValue(1, &dbufV2)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
@@ -154,16 +154,16 @@ func main() {
|
||||
}
|
||||
defer lstpre.Destroy()
|
||||
|
||||
err = lstpre.AppendMemoryCopy(dbufV1, hbufV1, bufsz)
|
||||
err = lstpre.AppendMemoryCopy(dbufV1, hbufV1, bufsz, 0)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
err = lstpre.AppendMemoryCopy(dbufV2, hbufV2, bufsz)
|
||||
err = lstpre.AppendMemoryCopy(dbufV2, hbufV2, bufsz, 0)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
err = lstpre.AppendBarrier()
|
||||
err = lstpre.AppendBarrier(0)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
@@ -181,12 +181,12 @@ func main() {
|
||||
|
||||
err = lstcalc.AppendLaunchKernel(krn, &gozel.ZeGroupCount{
|
||||
Groupcountx: uint32(groupCount), Groupcounty: 1, Groupcountz: 1,
|
||||
})
|
||||
}, 0)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
err = lstcalc.AppendBarrier()
|
||||
err = lstcalc.AppendBarrier(0)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
@@ -202,7 +202,7 @@ func main() {
|
||||
}
|
||||
defer lstpost.Destroy()
|
||||
|
||||
err = lstpost.AppendMemoryCopy(hbufV1, dbufV1, bufsz)
|
||||
err = lstpost.AppendMemoryCopy(hbufV1, dbufV1, bufsz, 0)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
@@ -217,7 +217,7 @@ func main() {
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
err = q.Synchronize()
|
||||
err = q.Synchronize(math.MaxUint64)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
@@ -4,18 +4,21 @@ target datalayout = "e-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:
|
||||
target triple = "spirv64-unknown-unknown"
|
||||
|
||||
@__spirv_BuiltInGlobalInvocationId = external local_unnamed_addr addrspace(1) constant <3 x i64>, align 32
|
||||
@__spirv_BuiltInGlobalOffset = external local_unnamed_addr addrspace(1) constant <3 x i64>, align 32
|
||||
|
||||
; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: readwrite, inaccessiblemem: write)
|
||||
define spir_kernel void @__sycl_kernel_vector_add(ptr addrspace(1) noundef align 4 captures(none) %0, ptr addrspace(1) noundef readonly align 4 captures(none) %1) local_unnamed_addr #0 !kernel_arg_buffer_location !6 !sycl_fixed_targets !7 !sycl_kernel_omit_args !8 {
|
||||
%3 = load i64, ptr addrspace(1) @__spirv_BuiltInGlobalInvocationId, align 32, !noalias !9
|
||||
%4 = icmp ult i64 %3, 2147483648
|
||||
tail call void @llvm.assume(i1 %4)
|
||||
%5 = getelementptr inbounds float, ptr addrspace(1) %1, i64 %3
|
||||
%6 = load float, ptr addrspace(1) %5, align 4, !tbaa !16
|
||||
%7 = getelementptr inbounds float, ptr addrspace(1) %0, i64 %3
|
||||
%8 = load float, ptr addrspace(1) %7, align 4, !tbaa !16
|
||||
%9 = fadd float %8, %6
|
||||
store float %9, ptr addrspace(1) %7, align 4, !tbaa !16
|
||||
%4 = load i64, ptr addrspace(1) @__spirv_BuiltInGlobalOffset, align 32, !noalias !16
|
||||
%5 = sub i64 %3, %4
|
||||
%6 = icmp ult i64 %5, 2147483648
|
||||
tail call void @llvm.assume(i1 %6)
|
||||
%7 = getelementptr inbounds float, ptr addrspace(1) %1, i64 %5
|
||||
%8 = load float, ptr addrspace(1) %7, align 4, !tbaa !23
|
||||
%9 = getelementptr inbounds float, ptr addrspace(1) %0, i64 %5
|
||||
%10 = load float, ptr addrspace(1) %9, align 4, !tbaa !23
|
||||
%11 = fadd float %10, %8
|
||||
store float %11, ptr addrspace(1) %9, align 4, !tbaa !23
|
||||
ret void
|
||||
}
|
||||
|
||||
@@ -48,7 +51,14 @@ attributes #1 = { nocallback nofree nosync nounwind willreturn memory(inaccessib
|
||||
!13 = distinct !{!13, !"_ZN7__spirv22initGlobalInvocationIdILi1EN4sycl3_V12idILi1EEEEET0_v"}
|
||||
!14 = distinct !{!14, !15, !"_ZNK4sycl3_V17nd_itemILi1EE13get_global_idEv: argument 0"}
|
||||
!15 = distinct !{!15, !"_ZNK4sycl3_V17nd_itemILi1EE13get_global_idEv"}
|
||||
!16 = !{!17, !17, i64 0}
|
||||
!17 = !{!"float", !18, i64 0}
|
||||
!18 = !{!"omnipotent char", !19, i64 0}
|
||||
!19 = !{!"Simple C++ TBAA"}
|
||||
!16 = !{!17, !19, !21}
|
||||
!17 = distinct !{!17, !18, !"_ZN7__spirv23InitSizesSTGlobalOffsetILi1EN4sycl3_V12idILi1EEEE8initSizeEv: argument 0"}
|
||||
!18 = distinct !{!18, !"_ZN7__spirv23InitSizesSTGlobalOffsetILi1EN4sycl3_V12idILi1EEEE8initSizeEv"}
|
||||
!19 = distinct !{!19, !20, !"_ZN7__spirv16initGlobalOffsetILi1EN4sycl3_V12idILi1EEEEET0_v: argument 0"}
|
||||
!20 = distinct !{!20, !"_ZN7__spirv16initGlobalOffsetILi1EN4sycl3_V12idILi1EEEEET0_v"}
|
||||
!21 = distinct !{!21, !22, !"_ZNK4sycl3_V17nd_itemILi1EE10get_offsetEv: argument 0"}
|
||||
!22 = distinct !{!22, !"_ZNK4sycl3_V17nd_itemILi1EE10get_offsetEv"}
|
||||
!23 = !{!24, !24, i64 0}
|
||||
!24 = !{!"float", !25, i64 0}
|
||||
!25 = !{!"omnipotent char", !26, i64 0}
|
||||
!26 = !{!"Simple C++ TBAA"}
|
||||
|
||||
Binary file not shown.
Reference in New Issue
Block a user