Skip to content

Commit

Permalink
things work, gonna try out the one line reinterpret_cast
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolemarsaglia committed Sep 10, 2024
1 parent 6b5245b commit 6903048
Showing 1 changed file with 108 additions and 71 deletions.
179 changes: 108 additions & 71 deletions src/libs/ascent/runtimes/ascent_vtkh_data_adapter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1535,7 +1535,7 @@ std::cerr << "AF 6" << std::endl;

try
{
std::cerr << "SUPPORTED" << std::endl;
std::cerr << "TRY SUPPORTED" << std::endl;
bool supported_type = false;

// vtk-m can stride as long as the strides are a multiple of the native stride
Expand Down Expand Up @@ -1598,6 +1598,7 @@ std::cerr << "stride \% sizeof(float64) = " << stride % sizeof(float64) << std::
zero_copy));
supported_type = true;
}
std::cerr << "HJERE ini end float64" << std::endl;
}
// ***********************************************************************
// NOTE: TODO OUR VTK-M is not compiled with int32 and int64 support ...
Expand All @@ -1607,93 +1608,99 @@ std::cerr << "stride \% sizeof(float64) = " << stride % sizeof(float64) << std::
// Array: valueType=x storageType=N4vtkm4cont15StorageTagBasicE 27 values occupying 216 bytes [0 1 2 ... 24 25 26]
// TypeList: N4vtkm4ListIJfdEEE
// ***********************************************************************
// ***********************************************************************
// NOTE: int32 should work as of sept 10 2024
// ***********************************************************************
//
// 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;
// }
// }
//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;
// }
//}
//else if(n_vals.dtype().is_uint64())
//{
// // check that the byte stride is a multiple of native stride
// index_t stride = n_vals.dtype().stride();
// index_t element_stride = stride / sizeof(uint64);
// //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(uint64) == 0 )
// {
// // in this case we can use a strided array handle
// dset->AddField(detail::GetField<uint64>(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 << "NOT SUPPORTED" << std::endl;

// std::cout << "WE ARE IN UNSUPPORTED DATA TYPE: "
// << n_vals.dtype().name() << std::endl;
if(n_vals.dtype().is_uint64())
{
// std::cout << "WE ARE IN UNSUPPORTED DATA TYPE: "
// << n_vals.dtype().name() << std::endl;
std::cerr << "HERE IN UNSUPPORTED uint75" << std::endl;

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

std::cerr << "AF 9" << std::endl;
// 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);
const unsigned long long *input = n_vals.value();
std::cerr << "AF 10" << std::endl;
vtkm::cont::ArrayHandle<unsigned long long> input_arr = vtkm::cont::make_ArrayHandle(input, num_vals, vtkm::CopyFlag::Off);
std::cerr << "AF 11" << std::endl;
//const unsigned long long *input = n_vals.value();
//vtkm::cont::ArrayHandle<unsigned long long> input_arr = vtkm::cont::make_ArrayHandle(input, num_vals);

vtkm::cont::Invoker invoker;
//vtkm::worklet::DispatcherMapField<vtkh::VTKmTypeCast>().Invoke(input_arr,vtkm_arr);
//vtkh::VTKmTypeCast<double,vtkm::Float64> worklet;
vtkh::VTKmTypeCast worklet;
std::cerr << "AF 7" << std::endl;
std::cerr<< " before calling cast" <<std::endl;
invoker(worklet,input_arr,vtkm_arr);
// VTKHDeviceAdapter::castUint64ToFloat64(input, output2, num_vals);
std::cerr<< " after calling cast" <<std::endl;

std::cerr << "AF 13" << std::endl;
// n_vals.to_float64_array(n_tmp);
invoker(worklet,input_arr,vtkm_arr);

std::cerr << "AF 14" << std::endl;
// add field to dataset
if(assoc_str == "vertex")
{
Expand All @@ -1708,12 +1715,42 @@ std::cerr << "AF 14" << std::endl;
vtkm_arr));
}
}
}
else
{
std::cerr << "HERE IN UNSUPPORTED CATGCH ALL" << std::endl;
// st d::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);
n_vals.to_float64_array(n_tmp);

// add field to dataset
if(assoc_str == "vertex")
{
dset->AddField(vtkm::cont::Field(field_name.c_str(),
vtkm::cont::Field::Association::Points,
vtkm_arr));
}
else if( assoc_str == "element")
{
dset->AddField(vtkm::cont::Field(field_name.c_str(),
vtkm::cont::Field::Association::Cells,
vtkm_arr));
}
}
// else
// {
// std::cout << "SUPPORTED DATA TYPE: "
// << n_vals.dtype().name() << std::endl;
// }
}
}
catch (vtkm::cont::Error error)
{
Expand Down

0 comments on commit 6903048

Please sign in to comment.