{"id":18821617,"url":"https://github.com/octu0/example-halide-go","last_synced_at":"2026-01-18T09:30:17.835Z","repository":{"id":98859303,"uuid":"594742794","full_name":"octu0/example-halide-go","owner":"octu0","description":"Example implementation of Halide with go generate as a helper","archived":false,"fork":false,"pushed_at":"2023-04-17T11:45:39.000Z","size":232,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-12-30T03:43:19.203Z","etag":null,"topics":["cgo","cgo-bindings","go-generate","golang","halide"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/octu0.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-01-29T14:07:44.000Z","updated_at":"2024-08-29T01:40:30.000Z","dependencies_parsed_at":"2023-05-07T02:04:59.607Z","dependency_job_id":null,"html_url":"https://github.com/octu0/example-halide-go","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/octu0%2Fexample-halide-go","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/octu0%2Fexample-halide-go/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/octu0%2Fexample-halide-go/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/octu0%2Fexample-halide-go/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/octu0","download_url":"https://codeload.github.com/octu0/example-halide-go/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239758900,"owners_count":19692041,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cgo","cgo-bindings","go-generate","golang","halide"],"created_at":"2024-11-08T00:44:54.330Z","updated_at":"2026-01-18T09:30:17.774Z","avatar_url":"https://github.com/octu0.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# `example-halide-go`\n\n`example-halide-go` is an example implementation of Halide with `go generate` as a helper.\n\n### How to use\n\nC++ code is written as below:\n\n```cpp\nFunc rotate90(Func input, Expr width, Expr height) {\n  Var x(\"x\"), y(\"y\"), ch(\"ch\");\n  Expr w = width - 1;\n  Expr h = height - 1;\n\n  Region src_bounds = {{0, w},{0, h},{0, 4}};\n  Func in = BoundaryConditions::constant_exterior(input, 0, src_bounds);\n\n  Func r = Func(\"rotate90\");\n  r(x, y, ch) = in(y, h - x, ch);\n  return r;\n}\n```\n\nand, Set the needed parameters for the input and output of the function and write them to be returned by std::tuple.\n\n```cpp\nstd::tuple\u003cFunc, std::vector\u003cArgument\u003e\u003e export_rotate90() {\n  ImageParam src(UInt(8), 3, \"src\");\n  // input data format\n  src.dim(0).set_stride(4);\n  src.dim(2).set_stride(1);\n  src.dim(2).set_bounds(0, 4);\n\n  Param\u003cint32_t\u003e width{\"width\", 1920};\n  Param\u003cint32_t\u003e height{\"height\", 1080};\n\n  Func fn = rotate90(src.in(), width, height);\n\n  // output data format\n  OutputImageParam out = fn.output_buffer();\n  out.dim(0).set_stride(4);\n  out.dim(2).set_stride(1);\n  out.dim(2).set_bounds(0, 4);\n\n  std::vector\u003cArgument\u003e args = {src, width, height};\n  std::tuple\u003cFunc, std::vector\u003cArgument\u003e\u003e tuple = std::make_tuple(fn, args);\n  return tuple;\n}\n```\n\nwith header(rotate.hpp)\n\n```cpp\n#include \u003cHalide.h\u003e\nusing namespace Halide;\n\nstd::tuple\u003cFunc, std::vector\u003cArgument\u003e\u003e export_rotate90();\n```\n\nGo code is to call it as below:\n\n```go\npackage example\n//go:generate go run ./cmd/download/halide.go\n\n/*\n#cgo CFLAGS: -I${SRCDIR}/include\n#cgo LDFLAGS: -L${SRCDIR}/lib -ldl -lm\n#cgo darwin LDFLAGS: -lrotate90_darwin\n#cgo linux LDFLAGS: -lrotate90_linux\n\n#include \"rotate90.h\"\n*/\nimport \"C\"\n\n//go:generate go run ./cmd/compile/object.go f rotate90 rotate.cpp\nfunc Rotate90(in *image.RGBA) (*image.RGBA, error) {\n\twidth, height := in.Rect.Dx(), in.Rect.Dy()\n\tout := image.NewRGBA(image.Rect(0, 0, height, width))\n\toutBuf, err := HalideBufferRGBA(out.Pix, height, width)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tdefer HalideFreeBuffer(outBuf)\n\n\tinBuf, err := HalideBufferRGBA(in.Pix, width, height)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tdefer HalideFreeBuffer(inBuf)\n\n\tret := C.rotate90(\n\t\tinBuf,\n\t\tC.int(width),\n\t\tC.int(height),\n\t\toutBuf,\n\t)\n\tif ret != C.int(0) {\n\t\treturn nil, fmt.Errorf(\"failed to rotate90\")\n\t}\n\treturn out, nil\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foctu0%2Fexample-halide-go","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Foctu0%2Fexample-halide-go","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foctu0%2Fexample-halide-go/lists"}