Skip to content

Conversation

@multitalentloes
Copy link
Member

No description provided.

@multitalentloes multitalentloes added the manual:irrelevant This PR is a minor fix and should not appear in the manual label Sep 30, 2025
Copy link
Member

@atgeirr atgeirr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should merge, but needs some fixes

{
std::vector<TemplatedStruct<ResidualNBInfoType, MiniMatrixType>> minimatrices(cpu_matrix.dataSize());
for (auto e : cpu_matrix.dataStorage()) {
minimatrices.push_back(e); // will this be converted correctly???
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You will end up with minimatrices having twice the size it should, either give it size on construction or use push_back, not both.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a completely criminal error on my side...

);
}

// Since we cannot have MatrixBlock in GPU code, we need to convert to MiniMatrix
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The whole existence of this specialization is a bit of a hack... I suggest that we place it with the definition of the struct (where it can be concrete and need not be templatized) instead, it does not have to be placed here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not really sure how to avoid this. I suppose we want to end up with this being a very straight-forward initialization where we can just use SparseTable(GPUBuf1, GPUBuf2) and have the conversion of the stuff in the struct be handled automatically. I have made a couple of attempts at this but I have not gotten anything to work smoothly...

@multitalentloes multitalentloes force-pushed the start_porting_assembly_to_gpu branch from 8964fad to 6eb430b Compare October 6, 2025 12:30
@multitalentloes
Copy link
Member Author

Jenkins build this serial rocm hipify opm-simulators=4686 please

@multitalentloes
Copy link
Member Author

Jenkins build this opm-simulators=4686 serial rocm hipify please

@bska
Copy link
Member

bska commented Oct 14, 2025

jenkins build this opm-simulators=4686 serial rocm hipify please

@bska
Copy link
Member

bska commented Oct 14, 2025

opm-simulators=4686

I don't see how OPM/opm-simulators#4686 is related to this. Did you mean something else instead?

@multitalentloes
Copy link
Member Author

You are right, I was supposed to start jenkins with #6508 from OPM simulators

@multitalentloes
Copy link
Member Author

jenkins build this opm-simulators=6508 serial rocm hipify please

1 similar comment
@bska
Copy link
Member

bska commented Oct 14, 2025

jenkins build this opm-simulators=6508 serial rocm hipify please

Copy link
Contributor

@kjetilly kjetilly left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the copy and make view functions have the wrong signature, but I am not sure. These are not actually tested, so a bit difficult to tell.

Also some minor issues with using an rvalue ref instead of copying

#include <opm/simulators/linalg/gpuistl/GpuBuffer.hpp>
#include <opm/simulators/linalg/gpuistl/GpuView.hpp>
#endif
#endif
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not just gpuistl_if_available?

{
// removed for now because we cannot access the zero'th element if Storage is a GpuBuffer
// OPM_ERROR_IF(row_start_.size() == 0 || row_start_[0] != 0,
// "Invalid row_start array");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think storage can probably be passed as an rvalue reference:

Storage<T>&& data, Storage<int>&& row_starts 

it will save us an allocation and a copy on the gpu.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also, I would either remove the commented out code, or remove the comment and have the exception in an if constexpr (std::is_same_v<Storage<int>, std::vector<int>>)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good suggestion, done

// Since we cannot have MatrixBlock in GPU code, we need to convert to MiniMatrix
// For now I think this is an okay place to convert types
template<class MatrixBlockType, class MiniMatrixType, class ResidualNBInfoType, template <typename, typename...> class TemplatedStruct>
auto copy_to_gpu(const SparseTable<TemplatedStruct<ResidualNBInfoType, MatrixBlockType>>& cpu_matrix)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are you sure this is the correct template for sparsetable? TemplatedStruct looks like a Storage (should probably be renamed for clarity), but you are inserting it into the SparseTable with the templates, while SparseTable takes two template arguments, one of them the type T and then `Storage. I think a simpler signature would be something like

template<class MatrixBlockType, class MiniMatrixType>
auto copy_to_gpu(const SparseTable<MatrixBlockType, std::vector>& cpu_matrix)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, after having this explained I get it. I would however recommend these functions being moved to opm-simulators and having the struct names spelled out rather than having it as a template argument. First of all it will make the code a lot clearer, but secondly it will remove the potential of a wrong overload.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@multitalentloes
Copy link
Member Author

jenkins build this opm-simulators=6508 serial rocm hipify please

4 similar comments
@bska
Copy link
Member

bska commented Oct 15, 2025

jenkins build this opm-simulators=6508 serial rocm hipify please

@multitalentloes
Copy link
Member Author

jenkins build this opm-simulators=6508 serial rocm hipify please

@multitalentloes
Copy link
Member Author

jenkins build this opm-simulators=6508 serial rocm hipify please

@multitalentloes
Copy link
Member Author

jenkins build this opm-simulators=6508 serial rocm hipify please

Copy link
Member

@atgeirr atgeirr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good, only two remaining issues.

inline constexpr bool always_false_v = false;

// Poison iterator is a helper class that will allow for compilation but will fail at run-time
// Its intetion is to be used so that we can have a SparseTable of GPU data, which requires the
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the class uses static_assert, it seems to me it will fail at compilation, not only at run-time?

Typo: intetion->intention

}

SparseTable (Storage<T>&& data, Storage<int>&& row_starts)
: data_(data)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This must be

: data_(std::move(data))

to actually activate move semantics. Anything with a name must be moved from. Also row_starts.

@multitalentloes multitalentloes force-pushed the start_porting_assembly_to_gpu branch from 43ed086 to c4f5acd Compare October 24, 2025 09:27
@multitalentloes
Copy link
Member Author

jenkins build this opm-simulators=6508 serial rocm hipify please

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

manual:irrelevant This PR is a minor fix and should not appear in the manual

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants