Skip to content

Commit

Permalink
fix for fields vs non vtk-m supported type
Browse files Browse the repository at this point in the history
  • Loading branch information
cyrush committed Dec 6, 2023
1 parent 1e977d5 commit 6cd6d7a
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 77 deletions.
145 changes: 73 additions & 72 deletions src/libs/ascent/runtimes/ascent_vtkh_data_adapter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ GetExplicitCoordinateSystem(const conduit::Node &n_coords,

}


template<typename T>
vtkm::cont::Field GetField(const conduit::Node &node,
const std::string &field_name,
Expand Down Expand Up @@ -280,9 +281,9 @@ vtkm::cont::Field GetField(const conduit::Node &node,
// use ArrayHandleStride to create new field
//

// NOTE: In this case, the num_vals, needs to be
// NOTE: In this case, the num_vals, needs to be
// the full extent of the strided area3

int num_vals_expanded = num_vals * element_stride;
vtkm::cont::ArrayHandle<T> source_array = vtkm::cont::make_ArrayHandle(values_ptr,
num_vals_expanded,
Expand Down Expand Up @@ -1402,7 +1403,7 @@ VTKHDataAdapter::UnstructuredBlueprintToVTKmDataSet
else
{
// convert to int32
std::cerr << "INT32 unstructured conversion: non zero copy" << std::endl;
// std::cout << "INT32 unstructured conversion: non zero copy" << std::endl;
connectivity.Allocate(conn_size);
void *ptr = (void*) vtkh::GetVTKMPointer(connectivity);
Node n_tmp;
Expand All @@ -1420,7 +1421,7 @@ VTKHDataAdapter::UnstructuredBlueprintToVTKmDataSet
else
{
// convert to int64
std::cerr << "INT64 unstructured conversion: non zero copy" << std::endl;
// std::cout << "INT64 unstructured conversion: non zero copy" << std::endl;
connectivity.Allocate(conn_size);
void *ptr = (void*) vtkh::GetVTKMPointer(connectivity);
Node n_tmp;
Expand Down Expand Up @@ -1501,21 +1502,6 @@ VTKHDataAdapter::AddField(const std::string &field_name,
{
bool supported_type = false;

// if(n_vals.is_compact())
// {
// // we compile vtk-h with fp types
// if(n_vals.dtype().is_float32())
// {
// dset->AddField(detail::GetField<float32>(n_vals, field_name, assoc_str, topo_name, zero_copy));
// supported_type = true;
// }
// else if(n_vals.dtype().is_float64())
// {
// dset->AddField(detail::GetField<float64>(n_vals, field_name, assoc_str, topo_name, zero_copy));
// supported_type = true;
// }
// }

// vtk-m can stride as long as the strides are a multiple of the native stride

// we compile vtk-h with fp types
Expand All @@ -1524,15 +1510,15 @@ VTKHDataAdapter::AddField(const std::string &field_name,
// check that the byte stride is a multiple of native stride
index_t stride = n_vals.dtype().stride();
index_t element_stride = stride / sizeof(float32);

//std::cout << "field name: " << field_name << " <float32>"
// << " byte stride: " << stride
// << " element_stride: " << element_stride << std::endl;
// if element_stride is evenly divided by native, we are good to
// if element_stride is evenly divided by native, we are good to
// use vtk m array handles
if( stride % sizeof(float32) == 0 )
{
// in this case we can use a strided array handle
// in this case we can use a strided array handle
dset->AddField(detail::GetField<float32>(n_vals,
field_name,
assoc_str,
Expand All @@ -1543,18 +1529,18 @@ VTKHDataAdapter::AddField(const std::string &field_name,
}
}
else if(n_vals.dtype().is_float64())
{
{
// check that the byte stride is a multiple of native stride
index_t stride = n_vals.dtype().stride();
index_t element_stride = stride / sizeof(float64);
//std::cout << "field name: " << field_name << " <float64>"
// << " byte stride: " << stride
// << " element_stride: " << element_stride << std::endl;
// if element_stride is evenly divided by native, we are good to
// if element_stride is evenly divided by native, we are good to
// use vtk m array handles
if( stride % sizeof(float64) == 0 )
{
// in this case we can use a strided array handle
// in this case we can use a strided array handle
dset->AddField(detail::GetField<float64>(n_vals,
field_name,
assoc_str,
Expand All @@ -1564,62 +1550,72 @@ VTKHDataAdapter::AddField(const std::string &field_name,
supported_type = true;
}
}
else if(n_vals.dtype().is_int32())
{
// check that the byte stride is a multiple of native stride
index_t stride = n_vals.dtype().stride();
index_t element_stride = stride / sizeof(int32);
//std::cout << "field name: " << field_name << " <int32>"
// << " byte stride: " << stride
// << " element_stride: " << element_stride << std::endl;
// if element_stride is evenly divided by native, we are good to
// use vtk m array handles
if( stride % sizeof(int32) == 0 )
{
// in this case we can use a strided array handle
dset->AddField(detail::GetField<int32>(n_vals,
field_name,
assoc_str,
topo_name,
element_stride,
zero_copy));
supported_type = true;
}
}
else if(n_vals.dtype().is_int64())
{
// check that the byte stride is a multiple of native stride
index_t stride = n_vals.dtype().stride();
index_t element_stride = stride / sizeof(int64);
//std::cout << "field name: " << field_name << " <int64>"
// << " byte stride: " << stride
// << " element_stride: " << element_stride << std::endl;
// if element_stride is evenly divided by native, we are good to
// use vtk m array handles
if( stride % sizeof(int64) == 0 )
{
// in this case we can use a strided array handle
dset->AddField(detail::GetField<int64>(n_vals,
field_name,
assoc_str,
topo_name,
element_stride,
zero_copy));
supported_type = true;
}
}


// ***********************************************************************
// NOTE: TODO OUR VTK-M is not compiled with int32 and int64 support ...
// ***********************************************************************
// These cases fail and provide this error message:
// Execution failed with vtkm: Could not find appropriate cast for array in CastAndCall.
// Array: valueType=x storageType=N4vtkm4cont15StorageTagBasicE 27 values occupying 216 bytes [0 1 2 ... 24 25 26]
// TypeList: N4vtkm4ListIJfdEEE
// ***********************************************************************
//
// else if(n_vals.dtype().is_int32())
// {
// // check that the byte stride is a multiple of native stride
// index_t stride = n_vals.dtype().stride();
// index_t element_stride = stride / sizeof(int32);
// //std::cout << "field name: " << field_name << " <int32>"
// // << " byte stride: " << stride
// // << " element_stride: " << element_stride << std::endl;
// // if element_stride is evenly divided by native, we are good to
// // use vtk m array handles
// if( stride % sizeof(int32) == 0 )
// {
// // in this case we can use a strided array handle
// dset->AddField(detail::GetField<int32>(n_vals,
// field_name,
// assoc_str,
// topo_name,
// element_stride,
// zero_copy));
// supported_type = true;
// }
// }
// else if(n_vals.dtype().is_int64())
// {
// // check that the byte stride is a multiple of native stride
// index_t stride = n_vals.dtype().stride();
// index_t element_stride = stride / sizeof(int64);
// //std::cout << "field name: " << field_name << " <int64>"
// // << " byte stride: " << stride
// // << " element_stride: " << element_stride << std::endl;
// // if element_stride is evenly divided by native, we are good to
// // use vtk m array handles
// if( stride % sizeof(int64) == 0 )
// {
// // in this case we can use a strided array handle
// dset->AddField(detail::GetField<int64>(n_vals,
// field_name,
// assoc_str,
// topo_name,
// element_stride,
// zero_copy));
// supported_type = true;
// }
// }

// vtk-m cant support zero copy for this layout or was not compiled to expose this datatype
// use float64 by default
if(!supported_type)
{
std::cerr << "WE ARE IN UNSUPPORTED DATA TYPE" << std::endl;
// std::cout << "WE ARE IN UNSUPPORTED DATA TYPE: "
// << n_vals.dtype().name() << std::endl;

// convert to float64, we use this as a comprise to cover the widest range
vtkm::cont::ArrayHandle<vtkm::Float64> vtkm_arr;
vtkm_arr.Allocate(num_vals);

// TODO -- FUTURE: Do this conversion w/ device if on device
void *ptr = (void*) vtkh::GetVTKMPointer(vtkm_arr);
Node n_tmp;
n_tmp.set_external(DataType::float64(num_vals),ptr);
Expand All @@ -1639,6 +1635,11 @@ VTKHDataAdapter::AddField(const std::string &field_name,
vtkm_arr));
}
}
// else
// {
// std::cout << "SUPPORTED DATA TYPE: "
// << n_vals.dtype().name() << std::endl;
// }
}
catch (vtkm::cont::Error error)
{
Expand Down
9 changes: 4 additions & 5 deletions src/tests/ascent/t_ascent_render_3d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,6 @@ TEST(ascent_render_3d, test_render_3d_original_bounds)
// remove old images before rendering
remove_test_image(output_file);


//
// Create the actions.
//
Expand Down Expand Up @@ -2643,7 +2642,7 @@ TEST(ascent_render_3d, test_render_3d_extreme_extents)
Ascent ascent;
ascent.open();
ascent.publish(mesh);

scenes["s1/image_prefix"] = output_file;
ascent.execute(actions);
// check that we created an image
Expand Down Expand Up @@ -2679,11 +2678,11 @@ TEST(ascent_render_3d, test_render_3d_extreme_extents)
// check that we created an image
// TODO: We expect this to fail until we address float64 vs float32 issues
EXPECT_FALSE(check_test_image(output_file));


//now with unstructured:
Node mesh_unstruct;

conduit::blueprint::mesh::topology::rectilinear::to_unstructured(mesh["topologies/topo"],
mesh_unstruct["topologies/topo"],
mesh_unstruct["coordsets/coords"]);
Expand Down Expand Up @@ -2712,7 +2711,7 @@ TEST(ascent_render_3d, test_render_3d_extreme_extents)
// TODO: We expect this to fail until we address float64 vs float32 issues
EXPECT_FALSE(check_test_image(output_file));


}


Expand Down

0 comments on commit 6cd6d7a

Please sign in to comment.