Arcane  4.1.12.0
Developer documentation
Loading...
Searching...
No Matches
AlephCuda.cc
1// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
2//-----------------------------------------------------------------------------
3// Copyright 2000-2026 CEA (www.cea.fr) IFPEN (www.ifpenergiesnouvelles.com)
4// See the top-level COPYRIGHT file for details.
5// SPDX-License-Identifier: Apache-2.0
6//-----------------------------------------------------------------------------
7/*---------------------------------------------------------------------------*/
8/* AlephCuda.cc (C) 2010-2012 */
9/* */
10/*---------------------------------------------------------------------------*/
11/*---------------------------------------------------------------------------*/
12
13#include "arcane/aleph/AlephArcane.h"
14#include "arcane/aleph/cuda/IAlephCuda.h"
15
16/*---------------------------------------------------------------------------*/
17/*---------------------------------------------------------------------------*/
18
19namespace Arcane
20{
21
22/*---------------------------------------------------------------------------*/
23/*---------------------------------------------------------------------------*/
24
25class CudaAlephFactoryImpl
26: public AbstractService
27, public IAlephFactoryImpl
28{
29 public:
30
31 CudaAlephFactoryImpl(const ServiceBuildInfo& sbi)
32 : AbstractService(sbi)
33 {}
34
35 public:
36
37 virtual void initialize()
38 {
39 debug() << "\t[AlephFactory::AlephFactory] cudaDeviceReset";
40 cudaDeviceReset();
41 debug() << "\t[AlephFactory::AlephFactory] cudaDeviceSynchronize";
42 cudaDeviceSynchronize();
43 // If cublasInit fails, it means there is no device
44 if (cublasInit() != CUBLAS_STATUS_SUCCESS)
45 return;
46 // throw FatalErrorException("AlephFactory", "Could not initialize CUBLAS!");
47 // Now check if there is a device supporting CUDA
48 int deviceCount;
49 cudaGetDeviceCount(&deviceCount);
50 if (deviceCount == 0)
51 throw FatalErrorException("AlephFactory", "No device found!");
52 int dev;
53 for (dev = 0; dev < deviceCount; ++dev) {
54 cudaDeviceProp deviceProp;
55 cudaGetDeviceProperties(&deviceProp, dev);
56 if (strncmp(deviceProp.name, "Device Emulation", 16))
57 break;
58 }
59 if (dev == deviceCount)
60 throw FatalErrorException(A_FUNCINFO, "No suitable device found");
61 debug() << "\t[Aleph::Cuda::device_check] setting device!";
62 cudaSetDevice(dev);
63 }
64
65 virtual IAlephTopology* createTopology(ITraceMng* tm, AlephKernel* kernel, Integer index, Integer nb_row_size)
66 {
67 return 0;
68 }
69
70 virtual IAlephVector* createVector(ITraceMng* tm, AlephKernel* kernel, Integer index)
71 {
72 return new AlephVectorCnc(tm, kernel, index);
73 }
74
75 virtual IAlephMatrix* createMatrix(ITraceMng* tm, AlephKernel* kernel, Integer index)
76 {
77 return new AlephMatrixCnc(tm, kernel, index);
78 }
79};
80
81/*---------------------------------------------------------------------------*/
82/*---------------------------------------------------------------------------*/
83
85
86/*---------------------------------------------------------------------------*/
87/*---------------------------------------------------------------------------*/
88
89} // namespace Arcane
90
91/*---------------------------------------------------------------------------*/
92/*---------------------------------------------------------------------------*/
#define ARCANE_REGISTER_APPLICATION_FACTORY(aclass, ainterface, aname)
Registers a factory service for the class aclass.
AbstractService(const ServiceBuildInfo &)
Constructor from a ServiceBuildInfo.
Interface of an implementation factory for Aleph.
Structure containing the information to create a service.
TraceMessageDbg debug(Trace::eDebugLevel=Trace::Medium) const
Flow for a debug message.
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
Int32 Integer
Type representing an integer.