Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:15:43

0001 #include "catch.hpp"
0002 
0003 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0004 #include "FWCore/ParameterSetReader/interface/ParameterSetReader.h"
0005 
0006 #include <fmt/format.h>
0007 
0008 #include <iostream>
0009 #include <string_view>
0010 
0011 static constexpr auto s_tag = "[ProcessAcceleratorCUDA]";
0012 
0013 namespace {
0014   std::string makeConfig(std::string_view cpu, std::string_view cuda, std::string_view accelerator) {
0015     return fmt::format(
0016         R"_(import FWCore.ParameterSet.Config as cms
0017 
0018 process = cms.Process("TEST")
0019 process.options.accelerators = [{}]
0020 
0021 process.load("HeterogeneousCore.CUDACore.ProcessAcceleratorCUDA_cfi")
0022 from HeterogeneousCore.CUDACore.SwitchProducerCUDA import *
0023 
0024 process.s = SwitchProducerCUDA(
0025    cpu = {},
0026    cuda = {}
0027 )
0028 process.p = cms.Path(process.s)
0029 )_",
0030         accelerator,
0031         cpu,
0032         cuda);
0033   }
0034 }  // namespace
0035 
0036 TEST_CASE("Configuration", s_tag) {
0037   const std::string test1{"cms.EDProducer('IntProducer', ivalue = cms.int32(1))"};
0038   const std::string test2{"cms.EDProducer('ManyIntProducer', ivalue = cms.int32(2), values = cms.VPSet())"};
0039 
0040   const std::string baseConfig_auto = makeConfig(test1, test2, "'*'");
0041   const std::string baseConfig_cpu = makeConfig(test1, test2, "'cpu'");
0042   const std::string baseConfig_cuda = makeConfig(test1, test2, "'gpu-nvidia'");
0043 
0044   SECTION("Configuration hash is not changed") {
0045     std::unique_ptr<edm::ParameterSet> pset_auto, pset_cpu, pset_cuda;
0046     edm::makeParameterSets(baseConfig_auto, pset_auto);
0047     edm::makeParameterSets(baseConfig_cpu, pset_cpu);
0048     edm::makeParameterSets(baseConfig_cuda, pset_cuda);
0049     pset_auto->registerIt();
0050     pset_cpu->registerIt();
0051     pset_cuda->registerIt();
0052     REQUIRE(pset_auto->id() == pset_cpu->id());
0053     REQUIRE(pset_auto->id() == pset_cuda->id());
0054   }
0055 }