Skip to content

Commit 7d16e29

Browse files
committed
Add simple example of using GDS VFD
1 parent 1e833ab commit 7d16e29

File tree

4 files changed

+97
-2
lines changed

4 files changed

+97
-2
lines changed

CMakeLists.txt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,14 @@ option(BUILD_DOCUMENTATION "Build documentation." ON)
316316
# add_subdirectory(Documentation/Doxygen)
317317
#endif()
318318

319+
#-----------------------------------------------------------------------------
320+
# Examples
321+
#-----------------------------------------------------------------------------
322+
option(BUILD_EXAMPLES "Build examples." ON)
323+
if(BUILD_EXAMPLES)
324+
add_subdirectory(examples)
325+
endif()
326+
319327
#-----------------------------------------------------------------------------
320328
# Testing
321329
#-----------------------------------------------------------------------------
@@ -398,4 +406,4 @@ if(NOT HDF5_VFD_GDS_EXTERNALLY_CONFIGURED)
398406
set(CPACK_SOURCE_IGNORE_FILES ".git*;/GitSetup/;/.git/;.swp$;.#;/#;.*~")
399407
set(CPACK_SOURCE_STRIP_FILES "")
400408
include(CPack)
401-
endif()
409+
endif()

examples/CMakeLists.txt

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
cmake_minimum_required(VERSION 2.8.12.2 FATAL_ERROR)
2+
3+
#------------------------------------------------------------------------------
4+
# Include source and build directories
5+
#------------------------------------------------------------------------------
6+
include_directories(
7+
${CMAKE_CURRENT_SOURCE_DIR}
8+
${CMAKE_CURRENT_BINARY_DIR}
9+
)
10+
11+
#-----------------------------------------------------------------------------
12+
# Define Sources
13+
#-----------------------------------------------------------------------------
14+
set(examples
15+
simple_dset_write
16+
)
17+
18+
foreach (example ${examples})
19+
add_executable (h5gds_${example}
20+
${CMAKE_CURRENT_SOURCE_DIR}/${example}.c
21+
)
22+
target_include_directories(h5gds_${example}
23+
PUBLIC ${CMAKE_SOURCE_DIR}/src
24+
)
25+
target_include_directories(h5gds_${example}
26+
PUBLIC "$<BUILD_INTERFACE:${HDF5_VFD_GDS_BUILD_INCLUDE_DEPENDENCIES}>"
27+
$<INSTALL_INTERFACE:${HDF5_VFD_GDS_INSTALL_INCLUDE_INTERFACE}>
28+
)
29+
target_include_directories(h5gds_${example}
30+
SYSTEM PUBLIC ${HDF5_VFD_GDS_EXT_INCLUDE_DEPENDENCIES}
31+
)
32+
target_link_libraries(h5gds_${example}
33+
${HDF5_VFD_GDS_EXPORTED_LIBS}
34+
${HDF5_VFD_GDS_EXT_LIB_DEPENDENCIES}
35+
${HDF5_VFD_GDS_EXT_PKG_DEPENDENCIES}
36+
)
37+
endforeach()

examples/simple_dset_write.c

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#include <hdf5.h>
2+
#include <cuda.h>
3+
#include <cuda_runtime.h>
4+
5+
#include "H5FDgds.h"
6+
7+
#define FILENAME "gds_simple_dset_write.h5"
8+
#define DIM_SIZE 10
9+
10+
int
11+
main(int argc, char **argv)
12+
{
13+
hsize_t i, dims[] = { DIM_SIZE, DIM_SIZE };
14+
hid_t file_id = H5I_INVALID_HID;
15+
hid_t fapl_id = H5I_INVALID_HID;
16+
hid_t dset_id = H5I_INVALID_HID;
17+
hid_t space_id = H5I_INVALID_HID;
18+
int data[DIM_SIZE * DIM_SIZE];
19+
int *cuda_buf = NULL;
20+
21+
fapl_id = H5Pcreate(H5P_FILE_ACCESS);
22+
23+
H5Pset_fapl_gds(fapl_id, MBOUNDARY_DEF, FBSIZE_DEF, CBSIZE_DEF);
24+
25+
file_id = H5Fcreate(FILENAME, H5F_ACC_TRUNC, H5P_DEFAULT, fapl_id);
26+
27+
space_id = H5Screate_simple(2, dims, NULL);
28+
29+
dset_id = H5Dcreate2(file_id, "dset", H5T_NATIVE_INT, space_id, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
30+
31+
for (i = 0; i < dims[0] * dims[1]; i++)
32+
data[i] = i;
33+
34+
/* Allocate memory on CUDA device and copy data into that buffer */
35+
cudaMalloc((void **)&cuda_buf, DIM_SIZE * DIM_SIZE * sizeof(int));
36+
cudaMemcpy(cuda_buf, data, DIM_SIZE * DIM_SIZE * sizeof(int), cudaMemcpyHostToDevice);
37+
38+
/* Write dataset using buffer allocated on CUDA device */
39+
H5Dwrite(dset_id, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, cuda_buf);
40+
41+
cudaFree(&cuda_buf);
42+
43+
H5Sclose(space_id);
44+
H5Dclose(dset_id);
45+
H5Pclose(fapl_id);
46+
H5Fclose(file_id);
47+
48+
return 0;
49+
}
50+

src/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ if(HDF5_VFD_GDS_ENABLE_COVERAGE)
5151
set_coverage_flags(hdf5_vfd_gds)
5252
endif()
5353

54-
set(HDF5_VFD_GDS_EXPORTED_LIBS hdf5_vfd_gds ${HDF5_VFD_GDS_EXPORTED_LIBS})
54+
set(HDF5_VFD_GDS_EXPORTED_LIBS hdf5_vfd_gds ${HDF5_VFD_GDS_EXPORTED_LIBS} PARENT_SCOPE)
5555

5656
#-----------------------------------------------------------------------------
5757
# Specify project header files to be installed

0 commit comments

Comments
 (0)