-
Notifications
You must be signed in to change notification settings - Fork 111
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
GPU Fix call stack issue and support ggml (#1546)
- Loading branch information
Showing
3 changed files
with
121 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package gpuevent | ||
|
||
// Interval represents an interval with a low and high value | ||
type Symbol struct { | ||
Low, High uint64 | ||
Symbol string | ||
} | ||
|
||
// Node represents a node in the interval tree | ||
type Node struct { | ||
Symbol Symbol | ||
Max uint64 | ||
Left *Node | ||
Right *Node | ||
} | ||
|
||
// SymbolTree represents the interval tree | ||
type SymbolTree struct { | ||
Root *Node | ||
} | ||
|
||
// NewSymbolTree creates a new interval tree | ||
func NewSymbolTree() *SymbolTree { | ||
return &SymbolTree{} | ||
} | ||
|
||
// Insert inserts a new interval into the interval tree | ||
func (t *SymbolTree) Insert(sym Symbol) { | ||
t.Root = insert(t.Root, sym) | ||
} | ||
|
||
func insert(root *Node, sym Symbol) *Node { | ||
if root == nil { | ||
return &Node{ | ||
Symbol: sym, | ||
Max: sym.High, | ||
} | ||
} | ||
|
||
if sym.Low < root.Symbol.Low { | ||
root.Left = insert(root.Left, sym) | ||
} else { | ||
root.Right = insert(root.Right, sym) | ||
} | ||
|
||
if root.Max < sym.High { | ||
root.Max = sym.High | ||
} | ||
|
||
return root | ||
} | ||
|
||
// Search searches for intervals that overlap with the given point | ||
func (t *SymbolTree) Search(point uint64) []Symbol { | ||
var result []Symbol | ||
search(t.Root, point, &result) | ||
return result | ||
} | ||
|
||
func search(root *Node, point uint64, result *[]Symbol) { | ||
if root == nil { | ||
return | ||
} | ||
|
||
if root.Symbol.Low <= point && point < root.Symbol.High { | ||
*result = append(*result, root.Symbol) | ||
} | ||
|
||
if root.Left != nil && root.Left.Max >= point { | ||
search(root.Left, point, result) | ||
} | ||
|
||
search(root.Right, point, result) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package gpuevent | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestSymbolTree(t *testing.T) { | ||
tr := &SymbolTree{} | ||
|
||
tr.Insert(Symbol{Low: 100, High: 200, Symbol: "test"}) | ||
tr.Insert(Symbol{Low: 200, High: 300, Symbol: "test2"}) | ||
|
||
r := tr.Search(200) | ||
assert.Equal(t, 1, len(r)) | ||
assert.Equal(t, "test2", r[0].Symbol) | ||
} |