Skip to content

Commit

Permalink
Update macro to be more specific
Browse files Browse the repository at this point in the history
  • Loading branch information
ashao committed May 29, 2023
1 parent 66f33b3 commit 620353b
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 28 deletions.
31 changes: 17 additions & 14 deletions src/fortran/client.F90
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,13 @@
! OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
! OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

! Note the below macros are here to allow compilation with Nvidia drivers
! While assumed size should be sufficient, this does not seem to work with
! Intel and GNU (however those have support for assumed rank)
#ifdef __NVCOMPILER
#define DIM_DEF dimension(*)
#define DIM_RANK_SPEC dimension(*)
#else
#define DIM_DEF dimension(..)
#define DIM_RANK_SPEC dimension(..)
#endif

module smartredis_client
Expand Down Expand Up @@ -466,7 +469,7 @@ end function poll_key

!> Put a tensor whose Fortran type is the equivalent 'int8' C-type
function put_tensor_i8(self, name, data, dims) result(code)
integer(kind=c_int8_t), DIM_DEF, target, intent(in) :: data !< Data to be sent
integer(kind=c_int8_t), DIM_RANK_SPEC, target, intent(in) :: data !< Data to be sent
class(client_type), intent(in) :: self !< Fortran SmartRedis client
character(len=*), intent(in) :: name !< The unique name used to store in the database
integer, dimension(:), intent(in) :: dims !< The length of each dimension
Expand All @@ -482,7 +485,7 @@ end function put_tensor_i8

!> Put a tensor whose Fortran type is the equivalent 'int16' C-type
function put_tensor_i16(self, name, data, dims) result(code)
integer(kind=c_int16_t), DIM_DEF, target, intent(in) :: data !< Data to be sent
integer(kind=c_int16_t), DIM_RANK_SPEC, target, intent(in) :: data !< Data to be sent
class(client_type), intent(in) :: self !< Fortran SmartRedis client
character(len=*), intent(in) :: name !< The unique name used to store in the database
integer, dimension(:), intent(in) :: dims !< The length of each dimension
Expand All @@ -498,7 +501,7 @@ end function put_tensor_i16

!> Put a tensor whose Fortran type is the equivalent 'int32' C-type
function put_tensor_i32(self, name, data, dims) result(code)
integer(kind=c_int32_t), DIM_DEF, target, intent(in) :: data !< Data to be sent
integer(kind=c_int32_t), DIM_RANK_SPEC, target, intent(in) :: data !< Data to be sent
class(client_type), intent(in) :: self !< Fortran SmartRedis client
character(len=*), intent(in) :: name !< The unique name used to store in the database
integer, dimension(:), intent(in) :: dims !< The length of each dimension
Expand All @@ -514,7 +517,7 @@ end function put_tensor_i32

!> Put a tensor whose Fortran type is the equivalent 'int64' C-type
function put_tensor_i64(self, name, data, dims) result(code)
integer(kind=c_int64_t), DIM_DEF, target, intent(in) :: data !< Data to be sent
integer(kind=c_int64_t), DIM_RANK_SPEC, target, intent(in) :: data !< Data to be sent
class(client_type), intent(in) :: self !< Fortran SmartRedis client
character(len=*), intent(in) :: name !< The unique name used to store in the database
integer, dimension(:), intent(in) :: dims !< The length of each dimension
Expand All @@ -530,7 +533,7 @@ end function put_tensor_i64

!> Put a tensor whose Fortran type is the equivalent 'float' C-type
function put_tensor_float(self, name, data, dims) result(code)
real(kind=c_float), DIM_DEF, target, intent(in) :: data !< Data to be sent
real(kind=c_float), DIM_RANK_SPEC, target, intent(in) :: data !< Data to be sent
class(client_type), intent(in) :: self !< Fortran SmartRedis client
character(len=*), intent(in) :: name !< The unique name used to store in the database
integer, dimension(:), intent(in) :: dims !< The length of each dimension
Expand All @@ -546,7 +549,7 @@ end function put_tensor_float

