Thanks for using Compiler Explorer
Sponsors
Jakt
C++
Ada
Analysis
Android Java
Android Kotlin
Assembly
C
C3
Carbon
C++ (Circle)
CIRCT
Clean
CMake
CMakeScript
COBOL
C++ for OpenCL
MLIR
Cppx
Cppx-Blue
Cppx-Gold
Cpp2-cppfront
Crystal
C#
CUDA C++
D
Dart
Elixir
Erlang
Fortran
F#
Go
Haskell
HLSL
Hook
Hylo
ispc
Java
Julia
Kotlin
LLVM IR
LLVM MIR
Modula-2
Nim
Objective-C
Objective-C++
OCaml
OpenCL C
Pascal
Pony
Python
Racket
Ruby
Rust
Snowball
Scala
Solidity
Spice
Swift
LLVM TableGen
Toit
TypeScript Native
V
Vala
Visual Basic
Zig
Javascript
GIMPLE
cuda source #1
Output
Compile to binary object
Link to binary
Execute the code
Intel asm syntax
Demangle identifiers
Verbose demangling
Filters
Unused labels
Library functions
Directives
Comments
Horizontal whitespace
Debug intrinsics
Compiler
10.0.0 sm_75 CUDA-10.2
10.0.1 sm_75 CUDA-10.2
11.0.0 sm_75 CUDA-10.2
NVCC 10.0.130
NVCC 10.1.105
NVCC 10.1.168
NVCC 10.1.243
NVCC 10.2.89
NVCC 11.0.2
NVCC 11.0.3
NVCC 11.1.0
NVCC 11.1.1
NVCC 11.2.0
NVCC 11.2.1
NVCC 11.2.2
NVCC 11.3.0
NVCC 11.3.1
NVCC 11.4.0
NVCC 11.4.1
NVCC 11.4.2
NVCC 11.4.3
NVCC 11.4.4
NVCC 11.5.0
NVCC 11.5.1
NVCC 11.5.2
NVCC 11.6.0
NVCC 11.6.1
NVCC 11.6.2
NVCC 11.7.0
NVCC 11.7.1
NVCC 11.8.0
NVCC 12.0.0
NVCC 12.0.1
NVCC 12.1.0
NVCC 12.2.1
NVCC 12.3.1
NVCC 9.1.85
NVCC 9.2.88
NVRTC 11.0.2
NVRTC 11.0.3
NVRTC 11.1.0
NVRTC 11.1.1
NVRTC 11.2.0
NVRTC 11.2.1
NVRTC 11.2.2
NVRTC 11.3.0
NVRTC 11.3.1
NVRTC 11.4.0
NVRTC 11.4.1
NVRTC 11.5.0
NVRTC 11.5.1
NVRTC 11.5.2
NVRTC 11.6.0
NVRTC 11.6.1
NVRTC 11.6.2
NVRTC 11.7.0
NVRTC 11.7.1
NVRTC 11.8.0
NVRTC 12.0.0
NVRTC 12.0.1
NVRTC 12.1.0
clang 7.0.0 sm_70 CUDA-9.1
clang 8.0.0 sm_75 CUDA-10.0
clang 9.0.0 sm_75 CUDA-10.1
clang rocm-4.5.2
clang rocm-5.0.2
clang rocm-5.1.3
clang rocm-5.2.3
clang rocm-5.3.2
clang rocm-5.7.0
trunk sm_86 CUDA-11.3
Options
Source code
#include "cuda_runtime.h" #include "device_launch_parameters.h" #include <iostream> void checkCudaError(cudaError_t result) { if (result != cudaSuccess) { std::cout << "ERROR: " << result << std::endl; } } std::ostream& operator << (std::ostream & out, const float3 & v) { out << "(" << v.x << "," << v.y << "," << v.z << ")"; return out; } struct StructCombined { float3 m_a; float3 m_b; }; struct StructSplit { float3 m_singleValue; }; __global__ void splitStructKernel(StructSplit* splitOut, const StructCombined* combinedIn) { int index = threadIdx.x; float3 result; StructCombined combinedStruct = combinedIn[0]; //based on this logic the first thread should get (1.,1.,1.) //and the second should get (2.,2.,2.) but they both seem to get (2.,2.,2.) in release mode! //if(index < 32){ if (index == 0) { float3 result1 = combinedStruct.m_a; result = result1; } else { float3 result2 = combinedStruct.m_b; result = result2; } splitOut[index].m_singleValue = result; //} } int main() { checkCudaError(cudaSetDevice(0)); StructCombined hostCombinedStruct; hostCombinedStruct.m_a = { 1.,1.,1. }; hostCombinedStruct.m_b = { 2.,2.,2. }; StructCombined* deviceCombinedStruct; checkCudaError(cudaMalloc(&deviceCombinedStruct, sizeof(StructCombined))); checkCudaError(cudaMemcpy(deviceCombinedStruct, &hostCombinedStruct, sizeof(StructCombined), cudaMemcpyHostToDevice)); StructSplit hostSplitStruct[2]; StructSplit* deviceSplitStruct; checkCudaError(cudaMalloc(&deviceSplitStruct, 2 * sizeof(StructSplit))); splitStructKernel << <1, 2>>> (deviceSplitStruct, deviceCombinedStruct); checkCudaError(cudaDeviceSynchronize()); checkCudaError(cudaMemcpy(hostSplitStruct, deviceSplitStruct, 2 * sizeof(StructSplit), cudaMemcpyDeviceToHost)); std::cout << hostSplitStruct[0].m_singleValue << std::endl; std::cout << hostSplitStruct[1].m_singleValue << std::endl; checkCudaError(cudaFree(deviceCombinedStruct)); checkCudaError(cudaFree(deviceSplitStruct)); return 0; }
Become a Patron
Sponsor on GitHub
Donate via PayPal
Source on GitHub
Mailing list
Installed libraries
Wiki
Report an issue
How it works
Contact the author
CE on Mastodon
About the author
Statistics
Changelog
Version tree