Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cbuffer/cbuffer.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func (b *CBuffer) Free() {

// Bytes returns the buffer as a byte slice.
//
// Ownership is not transferred: remember to free CBuffer afterwards.
// Ownership is not transferred: remember to free CBuffer afterward.
func (b *CBuffer) Bytes() []byte {
if b.data == nil {
return nil
Expand Down
4 changes: 4 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Gopjrt Changelog

# Next

* Fixed small memory leak of a VectorData wrapper when converting to HLO/StableHLO (#31).

# v0.6.2 - 2025/02/26

* Fixed C/C++ wrapper version.
Expand Down
10 changes: 8 additions & 2 deletions xlabuilder/xlacomputation.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,9 @@ func (comp *XlaComputation) SerializedHLO() *cbuffer.CBuffer {
}
var vectorData *C.VectorData
vectorData = (*C.VectorData)(C.XlaComputationSerializedHLO(unsafe.Pointer(comp.cXlaComputation)))
return cbuffer.New(unsafe.Pointer(vectorData.data), int(vectorData.count), true)
cBuf := cbuffer.New(unsafe.Pointer(vectorData.data), int(vectorData.count), true)
C.free(unsafe.Pointer(vectorData))
return cBuf
}

// HasStableHLO returns whether StableHLO support was included in the build -- it's very large, so by default it is not.
Expand Down Expand Up @@ -111,7 +113,9 @@ func (comp *XlaComputation) SerializedStableHLO() (*cbuffer.CBuffer, error) {
if err != nil {
return nil, errors.Wrapf(err, "while converting XlaComputation to StableHLO")
}
return cbuffer.New(unsafe.Pointer(vectorData.data), int(vectorData.count), true), nil
cBuf := cbuffer.New(unsafe.Pointer(vectorData.data), int(vectorData.count), true)
C.free(unsafe.Pointer(vectorData))
return cBuf, nil
}

// TextHLO generates the HLO program as a <serialized HLOModule proto> and returns its text representation.
Expand All @@ -130,6 +134,8 @@ func (comp *XlaComputation) TextHLO() string {
}

// TextStableHLO generates the StableHLO program.
//
// It returns an error if StableHLO code was not linked in (it's large). This can be checked with HasStableHLO.
func (comp *XlaComputation) TextStableHLO() (string, error) {
if comp.IsNil() {
return "", errors.New("XlaComputation is nil, maybe it has already been destroyed?")
Expand Down
Loading