!> Put a tensor whose Fortran type is the equivalent 'double' C-type
function put_tensor_double(self, name, data, dims) result(code)
real(kind=c_double), DIM_DEF, target, intent(in) :: data !< Data to be sent
real(kind=c_double), DIM_RANK_SPEC, target, intent(in) :: data !< Data to be sent
class(client_type), intent(in) :: self !< Fortran SmartRedis client
character(len=*), intent(in) :: name !< The unique name used to store in the database
integer, dimension(:), intent(in) :: dims !< The length of each dimension
Expand All @@ -562,7 +565,7 @@ end function put_tensor_double

!> Put a tensor whose Fortran type is the equivalent 'int8' C-type
function unpack_tensor_i8(self, name, result, dims) result(code)
integer(kind=c_int8_t), DIM_DEF, target, intent(out) :: result !< Data to be sent
integer(kind=c_int8_t), DIM_RANK_SPEC, target, intent(out) :: result !< Data to be sent
class(client_type), intent(in) :: self !< Pointer to the initialized client
character(len=*), intent(in) :: name !< The name to use to place the tensor
integer, dimension(:), intent(in) :: dims !< Length along each dimension of the tensor
Expand All @@ -578,7 +581,7 @@ end function unpack_tensor_i8

!> Put a tensor whose Fortran type is the equivalent 'int16' C-type
function unpack_tensor_i16(self, name, result, dims) result(code)
integer(kind=c_int16_t), DIM_DEF, target, intent(out) :: result !< Data to be sent
integer(kind=c_int16_t), DIM_RANK_SPEC, target, intent(out) :: result !< Data to be sent
class(client_type), intent(in) :: self !< Pointer to the initialized client
character(len=*), intent(in) :: name !< The name to use to place the tensor
integer, dimension(:), intent(in) :: dims !< Length along each dimension of the tensor
Expand All @@ -594,7 +597,7 @@ end function unpack_tensor_i16

!> Put a tensor whose Fortran type is the equivalent 'int32' C-type
function unpack_tensor_i32(self, name, result, dims) result(code)
integer(kind=c_int32_t), DIM_DEF, target, intent(out) :: result !< Data to be sent
integer(kind=c_int32_t), DIM_RANK_SPEC, target, intent(out) :: result !< Data to be sent
class(client_type), intent(in) :: self !< Pointer to the initialized client
character(len=*), intent(in) :: name !< The name to use to place the tensor
integer, dimension(:), intent(in) :: dims !< Length along each dimension of the tensor
Expand All @@ -610,7 +613,7 @@ end function unpack_tensor_i32

!> Put a tensor whose Fortran type is the equivalent 'int64' C-type
function unpack_tensor_i64(self, name, result, dims) result(code)
integer(kind=c_int64_t), DIM_DEF, target, intent(out) :: result !< Data to be sent
integer(kind=c_int64_t), DIM_RANK_SPEC, target, intent(out) :: result !< Data to be sent
class(client_type), intent(in) :: self !< Pointer to the initialized client
character(len=*), intent(in) :: name !< The name to use to place the tensor
integer, dimension(:), intent(in) :: dims !< Length along each dimension of the tensor
Expand All @@ -626,7 +629,7 @@ end function unpack_tensor_i64

!> Put a tensor whose Fortran type is the equivalent 'float' C-type
function unpack_tensor_float(self, name, result, dims) result(code)
real(kind=c_float), DIM_DEF, target, intent(out) :: result !< Data to be sent
real(kind=c_float), DIM_RANK_SPEC, target, intent(out) :: result !< Data to be sent
class(client_type), intent(in) :: self !< Pointer to the initialized client
character(len=*), intent(in) :: name !< The name to use to place the tensor
integer, dimension(:), intent(in) :: dims !< Length along each dimension of the tensor
Expand All @@ -642,7 +645,7 @@ end function unpack_tensor_float

!> Put a tensor whose Fortran type is the equivalent 'double' C-type
function unpack_tensor_double(self, name, result, dims) result(code)
real(kind=c_double), DIM_DEF, target, intent(out) :: result !< Data to be sent
real(kind=c_double), DIM_RANK_SPEC, target, intent(out) :: result !< Data to be sent
class(client_type), intent(in) :: self !< Pointer to the initialized client
character(len=*), intent(in) :: name !< The name to use to place the tensor
integer, dimension(:), intent(in) :: dims !< Length along each dimension of the tensor
Expand Down
32 changes: 18 additions & 14 deletions src/fortran/dataset.F90
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,14 @@
! CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
! OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
! OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

