Skip to content
This repository was archived by the owner on Jan 26, 2024. It is now read-only.

Commit b777faf

Browse files
kjayapra-amdvsytch
authored andcommitted
SWDEV-252542 - Fixing Win Compilation on SWDEV-241902.
Change-Id: If76f79002b265dccf6da4acef1ff9372d8b0a2ff
1 parent ad79386 commit b777faf

File tree

7 files changed

+36
-17
lines changed

7 files changed

+36
-17
lines changed

device/device.hpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -871,7 +871,8 @@ class ClBinary : public amd::HeapObject {
871871

872872
/** called only in loading image routines, never storing routines */
873873
bool setBinary(const char* theBinary, size_t theBinarySize, bool allocated = false,
874-
amd::Os::FileDesc fd = -1, size_t foffset = 0, std::string uri = std::string());
874+
amd::Os::FileDesc fd = amd::Os::FDescInit(), size_t foffset = 0,
875+
std::string uri = std::string());
875876

876877
//! setin elfIn_
877878
bool setElfIn();
@@ -1049,7 +1050,7 @@ inline std::string Program::BinaryURI() const {
10491050

10501051
inline Program::finfo_t Program::BinaryFd() const {
10511052
if (clBinary() == NULL) {
1052-
return {-1, 0};
1053+
return {amd::Os::FDescInit(), 0};
10531054
}
10541055
return clBinary()->Datafd();
10551056
}

device/devprogram.hpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,8 @@ class Program : public amd::HeapObject {
195195
const ClBinary* clBinary() const { return clBinary_; }
196196

197197
bool setBinary(const char* binaryIn, size_t size, const device::Program* same_dev_prog = nullptr,
198-
amd::Os::FileDesc fdesc = -1, size_t foffset = 0, std::string uri = std::string());
198+
amd::Os::FileDesc fdesc = amd::Os::FDescInit(), size_t foffset = 0,
199+
std::string uri = std::string());
199200

200201
type_t type() const { return type_; }
201202

@@ -283,7 +284,8 @@ class Program : public amd::HeapObject {
283284
virtual bool createBinary(amd::option::Options* options) = 0;
284285

285286
//! Initialize Binary (used only for clCreateProgramWithBinary()).
286-
bool initClBinary(const char* binaryIn, size_t size, amd::Os::FileDesc fdesc = -1,
287+
bool initClBinary(const char* binaryIn, size_t size,
288+
amd::Os::FileDesc fdesc = amd::Os::FDescInit(),
287289
size_t foffset = 0, std::string uri = std::string());
288290

289291
//! Initialize Binary
@@ -299,7 +301,7 @@ class Program : public amd::HeapObject {
299301

300302
virtual bool setKernels(
301303
amd::option::Options* options, void* binary, size_t binSize,
302-
amd::Os::FileDesc fdesc = -1, size_t foffset = 0,
304+
amd::Os::FileDesc fdesc = amd::Os::FDescInit(), size_t foffset = 0,
303305
std::string uri = std::string()) { return true; }
304306

305307
//! Returns all the options to be appended while passing to the compiler library

device/pal/palprogram.hpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ class HSAILProgram : public device::Program {
196196
virtual const aclTargetInfo& info(const char* str = "");
197197

198198
virtual bool setKernels(amd::option::Options* options, void* binary, size_t binSize,
199-
amd::Os::FileDesc fdesc = -1, size_t foffset = 0,
199+
amd::Os::FileDesc fdesc = amd::Os::FDescInit(), size_t foffset = 0,
200200
std::string uri = std::string()) override;
201201

202202
//! Destroys CPU allocations in the code segment
@@ -251,7 +251,9 @@ class LightningProgram : public HSAILProgram {
251251
virtual ~LightningProgram() {}
252252

253253
protected:
254-
virtual bool setKernels(amd::option::Options* options, void* binary, size_t binSize) override;
254+
virtual bool setKernels(amd::option::Options* options, void* binary, size_t binSize,
255+
amd::Os::FileDesc fdesc = amd::Os::FDescInit(), size_t foffset = 0,
256+
std::string uri = std::string()) override;
255257

256258
virtual bool createBinary(amd::option::Options* options) override;
257259
};

device/rocm/rocprogram.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ class HSAILProgram : public roc::Program {
9292
bool createBinary(amd::option::Options* options) override { return true; }
9393

9494
virtual bool setKernels(amd::option::Options* options, void* binary, size_t binSize,
95-
amd::Os::FileDesc fdesc = -1, size_t foffset = 0,
95+
amd::Os::FileDesc fdesc = amd::Os::FDescInit(), size_t foffset = 0,
9696
std::string uri = std::string()) override;
9797

9898
private:
@@ -115,7 +115,7 @@ class LightningProgram final : public roc::Program {
115115
bool saveBinaryAndSetType(type_t type, void* rawBinary, size_t size);
116116

117117
bool setKernels(amd::option::Options* options, void* binary, size_t binSize,
118-
amd::Os::FileDesc fdesc = -1, size_t foffset = 0,
118+
amd::Os::FileDesc fdesc = amd::Os::FDescInit(), size_t foffset = 0,
119119
std::string uri = std::string()) final;
120120
};
121121

os/os.hpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333

3434
#ifdef _WIN32
3535
#include <Basetsd.h> // For KAFFINITY
36+
#include <windows.h>
3637
#endif // _WIN32
3738

3839
// Smallest supported VM page size.
@@ -99,6 +100,14 @@ class Os : AllStatic {
99100
#endif
100101
};
101102

103+
static FileDesc FDescInit() {
104+
#if defined(__linux__)
105+
return -1;
106+
#else
107+
return INVALID_HANDLE_VALUE;
108+
#endif
109+
}
110+
102111
// Returns unique resource indicator for a particular memory
103112
static bool GetURIFromMemory(const void* image, size_t image_size, std::string& uri);
104113

os/os_win32.cpp

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -824,7 +824,7 @@ void Os::getAppPathAndFileName(std::string& appName, std::string& appPathAndName
824824

825825
bool Os::GetURIFromMemory(const void* image, size_t image_size, std::string& uri_) {
826826
// Not implemented yet for windows
827-
uri = std::string();
827+
uri_ = std::string();
828828
return true;
829829
}
830830

@@ -836,7 +836,7 @@ bool Os::CloseFileHandle(FileDesc fdesc) {
836836
return true;
837837
}
838838

839-
bool GetFileHandle(const char* fname, FileDesc* fd_ptr, size_t* sz_ptr) {
839+
bool Os::GetFileHandle(const char* fname, FileDesc* fd_ptr, size_t* sz_ptr) {
840840
if ((fd_ptr == nullptr) || (sz_ptr == nullptr)) {
841841
return false;
842842
}
@@ -852,17 +852,21 @@ bool GetFileHandle(const char* fname, FileDesc* fd_ptr, size_t* sz_ptr) {
852852
return true;
853853
}
854854

855-
bool MemoryMapFileDesc(FileDesc fdesc, size_t fsize, size_t foffset, const void** mmap_ptr) {
856-
if (fdesc < 0) {
855+
bool Os::MemoryMapFileDesc(FileDesc fdesc, size_t fsize, size_t foffset, const void** mmap_ptr) {
856+
if (fdesc == INVALID_HANDLE_VALUE) {
857857
return false;
858858
}
859859

860-
*mmap_ptr = INVALID_HANDLE_VALUE;
861-
*mmap_ptr = CreateFileMappingA(fdesc, NULL, PAGE_READONLY, 0, 0, NULL);
862-
if (*mmap_ptr == INVALID_HANDLE_VALUE) {
860+
HANDLE map_handle = INVALID_HANDLE_VALUE;
861+
862+
map_handle = CreateFileMappingA(fdesc, NULL, PAGE_READONLY, 0, 0, NULL);
863+
if (map_handle == INVALID_HANDLE_VALUE) {
864+
CloseHandle(map_handle);
863865
return false;
864866
}
865867

868+
*mmap_ptr = MapViewOfFile(map_handle, FILE_MAP_READ, 0,0,0);
869+
866870
return true;
867871
}
868872

platform/program.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,8 @@ class Program : public RuntimeObject {
171171
//! Add a new device program with or without binary image and options.
172172
int32_t addDeviceProgram(Device&, const void* image = NULL, size_t len = 0,
173173
bool make_copy = true, amd::option::Options* options = NULL,
174-
const amd::Program* same_prog = nullptr, amd::Os::FileDesc fdesc = -1,
174+
const amd::Program* same_prog = nullptr,
175+
amd::Os::FileDesc fdesc = amd::Os::FDescInit(),
175176
size_t foffset = 0, std::string uri = std::string());
176177

177178
//! Find the section for the given device. Return NULL if not found.

0 commit comments

Comments
 (0)