mirror of
https://github.com/reactos/CMake.git
synced 2024-12-03 17:11:04 +00:00
Merge topic 'msvc_cuda_files_use_consistent_obj_names'
fa583869
CUDA: Use MSVC default pattern for naming object files
Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !1722
This commit is contained in:
commit
4499cc8bb6
@ -2078,9 +2078,15 @@ bool cmVisualStudio10TargetGenerator::OutputSourceSpecificFlags(
|
||||
(*this->BuildFileStream) << firstString;
|
||||
firstString = "";
|
||||
hasFlags = true;
|
||||
this->WriteString("<ObjectFileName>", 3);
|
||||
(*this->BuildFileStream) << "$(IntDir)/" << objectName
|
||||
<< "</ObjectFileName>\n";
|
||||
if (lang == "CUDA") {
|
||||
this->WriteString("<CompileOut>", 3);
|
||||
(*this->BuildFileStream) << "$(IntDir)/" << objectName
|
||||
<< "</CompileOut>\n";
|
||||
} else {
|
||||
this->WriteString("<ObjectFileName>", 3);
|
||||
(*this->BuildFileStream) << "$(IntDir)/" << objectName
|
||||
<< "</ObjectFileName>\n";
|
||||
}
|
||||
}
|
||||
for (std::string const& config : this->Configurations) {
|
||||
std::string configUpper = cmSystemTools::UpperCase(config);
|
||||
@ -2688,6 +2694,11 @@ bool cmVisualStudio10TargetGenerator::ComputeCudaOptions(
|
||||
cudaOptions.AddFlag("GPUDebugInfo", "false");
|
||||
}
|
||||
|
||||
// The extension on object libraries the CUDA gives isn't
|
||||
// consistent with how MSVC generates object libraries for C+, so set
|
||||
// the default to not have any extension
|
||||
cudaOptions.AddFlag("CompileOut", "$(IntDir)%(Filename).obj");
|
||||
|
||||
bool notPtx = true;
|
||||
if (this->GeneratorTarget->GetPropertyAsBool("CUDA_SEPARABLE_COMPILATION")) {
|
||||
cudaOptions.AddFlag("GenerateRelocatableDeviceCode", "true");
|
||||
|
@ -1,15 +1,18 @@
|
||||
cmake_minimum_required(VERSION 3.7)
|
||||
project (CudaObjectLibrary CUDA CXX)
|
||||
#Goal for this example:
|
||||
|
||||
#build a object files some with cuda and some without than
|
||||
#embed these into an executable
|
||||
#
|
||||
#Build C++ and CUDA object files and than use them to make an executable
|
||||
#Make sure that CMake logic to handle object output when multiple files
|
||||
#with the same name works
|
||||
add_subdirectory(Conflicts)
|
||||
|
||||
add_library(CudaMixedObjectLib OBJECT static.cu static.cpp)
|
||||
|
||||
add_executable(CudaObjectLibrary
|
||||
main.cpp
|
||||
$<TARGET_OBJECTS:CudaMixedObjectLib>)
|
||||
$<TARGET_OBJECTS:CudaMixedObjectLib>
|
||||
$<TARGET_OBJECTS:CudaConflicts>)
|
||||
|
||||
if(APPLE)
|
||||
# Help the static cuda runtime find the driver (libcuda.dyllib) at runtime.
|
||||
|
2
Tests/Cuda/ObjectLibrary/Conflicts/CMakeLists.txt
Normal file
2
Tests/Cuda/ObjectLibrary/Conflicts/CMakeLists.txt
Normal file
@ -0,0 +1,2 @@
|
||||
|
||||
add_library(CudaConflicts OBJECT static.cu)
|
17
Tests/Cuda/ObjectLibrary/Conflicts/static.cu
Normal file
17
Tests/Cuda/ObjectLibrary/Conflicts/static.cu
Normal file
@ -0,0 +1,17 @@
|
||||
|
||||
#include <cuda.h>
|
||||
#include <cuda_runtime.h>
|
||||
#include <iostream>
|
||||
|
||||
int __host__ cu2_sq_func(int x)
|
||||
{
|
||||
cudaError_t err;
|
||||
int nDevices = 0;
|
||||
err = cudaGetDeviceCount(&nDevices);
|
||||
if (err != cudaSuccess) {
|
||||
std::cerr << "nDevices: " << nDevices << std::endl;
|
||||
std::cerr << "err: " << err << std::endl;
|
||||
return 1;
|
||||
}
|
||||
return x * x;
|
||||
}
|
@ -1,22 +1,18 @@
|
||||
|
||||
#include <iostream>
|
||||
|
||||
int static_func(int);
|
||||
int file1_sq_func(int);
|
||||
int cpp_sq_func(int);
|
||||
int cu1_sq_func(int);
|
||||
int cu2_sq_func(int);
|
||||
|
||||
int test_functions()
|
||||
bool test_functions()
|
||||
{
|
||||
return file1_sq_func(static_func(42));
|
||||
return (cu1_sq_func(42) == cpp_sq_func(42)) &&
|
||||
(cu2_sq_func(42) == cpp_sq_func(42));
|
||||
}
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
if (test_functions() == 1) {
|
||||
return 1;
|
||||
}
|
||||
std::cout
|
||||
<< "this executable doesn't use cuda code, just call methods defined"
|
||||
<< std::endl;
|
||||
std::cout << "in object files that have cuda code" << std::endl;
|
||||
return 0;
|
||||
int result = test_functions() ? 0 : 1;
|
||||
return result;
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
int file1_sq_func(int);
|
||||
|
||||
int static_func(int x)
|
||||
int cpp_sq_func(int x)
|
||||
{
|
||||
return file1_sq_func(x);
|
||||
return x * x;
|
||||
}
|
||||
|
@ -3,7 +3,7 @@
|
||||
#include <cuda_runtime.h>
|
||||
#include <iostream>
|
||||
|
||||
int __host__ file1_sq_func(int x)
|
||||
int __host__ cu1_sq_func(int x)
|
||||
{
|
||||
cudaError_t err;
|
||||
int nDevices = 0;
|
||||
@ -13,9 +13,5 @@ int __host__ file1_sq_func(int x)
|
||||
std::cerr << "err: " << err << std::endl;
|
||||
return 1;
|
||||
}
|
||||
std::cout << "this library uses cuda code" << std::endl;
|
||||
std::cout << "you have " << nDevices << " devices that support cuda"
|
||||
<< std::endl;
|
||||
|
||||
return x * x;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user