! Note the below macros are here to allow compilation with Nvidia drivers
! While assumed size should be sufficient, this does not seem to work with
! Intel and GNU (however those have support for assumed rank)
#ifdef __NVCOMPILER
#define DIM_DEF dimension(*)
#define DIM_RANK_SPEC dimension(*)
#else
#define DIM_DEF dimension(..)
#define DIM_RANK_SPEC dimension(..)
#endif

module smartredis_dataset
Expand Down Expand Up @@ -149,7 +153,7 @@ end function get_c_pointer

!> Add a tensor to a dataset whose Fortran type is the equivalent 'int8' C-type
function add_tensor_i8(self, name, data, dims) result(code)
integer(kind=c_int8_t), DIM_DEF, target, intent(in) :: data !< Data to be sent
integer(kind=c_int8_t), DIM_RANK_SPEC, target, intent(in) :: data !< Data to be sent
class(dataset_type), intent(in) :: self !< Fortran SmartRedis dataset
character(len=*), intent(in) :: name !< The unique name used to store in the database
integer, dimension(:), intent(in) :: dims !< The length of each dimension
Expand All @@ -165,7 +169,7 @@ end function add_tensor_i8

!> Add a tensor to a dataset whose Fortran type is the equivalent 'int16' C-type
function add_tensor_i16(self, name, data, dims) result(code)
integer(kind=c_int16_t), DIM_DEF, target, intent(in) :: data !< Data to be sent
integer(kind=c_int16_t), DIM_RANK_SPEC, target, intent(in) :: data !< Data to be sent
class(dataset_type), intent(in) :: self !< Fortran SmartRedis dataset
character(len=*), intent(in) :: name !< The unique name used to store in the database
integer, dimension(:), intent(in) :: dims !< The length of each dimension
Expand All @@ -181,7 +185,7 @@ end function add_tensor_i16

!> Add a tensor to a dataset whose Fortran type is the equivalent 'int32' C-type
function add_tensor_i32(self, name, data, dims) result(code)
integer(kind=c_int32_t), DIM_DEF, target, intent(in) :: data !< Data to be sent
integer(kind=c_int32_t), DIM_RANK_SPEC, target, intent(in) :: data !< Data to be sent
class(dataset_type), intent(in) :: self !< Fortran SmartRedis dataset
character(len=*), intent(in) :: name !< The unique name used to store in the database
integer, dimension(:), intent(in) :: dims !< The length of each dimension
Expand All @@ -197,7 +201,7 @@ end function add_tensor_i32

!> Add a tensor to a dataset whose Fortran type is the equivalent 'int64' C-type
function add_tensor_i64(self, name, data, dims) result(code)
integer(kind=c_int64_t), DIM_DEF, target, intent(in) :: data !< Data to be sent
integer(kind=c_int64_t), DIM_RANK_SPEC, target, intent(in) :: data !< Data to be sent
class(dataset_type), intent(in) :: self !< Fortran SmartRedis dataset
character(len=*), intent(in) :: name !< The unique name used to store in the database
integer, dimension(:), intent(in) :: dims !< The length of each dimension
Expand All @@ -213,7 +217,7 @@ end function add_tensor_i64

!> Add a tensor to a dataset whose Fortran type is the equivalent 'float' C-type
function add_tensor_float(self, name, data, dims) result(code)
real(kind=c_float), DIM_DEF, target, intent(in) :: data !< Data to be sent
real(kind=c_float), DIM_RANK_SPEC, target, intent(in) :: data !< Data to be sent
class(dataset_type), intent(in) :: self !< Fortran SmartRedis dataset
character(len=*), intent(in) :: name !< The unique name used to store in the database
integer, dimension(:), intent(in) :: dims !< The length of each dimension
Expand All @@ -229,7 +233,7 @@ end function add_tensor_float

