Skip to content

Commit c96aede

Browse files
committed
feat(gpu): add more mem api
1 parent 0ebec86 commit c96aede

4 files changed

Lines changed: 16 additions & 6 deletions

File tree

gpu/mem.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,16 @@ func MemAllocHostDevicePair(size uintptr, alignment uintptr) (h, d unsafe.Pointe
1616
return
1717
}
1818

19+
// MemAllocHost allocs host mem.
20+
func MemAllocHost(size uintptr, alignment uintptr) (unsafe.Pointer, error) {
21+
return g().ctx.MemAllocHost(size, alignment)
22+
}
23+
24+
// MemAllocDevice allocs device mem.
25+
func MemAllocDevice(size uintptr, alignment uintptr) (unsafe.Pointer, error) {
26+
return g().ctx.MemAllocDevice(g().dev, size, alignment)
27+
}
28+
1929
// MemCopyGo2Host copies go array to host mem and returns the go array repr of dst.
2030
func MemCopyGo2Host[T any](dst unsafe.Pointer, src []T) []T {
2131
dstSlice := unsafe.Slice((*T)(dst), len(src))

internal/build/darkimg_ocl.cl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ kernel void isdark(
1919

2020
if (x < outW && y < outH) {
2121
float2 normCoord = (float2)(
22-
(float)x / (float)outW,
23-
(float)y / (float)outH
22+
((float)x + 0.5f) / (float)outW,
23+
((float)y + 0.5f) / (float)outH
2424
);
2525

2626
float4 pixel = read_imagef(inputImg, smp, normCoord);

internal/build/kmeans_ocl.cl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ kernel void assign_first_iter(
2525
pixel = read_imagef(inputImg, (int2)(x, y));
2626
} else {
2727
float2 normCoord = (float2)(
28-
(float)x / (float)dstW,
29-
(float)y / (float)dstH
28+
((float)x + 0.5f) / (float)dstW,
29+
((float)y + 0.5f) / (float)dstH
3030
);
3131
pixel = read_imagef(inputImg, smp, normCoord);
3232
}

internal/build/resize_ocl.cl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ kernel void scale(
1313
}
1414

1515
float2 normCoord = (float2)(
16-
(float)x / (float)outW,
17-
(float)y / (float)outH
16+
((float)x + 0.5f) / (float)outW,
17+
((float)y + 0.5f) / (float)outH
1818
);
1919

2020
float4 pixel = read_imagef(inputImg, smp, normCoord);

0 commit comments

Comments
 (0)