Skip to content

Commit

Permalink
Win
Browse files Browse the repository at this point in the history
  • Loading branch information
drnikolaev committed Feb 20, 2023
1 parent a789f60 commit 66a0025
Show file tree
Hide file tree
Showing 17 changed files with 506 additions and 95 deletions.
20 changes: 15 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,20 @@
cmake_minimum_required(VERSION 3.23)
cmake_minimum_required(VERSION 3.23.0)
SET (CVM_VERSION 9.1.0)
project(cvm VERSION ${CVM_VERSION} DESCRIPTION "CVM Class Library")
project(cvm LANGUAGES Fortran CXX VERSION ${CVM_VERSION} DESCRIPTION "CVM Class Library")

option(BUILD_TESTS "Build regression test program" OFF)
option(IFORT "Use Intel Fortran compiler" OFF)
option(ICC "Use Intel C++ compiler" OFF)
#cmake -DCMAKE_Fortran_COMPILER=ifx -DCMAKE_CXX_COMPILER=icx -DCMAKE_C_COMPILER=icx -DMKL=ON -DILP64=ON -DBUILD_TESTS=ON

if (${CMAKE_CXX_COMPILER_ID} MATCHES "^Intel.*")
SET(ICC ON)
message(STATUS "Found Intel C++: ${CMAKE_CXX_COMPILER_ID} version ${CMAKE_CXX_COMPILER_VERSION}")
endif()

if (${CMAKE_Fortran_COMPILER_ID} MATCHES "^Intel.*")
SET(IFORT ON)
message(STATUS "Found Intel Fortran: ${CMAKE_Fortran_COMPILER_ID} version ${CMAKE_Fortran_COMPILER_VERSION}")
endif()

