Skip to content

Commit

Permalink
Merge pull request #516 from CrayLabs/develop
Browse files Browse the repository at this point in the history
Merge develop to master for release

[ committed by @MattToast ]
[ reviewed by @al-rigazzi ]
  • Loading branch information
MattToast authored Sep 27, 2024
2 parents 1f694f1 + df55643 commit a9df20a
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 4 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ endif (POLICY CMP0048)

## Project definition for the SmartRedis
cmake_minimum_required(VERSION 3.13)
project(SmartRedis VERSION "0.6.0")
project(SmartRedis VERSION "0.6.1")

## Specify options for the SmartRedis project
option(BUILD_FORTRAN "Build the fortran client library" OFF)
Expand Down
17 changes: 17 additions & 0 deletions doc/changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,22 @@
# Changelog

### 0.6.1

Released on 27 September, 2024

Description

- Fix a memory leak in the Fortran Dataset implementation

Detailed Notes

- The dataset object, if used in a loop, would leave memory dangling.
To alleviate this, a final procedure has been implemented. Fortran
compilers, however, are notoriously bad at detecting when an object
goes out of scope and to destroy them automatically. We thus also
provide an explicit destructor procedure.
([PR514](https://github.com/CrayLabs/SmartRedis/pull/514))

### 0.6.0

Released on 25 September, 2024
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = smartredis
version = 0.6.0
version = 0.6.1
description = RedisAI clients for SmartSim
long_description = file: README.md
long_description_content_type=text/markdown
Expand Down
24 changes: 22 additions & 2 deletions src/fortran/dataset.F90
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ module smartredis_dataset

use iso_c_binding, only : c_ptr, c_char, c_int
use iso_c_binding, only : c_int8_t, c_int16_t, c_int32_t, c_int64_t, c_float, c_double, c_size_t
use iso_c_binding, only : c_loc, c_f_pointer
use iso_c_binding, only : c_loc, c_f_pointer, c_associated

use, intrinsic :: iso_fortran_env, only: stderr => error_unit

Expand Down Expand Up @@ -65,9 +65,13 @@ module smartredis_dataset

!> Initialize a new dataset with a given name
procedure :: initialize => initialize_dataset
!> Destroy the underlying C++ object
final :: final_destructor
procedure :: destructor
!> Access the raw C pointer for the dataset
procedure :: get_c_pointer


! Metadata procedures
!> Add metadata to the dataset with a given field and string
procedure :: add_meta_string
Expand Down Expand Up @@ -144,6 +148,23 @@ function initialize_dataset(self, name) result(code)
code = dataset_constructor(c_name, name_length, self%dataset_ptr)
end function initialize_dataset

!> Final method (for compilers which support it)
subroutine final_destructor(self)
type(dataset_type), intent(inout) :: self
integer :: code

if (c_associated(self%dataset_ptr)) code = dataset_deconstructor(self%dataset_ptr)
end subroutine final_destructor

!> Destroy the dataset
function destructor(self) result(code)
class(dataset_type), intent(inout) :: self
integer :: code

code = 0
if (c_associated(self%dataset_ptr)) code = dataset_deconstructor(self%dataset_ptr)
end function destructor

!> Access the raw C pointer for the dataset
function get_c_pointer(self)
type(c_ptr) :: get_c_pointer
Expand Down Expand Up @@ -247,7 +268,6 @@ function add_tensor_double(self, name, data, dims) result(code)
c_dims_ptr, c_n_dims, data_type, c_fortran_contiguous)
end function add_tensor_double


!> Unpack a tensor into already allocated memory whose Fortran type is the equivalent 'int8' C-type
function unpack_dataset_tensor_i8(self, name, result, dims) result(code)
integer(kind=c_int8_t), DIM_RANK_SPEC, target, intent(out) :: result !< Array to be populated with data
Expand Down
9 changes: 9 additions & 0 deletions src/fortran/dataset/dataset_interfaces.inc
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,15 @@ interface
end function dataset_constructor
end interface
interface
function dataset_deconstructor( dataset ) bind(c, name="DeallocateDataSet")
use iso_c_binding, only : c_ptr
import :: enum_kind
integer(kind=enum_kind) :: dataset_deconstructor
type(c_ptr) :: dataset !< Pointer to the underlying dataset
end function dataset_deconstructor
end interface
interface
function dataset_to_string_c(client) bind(c, name="dataset_to_string")
use iso_c_binding, only : c_ptr, c_char
Expand Down

0 comments on commit a9df20a

Please sign in to comment.