From 87df03f75b325c1aa730bffb6af2e67cd7c9381e Mon Sep 17 00:00:00 2001 From: alinpahontu2912 Date: Wed, 18 Mar 2026 11:19:27 +0100 Subject: [PATCH 1/5] Update CI pipeline from Ubuntu 20.04 (EOL) to Ubuntu 26.04 Replace Ubuntu 20.04 container image and apt sources with Ubuntu 26.04: - Container image: prereqs:ubuntu-20.04-* -> prereqs:ubuntu-26.04 - MS packages apt source: ubuntu/20.04 -> ubuntu/26.04 - Kitware apt source: focal -> resolute Fixes #1551 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- azure-pipelines.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 3a6a17a96..369f59199 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -29,11 +29,11 @@ variables: sudo apt-get -y update sudo apt-get -y install clang git libunwind8 curl libomp-dev libomp5 wget gpg wget -O - https://apt.kitware.com/keys/kitware-archive-latest.asc 2>/dev/null | gpg --dearmor - | sudo tee /usr/share/keyrings/kitware-archive-keyring.gpg >/dev/null - echo 'deb [signed-by=/usr/share/keyrings/kitware-archive-keyring.gpg] https://apt.kitware.com/ubuntu/ focal main' | sudo tee /etc/apt/sources.list.d/kitware.list + echo 'deb [signed-by=/usr/share/keyrings/kitware-archive-keyring.gpg] https://apt.kitware.com/ubuntu/ resolute main' | sudo tee /etc/apt/sources.list.d/kitware.list sudo apt-get -y update sudo apt-get -y install cmake cmake --version - wget https://packages.microsoft.com/config/ubuntu/20.04/packages-microsoft-prod.deb -O packages-microsoft-prod.deb + wget https://packages.microsoft.com/config/ubuntu/26.04/packages-microsoft-prod.deb -O packages-microsoft-prod.deb sudo dpkg --purge packages-microsoft-prod && sudo dpkg -i packages-microsoft-prod.deb sudo apt-get update; sudo apt-get install -y apt-transport-https && sudo apt-get update ldd --version && (/sbin/ldconfig -p | grep stdc++) && (strings /usr/lib/x86_64-linux-gnu/libstdc++.so.6 | grep LIBCXX) @@ -46,7 +46,7 @@ resources: # https://github.com/dotnet/versions/blob/main/build-info/docker/image-info.dotnet-dotnet-buildtools-prereqs-docker-main.json - container: UbuntuContainer - image: mcr.microsoft.com/dotnet-buildtools/prereqs:ubuntu-20.04-20240708213715-dcf0bb9 + image: mcr.microsoft.com/dotnet-buildtools/prereqs:ubuntu-26.04 jobs: - template: /build/ci/job-template.yml From 7c30db94dcf6ae8668862789465ebcb6133c28ec Mon Sep 17 00:00:00 2001 From: alinpahontu2912 Date: Wed, 18 Mar 2026 14:10:39 +0100 Subject: [PATCH 2/5] Fix CI: use Ubuntu 24.04 (Noble) instead of non-existent 26.04 - Docker image tag ubuntu-26.04 does not exist in MCR, use ubuntu-24.04 - Kitware apt codename resolute is invalid, use noble (24.04 LTS) - Microsoft packages URL ubuntu/26.04 does not exist, use 24.04 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- azure-pipelines.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 369f59199..9577abcf5 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -29,11 +29,11 @@ variables: sudo apt-get -y update sudo apt-get -y install clang git libunwind8 curl libomp-dev libomp5 wget gpg wget -O - https://apt.kitware.com/keys/kitware-archive-latest.asc 2>/dev/null | gpg --dearmor - | sudo tee /usr/share/keyrings/kitware-archive-keyring.gpg >/dev/null - echo 'deb [signed-by=/usr/share/keyrings/kitware-archive-keyring.gpg] https://apt.kitware.com/ubuntu/ resolute main' | sudo tee /etc/apt/sources.list.d/kitware.list + echo 'deb [signed-by=/usr/share/keyrings/kitware-archive-keyring.gpg] https://apt.kitware.com/ubuntu/ noble main' | sudo tee /etc/apt/sources.list.d/kitware.list sudo apt-get -y update sudo apt-get -y install cmake cmake --version - wget https://packages.microsoft.com/config/ubuntu/26.04/packages-microsoft-prod.deb -O packages-microsoft-prod.deb + wget https://packages.microsoft.com/config/ubuntu/24.04/packages-microsoft-prod.deb -O packages-microsoft-prod.deb sudo dpkg --purge packages-microsoft-prod && sudo dpkg -i packages-microsoft-prod.deb sudo apt-get update; sudo apt-get install -y apt-transport-https && sudo apt-get update ldd --version && (/sbin/ldconfig -p | grep stdc++) && (strings /usr/lib/x86_64-linux-gnu/libstdc++.so.6 | grep LIBCXX) @@ -46,7 +46,7 @@ resources: # https://github.com/dotnet/versions/blob/main/build-info/docker/image-info.dotnet-dotnet-buildtools-prereqs-docker-main.json - container: UbuntuContainer - image: mcr.microsoft.com/dotnet-buildtools/prereqs:ubuntu-26.04 + image: mcr.microsoft.com/dotnet-buildtools/prereqs:ubuntu-24.04 jobs: - template: /build/ci/job-template.yml From 42af79eca4fccc700bdac45cdc19816c62751aa2 Mon Sep 17 00:00:00 2001 From: alinpahontu2912 Date: Fri, 20 Mar 2026 11:11:10 +0100 Subject: [PATCH 3/5] Update Ubuntu references from 20.04 to 26.04 in CI pipeline Ubuntu 20.04 reached end-of-life in April 2025. Update: - Container image to prereqs:ubuntu-26.04 - MS packages apt source to ubuntu/26.04 - Kitware apt source codename to resolute (26.04) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- azure-pipelines.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 9577abcf5..369f59199 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -29,11 +29,11 @@ variables: sudo apt-get -y update sudo apt-get -y install clang git libunwind8 curl libomp-dev libomp5 wget gpg wget -O - https://apt.kitware.com/keys/kitware-archive-latest.asc 2>/dev/null | gpg --dearmor - | sudo tee /usr/share/keyrings/kitware-archive-keyring.gpg >/dev/null - echo 'deb [signed-by=/usr/share/keyrings/kitware-archive-keyring.gpg] https://apt.kitware.com/ubuntu/ noble main' | sudo tee /etc/apt/sources.list.d/kitware.list + echo 'deb [signed-by=/usr/share/keyrings/kitware-archive-keyring.gpg] https://apt.kitware.com/ubuntu/ resolute main' | sudo tee /etc/apt/sources.list.d/kitware.list sudo apt-get -y update sudo apt-get -y install cmake cmake --version - wget https://packages.microsoft.com/config/ubuntu/24.04/packages-microsoft-prod.deb -O packages-microsoft-prod.deb + wget https://packages.microsoft.com/config/ubuntu/26.04/packages-microsoft-prod.deb -O packages-microsoft-prod.deb sudo dpkg --purge packages-microsoft-prod && sudo dpkg -i packages-microsoft-prod.deb sudo apt-get update; sudo apt-get install -y apt-transport-https && sudo apt-get update ldd --version && (/sbin/ldconfig -p | grep stdc++) && (strings /usr/lib/x86_64-linux-gnu/libstdc++.so.6 | grep LIBCXX) @@ -46,7 +46,7 @@ resources: # https://github.com/dotnet/versions/blob/main/build-info/docker/image-info.dotnet-dotnet-buildtools-prereqs-docker-main.json - container: UbuntuContainer - image: mcr.microsoft.com/dotnet-buildtools/prereqs:ubuntu-24.04 + image: mcr.microsoft.com/dotnet-buildtools/prereqs:ubuntu-26.04 jobs: - template: /build/ci/job-template.yml From bcb3fbf67d9638f863915cb98006b831a64f45e6 Mon Sep 17 00:00:00 2001 From: alinpahontu2912 Date: Fri, 20 Mar 2026 11:53:28 +0100 Subject: [PATCH 4/5] Fix CI: use ubuntu-26.04-amd64 Docker image tag The unqualified 'ubuntu-26.04' tag does not exist in MCR. Unlike older Ubuntu versions, 26.04 only has architecture-qualified tags. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- azure-pipelines.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 369f59199..9df773f77 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -46,7 +46,7 @@ resources: # https://github.com/dotnet/versions/blob/main/build-info/docker/image-info.dotnet-dotnet-buildtools-prereqs-docker-main.json - container: UbuntuContainer - image: mcr.microsoft.com/dotnet-buildtools/prereqs:ubuntu-26.04 + image: mcr.microsoft.com/dotnet-buildtools/prereqs:ubuntu-26.04-amd64 jobs: - template: /build/ci/job-template.yml From 61e482320e11bafe6ab28ac33ef2f8cf35c69b89 Mon Sep 17 00:00:00 2001 From: alinpahontu2912 Date: Thu, 2 Apr 2026 16:17:51 +0200 Subject: [PATCH 5/5] Fix Clang build error: replace memcpy/memset on non-trivially copyable TensorIndex Replace unsafe memcpy/memset operations on at::indexing::TensorIndex with std::vector and emplace_back to fix -Wnontrivial-memcall errors on Ubuntu (Clang). The refactored completeTensorIndices now returns a vector built via emplace_back, eliminating all 12 error sites while preserving identical behavior across all platforms. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- src/Native/LibTorchSharp/THSTensor.cpp | 63 ++++++++------------------ 1 file changed, 20 insertions(+), 43 deletions(-) diff --git a/src/Native/LibTorchSharp/THSTensor.cpp b/src/Native/LibTorchSharp/THSTensor.cpp index 7b4a0e55e..a001045fc 100644 --- a/src/Native/LibTorchSharp/THSTensor.cpp +++ b/src/Native/LibTorchSharp/THSTensor.cpp @@ -753,13 +753,14 @@ Tensor THSTensor_isreal(const Tensor tensor) CATCH_TENSOR(torch::isreal(*tensor)); } -void completeTensorIndices(const int64_t* indexStarts, +std::vector completeTensorIndices(const int64_t* indexStarts, const int64_t* indexEnds, const int64_t* indexSteps, const Tensor* indexTensors, - at::indexing::TensorIndex* indicesArray, const int indicesLength) { + std::vector indices; + indices.reserve(indicesLength); // The indexStart encodes the kind of slice being performed for each dimension // range INT64_MIN..INT64_MIN+5 is for various singleton cases // range INT64_MIN+6 is for slice with absent start @@ -770,56 +771,41 @@ void completeTensorIndices(const int64_t* indexStarts, auto n = indexStarts[i]; if (n == INT64_MIN) // TensorIndex 'Null' { - at::indexing::TensorIndex idx(c10::nullopt); - // The '=' copy constructor for TensorIndex doesn't work - memcpy(&indicesArray[i], &idx, sizeof(at::indexing::TensorIndex)); + indices.emplace_back(c10::nullopt); } else if (n == INT64_MIN + 1) // TensorIndex 'False' { - at::indexing::TensorIndex idx(false); - // The '=' copy constructor for TensorIndex doesn't work - memcpy(&indicesArray[i], &idx, sizeof(at::indexing::TensorIndex)); + indices.emplace_back(false); } else if (n == INT64_MIN + 2) // TensorIndex 'True' { - at::indexing::TensorIndex idx(true); - // The '=' copy constructor for TensorIndex doesn't work - memcpy(&indicesArray[i], &idx, sizeof(at::indexing::TensorIndex)); + indices.emplace_back(true); } else if (n == INT64_MIN + 3) // TensorIndex '...' { - at::indexing::TensorIndex idx(at::indexing::Ellipsis); - // The '=' copy constructor for TensorIndex doesn't work - memcpy(&indicesArray[i], &idx, sizeof(at::indexing::TensorIndex)); + indices.emplace_back(at::indexing::Ellipsis); } else if (n == INT64_MIN + 4) // TensorIndex 'None' { - at::indexing::TensorIndex idx(at::indexing::None); - // The '=' copy constructor for TensorIndex doesn't work - memcpy(&indicesArray[i], &idx, sizeof(at::indexing::TensorIndex)); + indices.emplace_back(at::indexing::None); } else if (n == INT64_MIN + 5) // TensorIndex by tensor { - at::indexing::TensorIndex idx(*indexTensors[i]); - // The '=' copy constructor for TensorIndex doesn't work - memcpy(&indicesArray[i], &idx, sizeof(at::indexing::TensorIndex)); + indices.emplace_back(*indexTensors[i]); } else if (n > INT64_MIN / 4) // TensorIndex by integer { - at::indexing::TensorIndex idx(n); - // The '=' copy constructor for TensorIndex doesn't work - memcpy(&indicesArray[i], &idx, sizeof(at::indexing::TensorIndex)); + indices.emplace_back(n); } else // TensorIndex by Slice { - // slice auto start = (n == INT64_MIN + 6) ? c10::optional() : c10::optional(n - INT64_MIN / 2); auto end = (indexEnds == nullptr || indexEnds[i] == INT64_MIN) ? c10::optional() : c10::optional(indexEnds[i]); auto step = (indexSteps == nullptr || indexSteps[i] == INT64_MIN) ? c10::optional() : c10::optional(indexSteps[i]); - at::indexing::TensorIndex idx(at::indexing::Slice(start, end, step)); - memcpy(&indicesArray[i], &idx, sizeof(at::indexing::TensorIndex)); + indices.emplace_back(at::indexing::Slice(start, end, step)); } } + return indices; } Tensor THSTensor_index(Tensor tensor, @@ -829,11 +815,8 @@ Tensor THSTensor_index(Tensor tensor, const Tensor* indexTensors, const int indicesLength) { - at::indexing::TensorIndex* indicesArray = (at::indexing::TensorIndex*)alloca(indicesLength * sizeof(at::indexing::TensorIndex)); - memset(indicesArray, 0, indicesLength * sizeof(at::indexing::TensorIndex)); - // The indexStart encodes the kind of slice being performed for each dimension - completeTensorIndices(indexStarts, indexEnds, indexSteps, indexTensors, indicesArray, indicesLength); - auto indices = at::ArrayRef(indicesArray, indicesLength); + auto indicesVec = completeTensorIndices(indexStarts, indexEnds, indexSteps, indexTensors, indicesLength); + auto indices = at::ArrayRef(indicesVec.data(), indicesVec.size()); CATCH_TENSOR(tensor->index(indices)); } @@ -845,10 +828,8 @@ void THSTensor_index_put_(Tensor tensor, const int indicesLength, const Tensor value) { - at::indexing::TensorIndex* indicesArray = (at::indexing::TensorIndex*)alloca(indicesLength * sizeof(at::indexing::TensorIndex)); - memset(indicesArray, 0, indicesLength * sizeof(at::indexing::TensorIndex)); - completeTensorIndices(indexStarts, indexEnds, indexSteps, indexTensors, indicesArray, indicesLength); - auto indices = at::ArrayRef(indicesArray, indicesLength); + auto indicesVec = completeTensorIndices(indexStarts, indexEnds, indexSteps, indexTensors, indicesLength); + auto indices = at::ArrayRef(indicesVec.data(), indicesVec.size()); CATCH(tensor->index_put_(indices, *value);); } @@ -861,10 +842,8 @@ void THSTensor_index_put_(Tensor tensor, const Tensor value, const bool accumulate) { - at::indexing::TensorIndex* indicesArray = (at::indexing::TensorIndex*)alloca(indicesLength * sizeof(at::indexing::TensorIndex)); - memset(indicesArray, 0, indicesLength * sizeof(at::indexing::TensorIndex)); - completeTensorIndices(indexStarts, indexEnds, indexSteps, indexTensors, indicesArray, indicesLength); - auto indices = at::ArrayRef(indicesArray, indicesLength); + auto indicesVec = completeTensorIndices(indexStarts, indexEnds, indexSteps, indexTensors, indicesLength); + auto indices = at::ArrayRef(indicesVec.data(), indicesVec.size()); if (accumulate) { c10::List> indicesList = c10::List>(); for (int i = 0; i < indicesLength; i++) { @@ -885,10 +864,8 @@ void THSTensor_index_put_scalar_(Tensor tensor, const int indicesLength, const Scalar value) { - at::indexing::TensorIndex* indicesArray = (at::indexing::TensorIndex*)alloca(indicesLength * sizeof(at::indexing::TensorIndex)); - memset(indicesArray, 0, indicesLength * sizeof(at::indexing::TensorIndex)); - completeTensorIndices(indexStarts, indexEnds, indexSteps, indexTensors, indicesArray, indicesLength); - auto indices = at::ArrayRef(indicesArray, indicesLength); + auto indicesVec = completeTensorIndices(indexStarts, indexEnds, indexSteps, indexTensors, indicesLength); + auto indices = at::ArrayRef(indicesVec.data(), indicesVec.size()); CATCH(tensor->index_put_(indices, *value);); }