option(BUILD_TESTS "Build regression test program (takes a while)" OFF)
option(MKL "Use Intel MKL library" OFF)
option(ILP64 "Set default integer size to 8 byte" OFF)

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ sudo apt update
sudo apt install intel-basekit
source /opt/intel/oneapi/compiler/latest/env/vars.sh
mkdir build
cmake -DICC=ON -DIFORT=ON -DMKL=ON -DILP64=ON -DBUILD_TESTS=ON -DCMAKE_BUILD_TYPE=Release -S . -B build
cmake -DCMAKE_Fortran_COMPILER=ifx -DCMAKE_CXX_COMPILER=icx -DMKL=ON -DILP64=ON -DBUILD_TESTS=ON -DCMAKE_BUILD_TYPE=Release -S . -B build
cd build
make -j
../lib/cvm_test
Expand Down
37 changes: 23 additions & 14 deletions cvm/src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
set(CMAKE_CXX_STANDARD 17)
set(OUTPUT_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../../lib")

if(ICC)
SET(CMAKE_CXX_COMPILER icpx)
endif()

add_subdirectory(ftn)

add_library(cvm SHARED
Expand All @@ -17,7 +13,7 @@ add_library(cvm SHARED
scmatrix.cpp
srmatrix.cpp
utils.cpp
)
../../cvmlib/framework.h ../../cvmlib/dllmain.cpp ../../cvmlib/pch.cpp)

set_target_properties(
cvm
Expand All @@ -37,23 +33,34 @@ add_dependencies(cvm ftn)
if(ILP64)
target_compile_definitions(cvm PUBLIC CVM_ILP64)
endif()
if(ICC)
target_compile_options(cvm PUBLIC -fsycl -Rdebug-disables-optimization)
endif()
#if(ICC)
# target_compile_options(cvm PUBLIC -fsycl -Rdebug-disables-optimization)
#endif()

target_include_directories(cvm PRIVATE .)
target_compile_options(cvm PUBLIC -fPIC
if(LINUX)
target_compile_options(cvm PUBLIC -fPIC
$<$<CONFIG:Release>:-O3>
$<$<CONFIG:Debug>:-O0 -g>)
else()
target_compile_definitions(cvm PUBLIC SRC_EXPORTS)
target_compile_options(cvm PUBLIC
$<$<CONFIG:Release>:/O3>
$<$<CONFIG:Debug>:/Od /debug:all>)
endif()

target_link_directories(cvm PUBLIC ${OUTPUT_PATH})
target_link_libraries(cvm optimized ftn)
target_link_libraries(cvm debug ftn_debug)
target_link_libraries(cvm pthread m dl)
if(LINUX)
target_link_libraries(cvm pthread m dl)
endif()


if(MKL)
if(ILP64)
if(ICC)
target_compile_options(cvm PUBLIC -qmkl-ilp64=parallel)
target_compile_options(cvm PUBLIC /Qmkl-ilp64:parallel)
endif()
if(IFORT)
target_link_libraries(cvm mkl_intel_ilp64)
Expand All @@ -62,7 +69,7 @@ if(MKL)
endif()
else()
if(ICC)
target_compile_options(cvm PUBLIC -qmkl=parallel)
target_compile_options(cvm PUBLIC -Qmkl=parallel)
endif()
if(IFORT)
target_link_libraries(cvm mkl_intel_lp64)
Expand All @@ -84,6 +91,8 @@ else()
endif()
endif()

if(ICC)
target_link_libraries(cvm iomp5)
if(LINUX)
if(ICC)
target_link_libraries(cvm iomp5)
endif()
endif()
33 changes: 24 additions & 9 deletions cvm/src/ftn/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
if(IFORT)
SET(CMAKE_Fortran_COMPILER ifx)
endif()
project(ftn LANGUAGES Fortran)

FILE(GLOB SOURCE_FILES *.f)
Expand All @@ -14,14 +11,32 @@ set_target_properties(ftn
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/../../../lib"
)

target_compile_options(ftn PUBLIC -pthread -fPIC
if(LINUX)
target_compile_options(ftn PUBLIC -pthread -fPIC
$<$<CONFIG:Release>:-O3>
$<$<CONFIG:Debug>:-O0 -g>)
else()
target_compile_options(ftn PUBLIC
$<$<CONFIG:Release>:/O2>
$<$<CONFIG:Debug>:/Od /debug>)
endif()


if(ILP64)
if(IFORT)
target_compile_options(ftn PUBLIC $<$<COMPILE_LANGUAGE:Fortran>:-integer-size 64>)
else()
target_compile_options(ftn PUBLIC $<$<COMPILE_LANGUAGE:Fortran>:-fdefault-integer-8>)
if(LINUX)
if(ILP64)
if(IFORT)
target_compile_options(ftn PUBLIC $<$<COMPILE_LANGUAGE:Fortran>:-integer-size 64>)
else()
target_compile_options(ftn PUBLIC $<$<COMPILE_LANGUAGE:Fortran>:-fdefault-integer-8>)
endif()
endif()
else()
if(ILP64)
if(IFORT)
target_compile_options(ftn PUBLIC $<$<COMPILE_LANGUAGE:Fortran>:/integer-size:64>)
else()
target_compile_options(ftn PUBLIC $<$<COMPILE_LANGUAGE:Fortran>:/default-integer-8>)
endif()
endif()
endif()

31 changes: 9 additions & 22 deletions cvm/src/globals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
#include "cvm.h"

#include <algorithm>
#if defined(__INTEL_COMPILER) || defined(__INTEL_LLVM_COMPILER)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wexceptions"
#endif

extern "C" {
void __stdcall XERBLA(const char* szSubName,
Expand All @@ -21,29 +25,12 @@ extern "C" {
}
}

#if defined(_MSC_VER)
# ifdef _MANAGED
# pragma managed(push, off)
# endif

BOOL APIENTRY DllMain(HANDLE /*hModule*/,
DWORD ul_reason_for_call,
LPVOID /*lpReserved*/)
{
switch(ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH:
break;
}
return TRUE;
}
#if defined(__INTEL_COMPILER) || defined(__INTEL_LLVM_COMPILER)
#pragma GCC diagnostic pop
#endif

# ifdef _MANAGED
# pragma managed(pop)
# endif
#if !defined(_MSC_VER)
#pragma GCC diagnostic pop
#endif

CVM_NAMESPACE_BEG
Expand Down
26 changes: 15 additions & 11 deletions cvm/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@ FILE(GLOB SOURCE_FILES *.cpp)
set(SOURCE_FILES ${SOURCE_FILES} test.h)
set(OUTPUT_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../../lib")

if(ICC)
SET(CMAKE_CXX_COMPILER /opt/intel/oneapi/compiler/latest/linux/bin/icpx)
endif()

add_executable(cvm_test ${SOURCE_FILES})
add_dependencies(cvm_test cvm)

Expand All @@ -23,16 +19,24 @@ set_target_properties(
if(ILP64)
target_compile_definitions(cvm_test PUBLIC CVM_ILP64)
endif()
if(ICC)
target_compile_options(cvm_test PUBLIC -fsycl -Rdebug-disables-optimization)

if(LINUX)
target_compile_options(cvm_test PUBLIC
$<$<CONFIG:Release>:-O2>
$<$<CONFIG:Debug>:-O0 -g>)
else()
target_compile_options(cvm_test PUBLIC /MT
$<$<CONFIG:Release>:/O1>
$<$<CONFIG:Debug>:/Od /debug:all>)
endif()
target_compile_options(cvm_test PUBLIC
$<$<CONFIG:Release>:-O2>
$<$<CONFIG:Debug>:-O0 -g>)

include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../../gtest/googletest/include)
target_link_directories(cvm_test PUBLIC ${OUTPUT_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/../../gtest)
target_link_directories(cvm_test PUBLIC ${OUTPUT_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/../../gtest ${CMAKE_CURRENT_SOURCE_DIR}/../../gtest/lib/Release)

target_link_libraries(cvm_test optimized cvm)
target_link_libraries(cvm_test debug cvm_debug)
target_link_libraries(cvm_test gtest pthread)
if(LINUX)
target_link_libraries(cvm_test gtest pthread)
else()
target_link_libraries(cvm_test gtest)
endif()
4 changes: 0 additions & 4 deletions cvm/test/testBlas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,6 @@ TYPED_TEST(BlasTest, TestVectorNorminf) {

ssm1.set(1.);
m1.set(1.);

std::cerr << sizeof(tint) << std::endl;


m2 = ssm1 * m1;
EXPECT_EQ(TP(16.), m2.norminf()) << "srsmatrix * rmatrix";

Expand Down
61 changes: 33 additions & 28 deletions cvm/test/testInitialization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1294,17 +1294,16 @@ TYPED_TEST(InitializationTest, TestConstructorsAndBasicFeatures) {

cr1 = cv1(8);
cv1 *= cr2;
EXPECT_EQ(cr1 * cr2, cv1(8));
EXPECT_NEAR(std::abs(cr1 * cr2), std::abs(cv1(8)), s<TP>());
cr1 = cm1(1,1);
cm1 *= cr2;
EXPECT_EQ(cr1 * cr2, cm1(1,1));
EXPECT_NEAR(std::abs(cr1 * cr2), std::abs(cm1(1,1)), s<TP>());
cr1 = scm1(1,1);
scm1 *= cr2;
EXPECT_EQ(cr1 * cr2, scm1(1,1));
EXPECT_NEAR(std::abs(cr1 * cr2), std::abs(scm1(1,1)), s<TP>());
cr1 = scbm1(1,0);
scbm1 *= cr2;
// EXPECT_EQ(cr1 * cr2, scbm1(1,0));
EXPECT_NEAR(std::abs(cr1 * cr2), std::abs(scbm1(1,0)), s<TP>());
EXPECT_NEAR(std::abs(cr1 * cr2), std::abs(scbm1(1,0)), spp<TP>());
cr1 = cv1(8);
cv1 /= cr2;
EXPECT_NEAR(std::abs(cr1 / cr2), std::abs(cv1(8)), s<TP>());
Expand Down Expand Up @@ -1391,8 +1390,6 @@ TYPED_TEST(InitializationTest, TestConstructorsAndBasicFeatures) {
EXPECT_FALSE(sch1 == sch2) << "schmatrix ==";
EXPECT_TRUE(sch1 != sch2) << "schmatrix !=";



rv1 = rv;
EXPECT_EQ(rv(2), rv1[2]) << "rvector = rvector";
EXPECT_TRUE(rv1 == rv) << "rvector ==";
Expand Down Expand Up @@ -1674,18 +1671,18 @@ TYPED_TEST(InitializationTest, TestConstructorsAndBasicFeatures) {
srm4.resize(3);
srm4.mult(rm1, rm2);

EXPECT_EQ(rm1[2] * rm2(2),srm4(2,2)) << "mult";
EXPECT_NEAR(rm1[2] * rm2(2),srm4(2,2), sp<TP>()) << "mult";
rm4.resize(3, 2);
rm1.mult(srm4, rm4);
EXPECT_EQ(srm4[2] * rm4(1),rm1(2,1)) << "mult";
EXPECT_NEAR(srm4[2] * rm4(1),rm1(2,1), sp<TP>()) << "mult";
srbm1.resize(3);
rm1.mult(srbm1, rm4);
EXPECT_EQ(srbm1[2] * rm4(1),rm1(2,1)) << "mult";
EXPECT_NEAR(srbm1[2] * rm4(1),rm1(2,1), sp<TP>()) << "mult";
rm1.mult(~srbm1, rm4);
tmp = static_cast<float>(rm1(2,1));
EXPECT_FLOAT_EQ(static_cast<float>(srbm1(2) * rm4(1)),tmp) << "mult";
srbm1.mult(rm1, rm2);
EXPECT_EQ(rm1[1] * rm2(1),srbm1(1,1)) << "mult";
EXPECT_NEAR(rm1[1] * rm2(1),srbm1(1,1), sp<TP>()) << "mult";

r1 = -0.031;
r2 = 0.319;
Expand Down Expand Up @@ -1717,24 +1714,28 @@ TYPED_TEST(InitializationTest, TestConstructorsAndBasicFeatures) {
EXPECT_FLOAT_EQ(static_cast<float>((cm2[1] * cm1(1)).imag()),
static_cast<float>(cm3(1,1).imag())) << "mult";
cm4.mult(cm1, cm2);
EXPECT_EQ(cm1[2] * cm2(2),cm4(2,2)) << "mult";
EXPECT_FLOAT_EQ((cm1[2] * cm2(2)).real(),cm4(2,2).real()) << "mult";
EXPECT_FLOAT_EQ((cm1[2] * cm2(2)).imag(),cm4(2,2).imag()) << "mult";
scm4.resize(3);
scm4.mult(cm1, cm2);
EXPECT_EQ(cm1[2] * cm2(2),scm4(2,2)) << "mult";
EXPECT_FLOAT_EQ((cm1[2] * cm2(2)).real(),scm4(2,2).real()) << "mult";
EXPECT_FLOAT_EQ((cm1[2] * cm2(2)).imag(),scm4(2,2).imag()) << "mult";
cm4.resize(3, 2);
cm1.mult(scm4, cm4);
EXPECT_EQ(scm4[2] * cm4(1),cm1(2,1)) << "mult";
EXPECT_FLOAT_EQ((scm4[2] * cm4(1)).real(),cm1(2,1).real()) << "mult";
EXPECT_FLOAT_EQ((scm4[2] * cm4(1)).imag(),cm1(2,1).imag()) << "mult";
scbm.resize(3);
scbm.set(TPC(1.23,-0.912));
cm1.mult(scbm, cm4);
EXPECT_EQ(scbm[2] * cm4(1),cm1(2,1)) << "mult";
EXPECT_FLOAT_EQ((scbm[2] * cm4(1)).real(),cm1(2,1).real()) << "mult";
EXPECT_FLOAT_EQ((scbm[2] * cm4(1)).imag(),cm1(2,1).imag()) << "mult";
cm1.mult(~scbm, cm4);
EXPECT_FLOAT_EQ(static_cast<float>((~(scbm(2)) * cm4(1)).real()), static_cast<float>(cm1(2,1).real())) << "mult";
EXPECT_FLOAT_EQ(static_cast<float>((~(scbm(2)) * cm4(1)).imag()), static_cast<float>(cm1(2,1).imag())) << "mult";
scbm1.resize(3);
scbm1.mult(cm1, cm2);
EXPECT_EQ(cm1[1] * cm2(1),scbm1(1,1)) << "mult";

EXPECT_FLOAT_EQ((cm1[1] * cm2(1)).real(),scbm1(1,1).real()) << "mult";
EXPECT_FLOAT_EQ((cm1[1] * cm2(1)).imag(),scbm1(1,1).imag()) << "mult";

cm1.randomize_real(0., 1.);
cm2.randomize_real(0., 1.);
Expand Down Expand Up @@ -1918,26 +1919,30 @@ TYPED_TEST(InitializationTest, TestConstructorsAndBasicFeatures) {
scbm2.set(TPC(1.23,-0.977));

cm1 = scbm2;
EXPECT_NEAR(std::abs(scbm2(1,2)), std::abs(cm1(1,2)), s<TP>()) << "mix cmatrix scbm";
EXPECT_NEAR(std::abs(scbm2(3,0)), std::abs(cm1(3,0)), s<TP>()) << "mix cmatrix scbm";
EXPECT_NEAR(std::abs(scbm2(1,2)), std::abs(cm1(1,2)), s<TP>()) << "mix cmatrix scbm";
EXPECT_NEAR(std::abs(scbm2(3,0)), std::abs(cm1(3,0)), s<TP>()) << "mix cmatrix scbm";

cm1 = cm1 + scbm2;
cm1 += scbm2;
EXPECT_NEAR(std::abs(scbm2(1,2) * TP(3.)), std::abs(cm1(1,2)), s<TP>()) << "mix cmatrix scbm";
EXPECT_NEAR(std::abs(scbm2(3,0) * TP(3.)), std::abs(cm1(3,0)), s<TP>()) << "mix cmatrix scbm";
EXPECT_NEAR(std::abs(TP(3.) * scbm2(1,2)), std::abs(cm1(0,1)), s<TP>()) << "mix cmatrix scbm";
EXPECT_NEAR(std::abs(TP(3.) * scbm2(1,0)), std::abs(cm1(1,0)), s<TP>()) << "mix cmatrix scbm";
EXPECT_NEAR((scbm2(1,2) * TP(3.)).real(), cm1(1,2).real(), spp<TP>()) << "mix cmatrix scbm";
EXPECT_NEAR((scbm2(1,2) * TP(3.)).imag(), cm1(1,2).imag(), spp<TP>()) << "mix cmatrix scbm";
EXPECT_NEAR((scbm2(3,0) * TP(3.)).real(), cm1(3,0).real(), spp<TP>()) << "mix cmatrix scbm";
EXPECT_NEAR((scbm2(3,0) * TP(3.)).imag(), cm1(3,0).imag(), spp<TP>()) << "mix cmatrix scbm";
EXPECT_NEAR((TP(3.) * scbm2(1,2)).real(), cm1(0,1).real(), spp<TP>()) << "mix cmatrix scbm";
EXPECT_NEAR((TP(3.) * scbm2(1,2)).imag(), cm1(0,1).imag(), spp<TP>()) << "mix cmatrix scbm";
EXPECT_NEAR((TP(3.) * scbm2(1,0)).real(), cm1(1,0).real(), spp<TP>()) << "mix cmatrix scbm";
EXPECT_NEAR((TP(3.) * scbm2(1,0)).imag(), cm1(1,0).imag(), spp<TP>()) << "mix cmatrix scbm";

rm1 = srbm2;
EXPECT_NEAR(srbm2(1,2), rm1(1,2), s<TP>()) << "mix rmatrix srbm";
EXPECT_NEAR(srbm2(3,0), rm1(3,0), s<TP>()) << "mix rmatrix srbm";
EXPECT_NEAR(srbm2(1,2), rm1(1,2), s<TP>()) << "mix rmatrix srbm";
EXPECT_NEAR(srbm2(3,0), rm1(3,0), s<TP>()) << "mix rmatrix srbm";

rm1 = rm1 + srbm2;
rm1 += srbm2;
EXPECT_EQ(srbm2(1,2) * 3., rm1(1,2)) << "mix rmatrix srbm";
EXPECT_EQ(srbm2(1,2) * 3., rm1(1,2)) << "mix rmatrix srbm";
EXPECT_EQ(3. * srbm2(3,0), rm1(3,0)) << "mix matrix srbm";
EXPECT_EQ(3 * srbm2(3,0), rm1(3,0)) << "mix rmatrix srbm";
EXPECT_EQ(srbm2(1,2) * 3, rm1(1,2)) << "mix rmatrix srbm";
EXPECT_EQ(3 * srbm2(3,0), rm1(3,0)) << "mix rmatrix srbm";
EXPECT_EQ(srbm2(1,2) * 3, rm1(1,2)) << "mix rmatrix srbm";

scbm1.resize(4);
for (int j = 0; j <= 3; j++) {
Expand Down
Loading

0 comments on commit 66a0025

Please sign in to comment.