!> Add a tensor to a dataset whose Fortran type is the equivalent 'double' C-type
function add_tensor_double(self, name, data, dims) result(code)
real(kind=c_double), DIM_DEF, target, intent(in) :: data !< Data to be sent
real(kind=c_double), DIM_RANK_SPEC, target, intent(in) :: data !< Data to be sent
class(dataset_type), intent(in) :: self !< Fortran SmartRedis dataset
character(len=*), intent(in) :: name !< The unique name used to store in the database
integer, dimension(:), intent(in) :: dims !< The length of each dimension
Expand All @@ -246,7 +250,7 @@ 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_DEF, target, intent(out) :: result !< Array to be populated with data
integer(kind=c_int8_t), DIM_RANK_SPEC, target, intent(out) :: result !< Array to be populated with data
class(dataset_type), intent(in) :: self !< Pointer to the initialized dataset
character(len=*), intent(in) :: name !< The name to use to place the tensor
integer, dimension(:), intent(in) :: dims !< Length along each dimension of the tensor
Expand All @@ -262,7 +266,7 @@ end function unpack_dataset_tensor_i8

!> Unpack a tensor into already allocated memory whose Fortran type is the equivalent 'int16' C-type
function unpack_dataset_tensor_i16(self, name, result, dims) result(code)
integer(kind=c_int16_t), DIM_DEF, target, intent(out) :: result !< Array to be populated with data
integer(kind=c_int16_t), DIM_RANK_SPEC, target, intent(out) :: result !< Array to be populated with data
class(dataset_type), intent(in) :: self !< Pointer to the initialized dataset
character(len=*), intent(in) :: name !< The name to use to place the tensor
integer, dimension(:), intent(in) :: dims !< Length along each dimension of the tensor
Expand All @@ -278,7 +282,7 @@ end function unpack_dataset_tensor_i16

!> Unpack a tensor into already allocated memory whose Fortran type is the equivalent 'int32' C-type
function unpack_dataset_tensor_i32(self, name, result, dims) result(code)
integer(kind=c_int32_t), DIM_DEF, target, intent(out) :: result !< Array to be populated with data
integer(kind=c_int32_t), DIM_RANK_SPEC, target, intent(out) :: result !< Array to be populated with data
class(dataset_type), intent(in) :: self !< Pointer to the initialized dataset
character(len=*), intent(in) :: name !< The name to use to place the tensor
integer, dimension(:), intent(in) :: dims !< Length along each dimension of the tensor
Expand All @@ -294,7 +298,7 @@ end function unpack_dataset_tensor_i32

!> Unpack a tensor into already allocated memory whose Fortran type is the equivalent 'int64' C-type
function unpack_dataset_tensor_i64(self, name, result, dims) result(code)
integer(kind=c_int64_t), DIM_DEF, target, intent(out) :: result !< Array to be populated with data
integer(kind=c_int64_t), DIM_RANK_SPEC, target, intent(out) :: result !< Array to be populated with data
class(dataset_type), intent(in) :: self !< Pointer to the initialized dataset
character(len=*), intent(in) :: name !< The name to use to place the tensor
integer, dimension(:), intent(in) :: dims !< Length along each dimension of the tensor
Expand All @@ -310,7 +314,7 @@ end function unpack_dataset_tensor_i64

!> Unpack a tensor into already allocated memory whose Fortran type is the equivalent 'float' C-type
function unpack_dataset_tensor_float(self, name, result, dims) result(code)
real(kind=c_float), DIM_DEF, target, intent(out) :: result !< Array to be populated with data
real(kind=c_float), DIM_RANK_SPEC, target, intent(out) :: result !< Array to be populated with data
class(dataset_type), intent(in) :: self !< Pointer to the initialized dataset
character(len=*), intent(in) :: name !< The name to use to place the tensor
integer, dimension(:), intent(in) :: dims !< Length along each dimension of the tensor
Expand All @@ -326,7 +330,7 @@ end function unpack_dataset_tensor_float

!> Unpack a tensor into already allocated memory whose Fortran type is the equivalent 'double' C-type
function unpack_dataset_tensor_double(self, name, result, dims) result(code)
real(kind=c_double), DIM_DEF, target, intent(out) :: result !< Array to be populated with data
real(kind=c_double), DIM_RANK_SPEC, target, intent(out) :: result !< Array to be populated with data
class(dataset_type), intent(in) :: self !< Pointer to the initialized dataset
character(len=*), intent(in) :: name !< The name to use to place the tensor
integer, dimension(:), intent(in) :: dims !< Length along each dimension of the tensor
Expand Down

0 comments on commit 620353b

Please sign in to comment.